Java Reference
In-Depth Information
DomainRestaurantNotificationService calls the OrderRepository to retrieve the
orders that are ready to be sent. It then sends each one using the RestaurantNoti-
ficationGateway . Finally, DomainRestaurantNotificationService marks each
order as having been sent by calling Order.noteSent() .
This design works for both Hibernate and JDO . The only thing that needs to be
changed is the OrderRepository class and persistence framework-specific files,
such as the O/R mapping. Let's look at the concurrency options provided by JDO
and how to configure them.
12.3.2
Handling concurrent updates with JDO
JDO supports optimistic locking, pessimistic locking, and serializable transactions.
A JDO application uses pessimistic or optimistic locking by specifying the type of
the JDO transaction. Let's first explore how this is done and then see how to con-
figure serializable transactions.
Configuring the JDO transaction type
JDO defines two types of transactions: optimistic transactions, which use the opti-
mistic locking, and datastore transactions, which use pessimistic locking or fully iso-
lated transactions. The most common way to specify the JDO transaction type is by
configuring the JDO PersistenceManagerFactory . The PersistenceManagerFac-
tory has a property called javax.jdo.option.Optimistic , which specifies whether
to use optimistic or datastore transactions. A value of true specifies that any Per-
sistenceManager s created by the PersistenceManagerFactory should use optimistic
transactions. A value of false specifies that they should use datastore transactions.
There are also a couple of other rarely used ways to programmatically specify
the JDO transaction type. You can call PersistenceManagerFactory.setOptimis-
tic() , which is equivalent to using the javax.jdo.option.Optimistic property.
You can also specify the transaction type by calling Transaction.setOptimistic() ,
which specifies the type of the transactions used by that Transaction object. How-
ever, for most applications, configuring the PersistenceManagerFactory declara-
tively is the easiest approach.
A Spring application sets this property by configuring the Spring bean that cre-
ates the PersistenceManagerFactory . For example, you can enable optimistic
transactions in a Spring application by using the following bean definition:
<bean id="myPersistenceManagerFactory"
lazy-init="true"
class="org.springframework.orm.jdo.
bbbbbbb b
LocalPersistenceManagerFactoryBean">
<property name="configLocation">
 
 
 
 
 
 
Search WWH ::




Custom Search