Package org.h2.mvstore.tx
Class Transaction
java.lang.Object
org.h2.mvstore.tx.Transaction
A transaction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe status of a closed transaction (committed or rolled back).static final intThe status of a transaction that has been logically committed or rather marked as committed, because it might be still listed among prepared, if it was prepared for commit.static final intThe status of an open transaction.static final intThe status of a prepared transaction. -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this transaction has isolation level READ_COMMITTED or below.voidcommit()Commit the transaction.intgetChanges(long savepointId) Get the list of changes, starting with the latest change, up to the given savepoint (in reverse order than they occurred).intgetId()Returns the isolation level of this transaction.getName()longintbooleanDetermine if any database changes were made as part of this transaction.booleanReturns whether statement dependencies are currently set.voidMark an exit from SQL statement execution within this transaction.voidmarkStatementStart(HashSet<MVMap<Object, VersionedValue<Object>>> maps) Mark an entry into a new SQL statement execution within this transaction.<K,V> TransactionMap<K, V> Open a data map.<K,V> TransactionMap<K, V> Open the map to store the data.<K,V> TransactionMap<K, V> openMapX(MVMap<K, VersionedValue<V>> map) Open the transactional version of the given map.voidprepare()Prepare the transaction.<K,V> void removeMap(TransactionMap<K, V> map) Remove the map.voidrollback()Roll the transaction back.voidrollbackToSavepoint(long savepointId) Roll back to the given savepoint.voidlongCreate a new savepoint.voidsetTimeoutMillis(int timeoutMillis) Sets the new lock timeout.toString()booleanwaitFor(Transaction toWaitFor, String mapName, Object key, int timeoutMillis) Make this transaction to wait for the specified transaction to be closed, because both of them try to modify the same map entry.
-
Field Details
-
STATUS_CLOSED
public static final int STATUS_CLOSEDThe status of a closed transaction (committed or rolled back).- See Also:
-
STATUS_OPEN
public static final int STATUS_OPENThe status of an open transaction.- See Also:
-
STATUS_PREPARED
public static final int STATUS_PREPAREDThe status of a prepared transaction.- See Also:
-
STATUS_COMMITTED
public static final int STATUS_COMMITTEDThe status of a transaction that has been logically committed or rather marked as committed, because it might be still listed among prepared, if it was prepared for commit. Undo log entries might still exists for it and not all of it's changes within map's are re-written as committed yet. Nevertheless, those changes should be already viewed by other transactions as committed. This transaction's id can not be re-used until all of the above is completed and transaction is closed. A transactions can be observed in this state when the store was closed while the transaction was not closed yet. When opening a store, such transactions will automatically be processed and closed as committed.- See Also:
-
-
Method Details
-
getId
public int getId() -
getSequenceNum
public long getSequenceNum() -
getStatus
public int getStatus() -
hasChanges
public boolean hasChanges()Determine if any database changes were made as part of this transaction.- Returns:
- true if there are changes to commit, false otherwise
-
setName
-
getName
-
getBlockerId
public int getBlockerId() -
setSavepoint
public long setSavepoint()Create a new savepoint.- Returns:
- the savepoint id
-
hasStatementDependencies
public boolean hasStatementDependencies()Returns whether statement dependencies are currently set.- Returns:
- whether statement dependencies are currently set
-
getIsolationLevel
Returns the isolation level of this transaction.- Returns:
- the isolation level of this transaction
-
allowNonRepeatableRead
public boolean allowNonRepeatableRead()Whether this transaction has isolation level READ_COMMITTED or below.- Returns:
- true if isolation level is READ_COMMITTED or READ_UNCOMMITTED
-
markStatementStart
Mark an entry into a new SQL statement execution within this transaction.- Parameters:
maps- set of maps used by transaction or statement is about to be executed
-
markStatementEnd
public void markStatementEnd()Mark an exit from SQL statement execution within this transaction. -
openMap
Open a data map.- Type Parameters:
K- the key typeV- the value type- Parameters:
name- the name of the map- Returns:
- the transaction map
-
openMap
Open the map to store the data.- Type Parameters:
K- the key typeV- the value type- Parameters:
name- the name of the mapkeyType- the key data typevalueType- the value data type- Returns:
- the transaction map
-
openMapX
Open the transactional version of the given map.- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the base map- Returns:
- the transactional map
-
prepare
public void prepare()Prepare the transaction. Afterwards, the transaction can only be committed or completely rolled back. -
commit
public void commit()Commit the transaction. Afterwards, this transaction is closed. -
rollbackToSavepoint
public void rollbackToSavepoint(long savepointId) Roll back to the given savepoint. This is only allowed if the transaction is open.- Parameters:
savepointId- the savepoint id
-
rollback
public void rollback()Roll the transaction back. Afterwards, this transaction is closed. -
getChanges
Get the list of changes, starting with the latest change, up to the given savepoint (in reverse order than they occurred). The value of the change is the value before the change was applied.- Parameters:
savepointId- the savepoint id, 0 meaning the beginning of the transaction- Returns:
- the changes
-
setTimeoutMillis
public void setTimeoutMillis(int timeoutMillis) Sets the new lock timeout.- Parameters:
timeoutMillis- the new lock timeout in milliseconds
-
waitFor
Make this transaction to wait for the specified transaction to be closed, because both of them try to modify the same map entry.- Parameters:
toWaitFor- transaction to wait formapName- name of the map containing blocking entrykey- of the blocking entrytimeoutMillis- timeout in milliseconds,-1for default- Returns:
- true if other transaction was closed and this one can proceed, false if timed out
-
removeMap
Remove the map.- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the map
-
toString
-