we dont have much going on with support for this right now. So lets look at Hibernate and see what they do:
http://nhibernate.sourceforge.net/h2.0.3-docs/reference/html/ transactions.html#transactions-s5 http://www.hibernate.org/hib_docs/v3/api/org/hibernate/ Session.html#lock(java.lang.Object,%20org.hibernate.LockMode) so they pretty much have a LockMode object that all the various selecting methods can handle. the changes I see to SA for this include: - select(..., for_update=True) would also be able to take select (...., for_update="nowait"), which indicates "SELECT... FOR UPDATE NOWAIT" on Oracle. - Session would get a "lock" method: def lock(self, object, lockmode, entity_name=None) where lockmode is one of None, "read", "upgrade", "upgrade_nowait". it also would cascade following cascade rules. for "read", "upgrade", "upgrade_nowait", a SELECT is issued for the instance's row using the appropriate FOR UPDATE [NOWAIT]; if the mapper specifies a version_id column, that will be matched up against the instance's version id. - all the select/get methods on Query as well as Session.get/ Session.load would get an extra keyword argument "lockmode" which also can specify any of those values. "upgrade" and "upgrade_nowait" would add the FOR UPDATE [NOWAIT] to the select statement issued (question: what should happen with lazy loaders attached to the loaded instance ? the "lock" cascade rule would have to propigate this into the lazyloaders.) - Query gets a set_lock_mode() method that will apply the given lockmode indicator to all get/select operations. so thats a pretty big ticket. if it sounds good to the list I can add a trac item for it. I gather the extra argument on Query's load methods, possibly not including the cascade to lazy loader behavior, would be the most expediently addable element of this change. On Sep 1, 2006, at 11:04 AM, Mike Bernson wrote: > I have started using sessions and mappers. > > I am looking for the correct way to handle locking using sessions and > query object. > > I had code like: > statement = table.select(and_( > *[table.c[k] == v for k,v in > where.iteritems()]), for_update=True > return statement.execute() > > now > where = and_(*[table.c[k] == v for k,v in > where.iteritems()] > query = self.__session.query(mapper) > return query.select(where) > > It looks the select method on the query object can not handle taking > for_update=true. > How do I select the row with the for_update ? > > > ---------------------------------------------------------------------- > --- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users