|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.hypergraphdb.transaction.HGTransactionManager
public class HGTransactionManager
The HGTransactionManager handles transactional activity for a single
HyperGraph instance. You can obtain the transaction manager for a HyperGraph by
calling its getTransactionManager method.
| Field Summary | |
|---|---|
TxMonitor |
txMonitor
|
| Constructor Summary | |
|---|---|
HGTransactionManager(HGTransactionFactory factory)
Construct a new transaction manager with the given transaction factory. |
|
| Method Summary | ||
|---|---|---|
void |
abort()
Abort the current transaction by calling endTransaction(false). |
|
void |
beginTransaction()
Begin a new transaction in the current transaction context. |
|
void |
commit()
Commit the current transaction by calling endTransaction(true). |
|
HGTransaction |
createTransaction(HGTransaction parent)
Create and return a child transaction of the given parent transaction. |
|
void |
disable()
Disable transactions - equivalent to setEnabled(false) |
|
void |
enable()
Enable transactions - equivalent to setEnabled(true). |
|
void |
endTransaction(boolean success)
Terminate the currently active transaction. |
|
|
ensureTransaction(java.util.concurrent.Callable<V> transaction)
Perform a unit of work encapsulated as a transaction and return the result. |
|
HGTransactionContext |
getContext()
Return the HGTransactionContext instance associated with the current
thread. |
|
boolean |
isEnabled()
Return true if the transaction are enabled and false
otherwise. |
|
void |
setEnabled(boolean enabled)
Enable or disable transaction. |
|
void |
threadAttach(HGTransactionContext tContext)
Attach the given transaction context to the current thread. |
|
void |
threadDetach()
Detach the transaction context bound to the current thread. |
|
|
transact(java.util.concurrent.Callable<V> transaction)
Perform a unit of work encapsulated as a transaction and return the result. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public TxMonitor txMonitor
| Constructor Detail |
|---|
public HGTransactionManager(HGTransactionFactory factory)
Construct a new transaction manager with the given transaction factory. This
method is normally called only internally. To obtain the transactio manager
bound to a HyperGraph, use HyperGraph.getTransactionManager.
factory - The HGTransactionFactory responsible for
fabricating new transactions.| Method Detail |
|---|
public boolean isEnabled()
Return true if the transaction are enabled and false
otherwise.
public void setEnabled(boolean enabled)
Enable or disable transaction. Note that all current transactions will be silently aborted so make sure any pending transactions are completed before calling this method.
enabled - true if transaction must be henceforth enabled and
false otherwise.public void enable()
Enable transactions - equivalent to setEnabled(true).
public void disable()
Disable transactions - equivalent to setEnabled(false)
public HGTransactionContext getContext()
Return the HGTransactionContext instance associated with the current
thread.
public void threadAttach(HGTransactionContext tContext)
Attach the given transaction context to the current thread. This
method is normally called in a server environment. By default,
a transaction context will be created and bound to a thread
if need be, every time a new transaction is requested. So when
HyperGraph is embedded in a client application, there is no
need to explicitly attach/detach contexts to threads. However, in
an environment using thread pooling such as is common in servers where
a single transaction can span multiple requests, use the
threadAttach and threadDetach methods
to switch transactions contexts bound to clients.
tContext - public void threadDetach()
Detach the transaction context bound to the current thread. This method is normally called in a server environment. By default, a transaction context will be created and bound to a thread if need be, every time a new transaction is requested. So when HyperGraph is embedded in a client application, there is no need to explicitly attach/detach contexts to threads.
IMPORTANT NOTE: when managing transaction
contexts explicitly, you are responsible for closing
all pending transactions in the context before disposing of it.
This is done by invoking the HGTransactionContext.endAll
method.
tContext - public HGTransaction createTransaction(HGTransaction parent)
Create and return a child transaction of the given parent transaction.
The - parent HGTransaction - if null, a top-level
transaction object is returned.
public void beginTransaction()
Begin a new transaction in the current transaction context. If there's no transaction context bound to the active thread, one will be created.
public void endTransaction(boolean success)
throws HGTransactionException
Terminate the currently active transaction. The transaction will
be aborted or committed based on the success flag
(abort when false and commit when true).
You are graced with a HGException if there's no currently
active transaction.
success -
HGTransactionExceptionpublic void commit()
Commit the current transaction by calling endTransaction(true).
Wrap the possible HGTransactionException in a HGException.
public void abort()
Abort the current transaction by calling endTransaction(false).
Wrap the possible HGTransactionException in a HGException.
public <V> V ensureTransaction(java.util.concurrent.Callable<V> transaction)
Perform a unit of work encapsulated as a transaction and return the result. This method will reuse the currently active transaction if there is one or create a new transaction otherwise.
V - The type of the return value.transaction - The transaction process encapsulated as a Callable instance.
transaction.call().
The - method will (re)throw any exception that does not result from a deadlock.public <V> V transact(java.util.concurrent.Callable<V> transaction)
Perform a unit of work encapsulated as a transaction and return the result. This method explicitly allows deadlock to occur and it will reattempt the transaction in such a case indefinitely. In order for the transaction to eventually complete, the underlying transactional system must be configured to be fair or to prioritize transaction randomly (which is the default behavior).
V - The type of the return value.transaction - The transaction process encapsulated as a Callable instance.
transaction.call().
The - method will (re)throw any exception that does not result from a deadlock.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||