Java Reference
In-Depth Information
<value>classpath:/kodo.properties</value>
</property>
<property name="jdoProperties">
<props>
<prop key="javax.jdo.option.Optimistic">true</prop>
</props>
</property>
</bean>
The LocalPersistenceManagerFactoryBean creates the PersistenceManagerFac-
tory that injected into the JdoTemplate used by repositories such as JDOOrderRe-
positoryImpl . This bean definition sets the value of javax.jdo.option.Optimistic
to true .
Using a mixture of optimistic and pessimistic transactions in a JDO application
is difficult. Using a separate PersistenceManagerFactory for each type of transac-
tion is often impractical because you would have to define multiple instances of
each Spring bean that depends directly or indirectly on the PersistenceManager-
Factory . In addition, Spring 1.1.4 does not support declaratively specifying the
transaction type. To specify the JDO transaction type on a per-transaction basis, an
application would have to use a custom AOP interceptor that calls Transac-
tion.setOptimistic() .
Let's see how JDO optimistic transactions and pessimistic transactions work.
Using optimistic transactions
A JDO optimistic transaction uses optimistic locking to handle concurrent
updates. When an application commits an optimistic transaction, the JDO imple-
mentation verifies that all modified objects are unchanged in the database using
one of the three change-tracking mechanisms we described earlier. If any have
changed or been deleted, the JDO implementation will roll back the transaction
and throw a JDOOptimisticVerificationFailedException , which is mapped by
Spring's JdoTemplate to OptimisticLockingFailureException .
JDO 1.0 left the details of the optimistic locking mechanism up to the JDO ven-
dor. However, JDO 1 . x implementations such as Versant Open Access JDO (for-
merly known as JDO Genie) and Kodo JDO implement optimistic locking using all
three change-tracking mechanisms. This is an example of how to configure the
Order class in Kodo JDO 3.0.2 to use a version column:
<jdo>
<package name="net.chrisrichardson.foodToGo.domain">
<class name="Order" identity-type="datastore">
<extension vendor-name="kodo" key="table"
value="PLACED_ORDER" />
<extension vendor-name="kodo"
key="jdbc-version-ind"
 
 
 
 
Search WWH ::




Custom Search