Thread: [SQLObject] Data Transfert Object
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: G. <fra...@cl...> - 2003-07-04 10:33:28
|
Hi all, I've a new need (arg ;) ) : I've to minimize network traffic : I want to update an SQLObject (or better a collection) once I've modified all the attributes. I know a design pattern from j2ee/ejb : Data Transfert Object (www.theserverside.com provides a free book : "ejb design patterns", which describes DTO on page 47).=20 This pattern says : a SQLObj produces a light object that doesn't update the db each an attribute is set. Once the work with this DTO is done, it would be passed to the SQLObj so the attribute will be updated in the db. So I'm asking about what to do : adding a "passive mode" to SQLObject and add a "save" method to explicitly update, or adding a generated method getSomeClassDTO that would return the DTO.=20 DTO could be implemented as a proxy over SQLObj : reading attribute on DTO will read on SQLObj, but setting attribute will store in a local cache, marking this attribute 'modified' so reading will read this modified value. If you have any idea about this problematic, I would appreciate a lot ;) Fran=E7ois |
From: Matt G. <ma...@po...> - 2003-07-04 12:42:26
|
Hi, If you *really* need a DTO then this is not going to help but SQLObject=20 already provides the set() method for updating multiple attributes in=20 one UPDATE statement. Consider the following code (untested): class Person(SQLObject): firstName =3D StringCol() lastName =3D StringCol() # Do an INSERT p =3D Person.new(firstName=3D'Matt, lastName=3D'Goodall') # UPDATE first_name p.firstName =3D 'Francois' # UPDATE last_name p.lastName =3D 'Girault' # UPDATE first_name and last_name in one go p.set(firstName=3D'Matt, lastName=3D'Goodall') Hope that helps. Cheers, Matt Fran=E7ois Girault wrote: >Hi all, > >I've a new need (arg ;) ) : > >I've to minimize network traffic : I want to update an SQLObject (or >better a collection) once I've modified all the attributes. > >I know a design pattern from j2ee/ejb : Data Transfert Object >(www.theserverside.com provides a free book : "ejb design patterns", >which describes DTO on page 47).=20 > >This pattern says : a SQLObj produces a light object that doesn't update >the db each an attribute is set. Once the work with this DTO is done, it >would be passed to the SQLObj so the attribute will be updated in the >db. > >So I'm asking about what to do : adding a "passive mode" to SQLObject >and add a "save" method to explicitly update, or adding a generated >method getSomeClassDTO that would return the DTO.=20 > >DTO could be implemented as a proxy over SQLObj : reading attribute on >DTO will read on SQLObj, but setting attribute will store in a local >cache, marking this attribute 'modified' so reading will read this >modified value. > >If you have any idea about this problematic, I would appreciate a lot ;) > >Fran=E7ois > --=20 Matt Goodall, Pollenation Internet Ltd e: ma...@po... |
From: G. <fra...@cl...> - 2003-07-04 12:54:43
|
On Fri, 04 Jul 2003 13:51:40 +0100 Matt Goodall <ma...@po...> wrote: > Hi, Hi Matt, >=20 > If you *really* need a DTO then this is not going to help ... I really need a DTO, because of lot of attribute assignments in some algori= thms > Hope that helps. Not really, but thanks a lot to answer me so quickly ! BR Fran=E7ois |
From: Sidnei da S. <si...@re...> - 2003-07-04 16:20:05
|
Howdy, Im working on integrating SQLObject and Zope3, and I must say that SQLObject is wonderful. So far, I had to change only one line, and I already have a working app. Here's my patch. Index: SQLObject/SQLBuilder.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLBuilder.py,v retrieving revision 1.6 diff -u -r1.6 SQLBuilder.py --- SQLObject/SQLBuilder.py 26 Jun 2003 08:33:56 -0000 1.6 +++ SQLObject/SQLBuilder.py 4 Jul 2003 16:13:50 -0000 @@ -108,7 +108,7 @@ t = type(obj) if isinstance(obj, SQLExpression): return obj.sqlRepr() - elif t is type(""): + elif t is type("") or t is type (u""): for orig, repl in sqlStringReplace: obj = obj.replace(orig, repl) return "'%s'" % obj However, Im doing something not that clean which is 'registering' a connection with DBConnection._connections by assigning directly to the module variable. I would like to see a method to do that (eg: DBConnection.registerConnection(name)), so that if it changes in the future, any code depending on it doesnt break :) Thanks for the work so far, and I hope to be able to make more contributions soon. Just for the records, im working on a Sybase-based app, but Im still prototyping, so Im using MySQL currently. Of course when the time comes, I will need to write a SybaseConnection class and I would like to contribute it back to the codebase. []'s -- Sidnei da Silva (dreamcatcher) <si...@x3...> X3ng Web Technology <http://www.x3ng.com.br> GNU/Linux user 257852 Debian GNU/Linux 3.0 (Sid) 2.4.20-powerpc ppc Type louder, please. ----------------------------------------------------------------------- Verified for virus by mail.redesul.com.br Scanner: clamscan / ClamAV - Version 0.54 - Updated 01/07/2003 |
From: Ian B. <ia...@co...> - 2003-07-04 18:48:31
|
On Fri, 2003-07-04 at 11:17, Sidnei da Silva wrote: > Howdy, > > Im working on integrating SQLObject and Zope3, and I must say that > SQLObject is wonderful. So far, I had to change only one line, and I > already have a working app. Here's my patch. Cool... I was wondering how well it would work with Zope 3, and I'm glad it's not too hard. It's just too bad that Zope 2 is out of the question :( > However, Im doing something not that clean which is 'registering' a > connection with DBConnection._connections by assigning directly to the > module variable. I would like to see a method to do that (eg: > DBConnection.registerConnection(name)), so that if it changes in the > future, any code depending on it doesnt break :) I'm not clear what you mean. Can you give an example? > Thanks for the work so far, and I hope to be able to make more > contributions soon. Just for the records, im working on a Sybase-based > app, but Im still prototyping, so Im using MySQL currently. Of course > when the time comes, I will need to write a SybaseConnection class and > I would like to contribute it back to the codebase. Certainly that would be welcome. Ian |
From: Sidnei da S. <si...@re...> - 2003-07-04 19:16:18
|
On Fri, Jul 04, 2003 at 01:49:21PM -0500, Ian Bicking wrote: | On Fri, 2003-07-04 at 11:17, Sidnei da Silva wrote: | Cool... I was wondering how well it would work with Zope 3, and I'm glad | it's not too hard. It's just too bad that Zope 2 is out of the question | :( Indeed :( | > However, Im doing something not that clean which is 'registering' a | > connection with DBConnection._connections by assigning directly to the | > module variable. I would like to see a method to do that (eg: | > DBConnection.registerConnection(name)), so that if it changes in the | > future, any code depending on it doesnt break :) | | I'm not clear what you mean. Can you give an example? Im using the 'feature' of having the SQLObject class attribute '_connection' being a string and having it look the connection on the _connections registry on class creation. from SQLObject.DBConnection import _connections def registerConnection(self, connectionName): cs = zapi.getService(self, SQLDatabaseConnections) conn = cs.getConnection(connectionName) _connections[connectionName] = getAdapter(conn, ISQLConnection) Another approach I tried is: def getFactory(self): klass = getService(self, 'ClassService').getClass(self.className) if not klass._connection: cs = getService(self, SQLDatabaseConnections) conn = cs.getConnection(self.connectionName) klass._connection = getAdapter(conn, ISQLConnection) klass.createTable(ifNotExists=True) return klass But I feel dirty in both cases, for modifying a private variable. []'s -- Sidnei da Silva (dreamcatcher) <si...@x3...> X3ng Web Technology <http://www.x3ng.com.br> GNU/Linux user 257852 Debian GNU/Linux 3.0 (Sid) 2.4.20-powerpc ppc Real Users find the one combination of bizarre input values that shuts down the system for days. ----------------------------------------------------------------------- Verified for virus by mail.redesul.com.br Scanner: clamscan / ClamAV - Version 0.54 - Updated 01/07/2003 |
From: Ian B. <ia...@co...> - 2003-07-04 18:53:29
|
On Fri, 2003-07-04 at 05:26, Fran=E7ois Girault wrote: > Hi all, >=20 > I've a new need (arg ;) ) : >=20 > I've to minimize network traffic : I want to update an SQLObject (or > better a collection) once I've modified all the attributes. >=20 > I know a design pattern from j2ee/ejb : Data Transfert Object > (www.theserverside.com provides a free book : "ejb design patterns", > which describes DTO on page 47).=20 >=20 > This pattern says : a SQLObj produces a light object that doesn't updat= e > the db each an attribute is set. Once the work with this DTO is done, i= t > would be passed to the SQLObj so the attribute will be updated in the > db. Luke Opperman wrote a temporary memory transaction for SQLObject, though I think he's been too busy since then to continue with it. I believe he called it MemoryTransaction -- anyway, it saved your changes in memory until you explicitly saved them back to the database. I believe this would do what you want. It would be possible to change SQLObject fairly easily to do this as well. There's an attribute _SO_creating, which delays database operations during creation (so that all the values can be inserted at once). Using that, or something analogous, you could probably implement something like delay and save methods. But I think Luke's idea would be more generally useful. Ian |