[OJB-developers] Optimistic locking
Brought to you by:
thma
From: Jakob B. <jbr...@ho...> - 2002-02-02 10:07:08
|
hi, the attached zip contains some code based on version 0.7.310 to support optimistic locking for int, long and timestamp fields. <FieldDescriptor id="6"> <field.name>test</field.name> <column.name>test</column.name> <jdbc_type>INTEGER</jdbc_type> <locking>true</locking> </FieldDescriptor> <FieldDescriptor id="8"> <field.name>lastModified</field.name> <column.name>entryDate</column.name> <jdbc_type>TIMESTAMP</jdbc_type> <locking>true</locking> </FieldDescriptor> the locking fields are used in the where-clause for update and delete. if the rowcount of the update is 0, an exception is thrown (JdbcAccess::executeUpdate()) : ... broker.getStatementManager().bindUpdate(stmt, mif, obj); if (stmt.executeUpdate() == 0 && mif.isLocking()) //BRJ { throw new PersistenceBrokerException("Object has been modified by someone else"); } ... hth jakob |