|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Transaction
Representation of a transaction within DataNucleus. This interface is not user application visible. Handling of transactions in DataNucleus is split in 4 layers:
Transaction - the JDO API interfaceUserTransaction - the JTA API interfaceUserTransaction - DataNucleus API proprietary APITransaction interface defines the contract
for handling transactions for the ObjectManager.
In the X/Open/JTA layer the handling of XA resources is done. It means, XAResources are
obtained and enlisted to a TransactionManager. The TransactionManager will commit or rollback the resources
at the end of the transactions. There are two kinds of TransactionManager: DataNucleus and JTA. A
JTA TransactionManager is external to DataNucleus, while the DataNucleus TransactionManager is implemented
by DataNucleus as org.datanucleus.transaction. The DataNucleus TransactionManager is used when the DataSource used
to obtain connections to the underlying database is not enlisted in an external JTA TransactionManager.
The JTA TransactionManager is usually found when running in J2EE application servers, however
nowadays there are many JTA containers that can be used in J2SE.
The scenarios where a JTA TransactionManager is used is:
When an JTA TransactionManager exists, and the connections to the underlying databases
are acquired via transactional DataSources. That means, when you ask a connection to the DataSource,
it will automatically enlist it in a JTA TransactionManager.
The Resource layer is handled by the datastore. For example, with RDBMS databases,
the javax.sql.Connection is the API used to demarcate the database transactions. In The RBDMS database,
the resource layer, it is handling the database transaction.
| Field Summary | |
|---|---|
static java.lang.String |
TRANSACTION_ISOLATION_OPTION
Option to use when wanting to set the transaction isolation level. |
| Method Summary | |
|---|---|
void |
addTransactionEventListener(TransactionEventListener listener)
Adds a transaction listener. |
void |
begin()
Begin a transaction. |
void |
bindTransactionEventListener(TransactionEventListener listener)
Listeners that are never cleared, and invoked for all transactions |
void |
commit()
Commit the current transaction. |
void |
end()
Method to allow the transaction to flush any resources. |
void |
flush()
Method to allow the transaction to flush any resources. |
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. |
java.util.Map<java.lang.String,java.lang.Object> |
getOptions()
Obtain all settings for this Transaction |
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. |
java.lang.Boolean |
getSerializeRead()
Accessor for the setting for whether to serialize read objects (lock them). |
javax.transaction.Synchronization |
getSynchronization()
The user-specified Synchronization instance for this
Transaction instance. |
boolean |
isActive()
Returns whether there is a transaction currently active. |
boolean |
isCommitting()
Checks whether a transaction is committing. |
boolean |
lockReadObjects()
Convenience accessor providing a simple true/false for locking read objects. |
void |
removeTransactionEventListener(TransactionEventListener listener)
Removes the listeners for a single transaction |
void |
rollback()
Rollback the current 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 |
setOption(java.lang.String option,
boolean value)
|
void |
setOption(java.lang.String option,
int value)
|
void |
setOption(java.lang.String option,
java.lang.String value)
|
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(java.lang.Boolean serializeRead)
Mutator for whether to serialize (lock) any read objects in this transaction. |
void |
setSynchronization(javax.transaction.Synchronization sync)
The user can specify a Synchronization instance to be
notified on transaction completions. |
| Field Detail |
|---|
static final java.lang.String TRANSACTION_ISOLATION_OPTION
| Method Detail |
|---|
void begin()
NucleusUserException - if transactions are managed by a container
in the managed environment, or if the transaction is already active.void commit()
NucleusUserException - if transactions are managed by a container
in the managed environment, or if the transaction is not active.void rollback()
NucleusUserException - if transactions are managed by a container
in the managed environment, or if the transaction is not active.boolean isActive()
void flush()
void end()
boolean getRollbackOnly()
void setRollbackOnly()
true.
After this flag is set to true, the transaction
can no longer be committed.
NucleusUserException - if the flag is true and an attempt is made
to commit the txnvoid setNontransactionalRead(boolean nontransactionalRead)
true, allow persistent instances to be read without
a transaction active.
If an implementation does not support this option, a
nontransactionalRead - Whether to have non-tx reads
NucleusUserException - if not supported (supported by DataNucleus)boolean 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.
nontransactionalWrite - Whether requiring non-tx writes
NucleusUserException - if not supported (DataNucleus doesnt support it!)boolean 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.
retainValues - the value of the retainValues property
NucleusUserException - if not supported (DataNucleus supports it)boolean 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.
restoreValues - the value of the restoreValues property
NucleusUserException - if not supported (DataNucleus supports it)boolean getRestoreValues()
void setOptimistic(boolean optimistic)
optimistic - the value of the Optimistic flag.
NucleusUserException - if not supported (DataNucleus supports it)boolean getOptimistic()
void setSynchronization(javax.transaction.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 nonejavax.transaction.Synchronization getSynchronization()
Synchronization instance for this
Transaction instance.
Synchronization instance.boolean isCommitting()
void addTransactionEventListener(TransactionEventListener listener)
listener - void removeTransactionEventListener(TransactionEventListener listener)
listener - void bindTransactionEventListener(TransactionEventListener listener)
listener - java.util.Map<java.lang.String,java.lang.Object> getOptions()
void setSerializeRead(java.lang.Boolean serializeRead)
serializeRead - Whether to serialise (lock) any read objectsjava.lang.Boolean getSerializeRead()
boolean lockReadObjects()
void setOption(java.lang.String option,
int value)
void setOption(java.lang.String option,
boolean value)
void setOption(java.lang.String option,
java.lang.String value)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||