public interface Transaction
Transaction
interface provides for initiation and
completion of transactions under user control.
It is a sub-interface of the PersistenceManager
that deals with options and transaction demarcation.
Transaction options include whether optimistic concurrency control should be used for the current transaction, whether instances may hold values in the cache outside transactions, and whether values should be retained in the cache after transaction completion. These options are valid for both managed and non-managed transactions.
Transaction initiation and completion methods have similar semantics to
javax.transaction.UserTransaction
when used outside a managed
environment. When used in a managed environment, transaction initiation
and completion methods may only be used with bean-managed transaction
semantics.
Modifier and Type | Method and Description |
---|---|
void |
begin()
Begin a transaction.
|
void |
commit()
Commit the current transaction.
|
String |
getIsolationLevel()
Get the value for transaction isolation level for this transaction.
|
boolean |
getNontransactionalRead()
If
true , allows persistent instances to be read without
a transaction active. |
boolean |
getNontransactionalWrite()
If
true , allows persistent instances to be written without
a transaction active. |
boolean |
getOptimistic()
Optimistic transactions do not hold data store locks until commit time.
|
PersistenceManager |
getPersistenceManager()
The
Transaction instance is always associated with exactly
one PersistenceManager . |
boolean |
getRestoreValues()
Return the current value of the restoreValues property.
|
boolean |
getRetainValues()
If
true , at commit time instances retain their field
values. |
boolean |
getRollbackOnly()
Returns the rollback-only status of the transaction.
|
Boolean |
getSerializeRead()
Return the current value of the serializeRead property.
|
Synchronization |
getSynchronization()
The user-specified
Synchronization instance for this
Transaction instance. |
boolean |
isActive()
Returns whether there is a transaction currently active.
|
void |
rollback()
Roll back the current transaction.
|
void |
setIsolationLevel(String level)
Set the value for transaction isolation level for this transaction.
|
void |
setNontransactionalRead(boolean nontransactionalRead)
If
true , allow persistent instances to be read without
a transaction active. |
void |
setNontransactionalWrite(boolean nontransactionalWrite)
If
true , allow persistent instances to be written without
a transaction active. |
void |
setOptimistic(boolean optimistic)
Optimistic transactions do not hold data store locks until commit time.
|
void |
setRestoreValues(boolean restoreValues)
If
true , at rollback, fields of newly persistent instances
are restored to
their values as of the beginning of the transaction, and the instances
revert to transient. |
void |
setRetainValues(boolean retainValues)
If
true , at commit instances retain their values and the
instances transition to persistent-nontransactional. |
void |
setRollbackOnly()
Sets the rollback-only status of the transaction to
true . |
void |
setSerializeRead(Boolean serialize)
If
true , a lock will be applied to all objects read in this
transaction. |
void |
setSynchronization(Synchronization sync)
The user can specify a
Synchronization instance to be
notified on transaction completions. |
void begin()
JDOUserException
- if transactions are managed by a container
in the managed environment, or if the transaction is already active.setOptimistic(boolean)
,
getOptimistic()
void commit()
JDOUserException
- if transactions are managed by a container
in the managed environment, or if the transaction is not active.void rollback()
JDOUserException
- if transactions are managed by a container
in the managed environment, or if the transaction is not active.boolean isActive()
true
if the transaction is active.boolean getRollbackOnly()
true
if the transaction has been
marked for rollback.void setRollbackOnly()
true
.
After this flag is set to true
, the transaction
can no longer be committed, and any attempt to commit the
transaction will throw JDOFatalDataStoreException
.void setNontransactionalRead(boolean nontransactionalRead)
true
, allow persistent instances to be read without
a transaction active.
If an implementation does not support this option, a
JDOUnsupportedOptionException
is thrown.nontransactionalRead
- the value of the nontransactionalRead
propertyboolean getNontransactionalRead()
true
, allows persistent instances to be read without
a transaction active.void setNontransactionalWrite(boolean nontransactionalWrite)
true
, allow persistent instances to be written without
a transaction active.
If an implementation does not support this option, a
JDOUnsupportedOptionException
is thrown.nontransactionalWrite
- the value of the nontransactionalRead
propertyboolean getNontransactionalWrite()
true
, allows persistent instances to be written without
a transaction active.void setRetainValues(boolean retainValues)
true
, at commit instances retain their values and the
instances transition to persistent-nontransactional.
If an implementation does not support this option, a
JDOUnsupportedOptionException
is thrown.retainValues
- the value of the retainValues propertyboolean getRetainValues()
true
, at commit time instances retain their field
values.void setRestoreValues(boolean restoreValues)
true
, at rollback, fields of newly persistent instances
are restored to
their values as of the beginning of the transaction, and the instances
revert to transient. Additionally, fields of modified
instances of primitive types and immutable reference types
are restored to their values as of the beginning of the
transaction.
If false
, at rollback, the values of fields of
newly persistent instances are unchanged and the instances revert to
transient. Additionally, dirty instances transition to hollow.
If an implementation does not support this option, a
JDOUnsupportedOptionException
is thrown.
restoreValues
- the value of the restoreValues propertyboolean getRestoreValues()
void setOptimistic(boolean optimistic)
JDOUnsupportedOptionException
is thrown.optimistic
- the value of the Optimistic flag.boolean getOptimistic()
String getIsolationLevel()
setIsolationLevel(String)
void setIsolationLevel(String level)
Standard values in order of low to high are:
level
- the transaction isolation levelgetIsolationLevel()
,
Constants.TX_READ_UNCOMMITTED
,
Constants.TX_READ_COMMITTED
,
Constants.TX_REPEATABLE_READ
,
Constants.TX_SNAPSHOT
,
Constants.TX_SERIALIZABLE
void setSynchronization(Synchronization sync)
Synchronization
instance to be
notified on transaction completions. The beforeCompletion
method is called prior to flushing instances to the data store.
The afterCompletion
method is called after performing
state transitions of persistent and transactional instances, following
the data store commit or rollback operation.
Only one Synchronization
instance can be registered with
the Transaction
. If the application requires more than one
instance to receive synchronization callbacks, then the single
application instance is responsible for managing them, and forwarding
callbacks to them.
sync
- the Synchronization
instance to be notified;
null
for noneSynchronization getSynchronization()
Synchronization
instance for this
Transaction
instance.Synchronization
instance.PersistenceManager getPersistenceManager()
Transaction
instance is always associated with exactly
one PersistenceManager
.PersistenceManager
for this
Transaction
instancevoid setSerializeRead(Boolean serialize)
true
, a lock will be applied to all objects read in this
transaction.
If false
then retrieved objects will not be locked.
If null will fallback to the value for metadata for the class in question.
serialize
- the value of the serializeRead propertyBoolean getSerializeRead()
Copyright © 2005–1970 Apache Software Foundation. All rights reserved.