Java Reference
In-Depth Information
value="version-number">
<extension vendor-name="kodo"
key="column" value="VERSION"/>
</extension>
The XML metadata specifies that the Order class be mapped to the PLACED_ORDER
table and that the optimistic locking check use the VERSION column.
The JDO 2.0 specification, which defines an O/R mapping, requires a JDO
implementation to support these three change-tracking mechanisms. This is how
you would configure the Order class to use a version number in JDO 2.0 :
<class name="Order"
table="PLACED_ORDER"
detachable="true"
identity-type="application">
<version strategy="version-number" column="VERSION"/>
</class>
The <version> element specifies that the Order class should maintain the version
number in the VERSION column. You could also use a value of strategy="time-
stamp" to implement optimistic locking using a timestamp and strategy="state-
image" to compare all columns. Note that unlike Hibernate, the timestamp or ver-
sion number might not be stored in a field. This usually isn't important except
when implementing the Optimistic Offline Lock pattern, which is described in
the next chapter.
Once the PersistenceManagerFactory and the classes have been configured
correctly, the JDO implementation will generate the SQL statements that imple-
ment optimistic locking. A typical JDO implementation will even perform optimis-
tic lock checks for those classes during a datastore transaction.
Using datastore transactions
Whereas a JDO optimistic transaction uses optimistic locking, a JDO datastore
transaction uses either the transaction isolation level or pessimistic locking to han-
dle concurrent updates. No class-level configuration is necessary in order to use
datastore transactions. However, the details of how datastore transactions are
implemented depends on the JDO implementation and the database. For
instance, Versant Open Access JDO and Kodo JDO implement datastore transac-
tions on Oracle by querying the database using SELECT FOR UPDATE statements,
which lock the rows. With JPOX 1.1 , the default is to rely on the isolation level to
lock the rows, and you must set a flag in order to use pessimistic locking.
 
 
 
 
Search WWH ::




Custom Search