By default DataNucleus does not currently lock the objects fetched in a pessimistic transaction,
but you can configure this behaviour for RDBMS datastores by setting the persistence property
datanucleus.rdbms.useUpdateLock
to
true
.
This will result in all "SELECT ... FROM ..." statements being changed to be
"SELECT ... FROM ... FOR UPDATE". This will be applied only where the underlying RDBMS
supports the "FOR UPDATE" syntax.
With a pessimistic transaction DataNucleus will grab a datastore connection at the first
operation, and maintain it for the duration of the transaction.
A single connection is used for the transaction (with the exception of any
Identity Generation operations which need datastore
access, so these can use their own connection).
In terms of the process of a pessimistic (datastore) transaction, we demonstrate this below.
|
Operation
|
DataNucleus process
|
Datastore process
|
|
Start transaction
|
|
|
|
Persist object
|
Prepare object (1) for persistence
|
Open connection.
Insert the object (1) into the datastore
|
|
Update object
|
Prepare object (2) for update
|
Update the object (2) into the datastore
|
|
Persist object
|
Prepare object (3) for persistence
|
Insert the object (3) into the datastore
|
|
Update object
|
Prepare object (4) for update
|
Update the object (4) into the datastore
|
|
Flush
|
No outstanding changes so do nothing
|
|
|
Perform query
|
Generate query in datastore language
|
Query the datastore and return selected objects
|
|
Persist object
|
Prepare object (5) for persistence
|
Insert the object (5) into the datastore
|
|
Update object
|
Prepare object (6) for update
|
Update the object (6) into the datastore
|
|
Commit transaction
|
|
Commit connection
|
So here whenever an operation is performed, DataNucleus pushes it straight to the datastore.
Consequently any queries will always reflect the current state of all objects in use.
However this mode of operation has no version checking of objects and so if they were updated
by external processes in the meantime then they will overwrite those changes.
It should be noted that DataNucleus provides two persistence properties that allow an amount of
control over when flushing happens with datastore transactions.