Re: [Dbixx-devel] Questions about DatabaseInterface (again)
Status: Alpha
Brought to you by:
cyborch
From: Anders B. <cy...@de...> - 2002-06-17 10:55:21
|
Jerry Seutter wrote: > Hello again, > > I have a basic MySQLDatabaseInterface class going. It can retrieve > simple objects from the database and store them to the database. I haven't > worked on multiple table support yet. > > A couple of questions have arisen out of this: > > 1. PersistentFactory.createPersistent(DatabaseInterface dbi, Object identifier) > In my implementation of the PersistentFactory interface I have been using > identifier to pass in a string that tells the Factory which record to > retrieve from the database. It happens to be a String object and in the > Factory I just use the toString() method on the object to use the String in > my search. Is this the way it was intended to be used? Is the usage of > the Object being passed in something that the implementor of the > PersistentFactory interface and the user of it have to agree on? > The identifier is an Object since it HAS to be of the same datatype as the primary key of the table that holds the Persistent. If your primary key is a CHAR or VARCHAR like datatype this Object will have to be a String. On the other hand if it is an integer or a numeric or the like it will have to be an int. Therefore this is something the implementor of the PersistentFactory and the user have to agree on. > > 2. PersistentFactory did not have a storePersistent() method like the > diagrams indicate. I added: > storePersistent(DatabaseInterface dbi, Persistent p) > Sound about right? Indeed. That is correct. > 3. When storing an object to the database, I don't know when to use an > UPDATE statement and when to use an INSERT statement. If the object was > retrieved from the database, modified and is now to be put back into the > database, an UPDATE statement should be used. If it is a brand new object > then an INSERT statement should be used. How do you tell which one the > object is? Running another query just to find out if the object is in the > database seems wasteful and if the database allows multiple non-unique > records then this method would not work. It seems to me that the Factory > needs to have control over which type of statement is run. Thoughts? I agree that this may seem wasteful. It seems a bit wasteful to me. But there is only one place data can be stored: The Database. When a new Persistent is created it is not given an id. While that id is zero I presume that INSERT is the correct function to use. Otherwise id holds the primary key of the Persistent and UPDATE should be used. This way we should be able to avoid that extra database call. > > I'm close to getting the code in a contributable state. How do > you want it submitted? I would like to have it in diff format submitted to the project page. If i'm impressed (and it sounds like I will be) with what you have done you'll get cvs access. That way you can work faster and get more feedback as you work. -- Anders Borch Web Forge Software Engineer Jenagade 22 G, 2300 Copenhagen S, Denmark an...@we... www.web-forge.dk |