Package org.fcrepo.kernel.api
Interface Transaction
-
- All Known Implementing Classes:
ReadOnlyTransaction
,TransactionImpl
public interface Transaction
The Fedora Transaction abstraction- Author:
- mohideen
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
commit()
Commit the transactionvoid
commitIfShortLived()
Commit the transaction only if the transaction is shortLivedvoid
doInTx(Runnable runnable)
Executes the runnable within the tx.void
ensureCommitting()
Throws an exception if the tx is not in a COMMITTING statevoid
expire()
Expire a transactionvoid
fail()
Marks the transaction as failed.Instant
getExpires()
Get the date this session expiresString
getId()
Get the transaction idboolean
hasExpired()
Has the transaction expired?boolean
isCommitted()
boolean
isOpen()
boolean
isOpenLongRunning()
boolean
isReadOnly()
boolean
isRolledBack()
boolean
isShortLived()
Check if the transaction is short-lived.void
lockResource(FedoraId resourceId)
Acquires a lock on the specified resource for this transaction.void
lockResourceAndGhostNodes(FedoraId resourceId)
Acquire a lock on the specified resource and any ghost nodes above it for this transaction.void
refresh()
Refresh the transaction to extend its expiration window.void
releaseResourceLocksIfShortLived()
Releases any resource locks held by the transaction if the session is short-lived.void
rollback()
Rollback the transactionvoid
setBaseUri(String baseUri)
Sets the baseUri on the transactionvoid
setShortLived(boolean shortLived)
Set transaction short-lived state.void
setUserAgent(String userAgent)
Sets the user-agent on the transactionvoid
suppressEvents()
After invoking, any accumulated events will be suppressed.Instant
updateExpiry(Duration amountToAdd)
Update the expiry by the provided amount
-
-
-
Method Detail
-
commit
void commit()
Commit the transaction
-
commitIfShortLived
void commitIfShortLived()
Commit the transaction only if the transaction is shortLived
-
isCommitted
boolean isCommitted()
- Returns:
- returns true if this transaction has already been committed
-
rollback
void rollback()
Rollback the transaction
-
fail
void fail()
Marks the transaction as failed. Failed transactions cannot be committed but may be rolledback.
-
isRolledBack
boolean isRolledBack()
- Returns:
- true if this transaction has been rolled back
-
isOpenLongRunning
boolean isOpenLongRunning()
- Returns:
- true if the tx is a long-running tx that has not expired and is not in a COMMITTED, ROLLEDBACK, or FAILED state
-
isOpen
boolean isOpen()
- Returns:
- true if the tx is in an OPEN state and has not expired
-
ensureCommitting
void ensureCommitting()
Throws an exception if the tx is not in a COMMITTING state- Throws:
TransactionRuntimeException
- when not in committing
-
isReadOnly
boolean isReadOnly()
- Returns:
- true the tx is read-only
-
isShortLived
boolean isShortLived()
Check if the transaction is short-lived.- Returns:
- is the transaction short-lived.
-
setShortLived
void setShortLived(boolean shortLived)
Set transaction short-lived state.- Parameters:
shortLived
- boolean true (short-lived) or false (not short-lived)
-
expire
void expire()
Expire a transaction
-
hasExpired
boolean hasExpired()
Has the transaction expired?- Returns:
- true if expired
-
updateExpiry
Instant updateExpiry(Duration amountToAdd)
Update the expiry by the provided amount- Parameters:
amountToAdd
- the amount of time to add- Returns:
- the new expiration date
-
getExpires
Instant getExpires()
Get the date this session expires- Returns:
- expiration date, if one exists
-
refresh
void refresh()
Refresh the transaction to extend its expiration window.
-
lockResource
void lockResource(FedoraId resourceId)
Acquires a lock on the specified resource for this transaction.- Parameters:
resourceId
- the resource to lock- Throws:
ConcurrentUpdateException
- if the lock cannot be acquired
-
lockResourceAndGhostNodes
void lockResourceAndGhostNodes(FedoraId resourceId)
Acquire a lock on the specified resource and any ghost nodes above it for this transaction.- Parameters:
resourceId
- the resource to lock- Throws:
ConcurrentUpdateException
- if the lock cannot be acquired
-
releaseResourceLocksIfShortLived
void releaseResourceLocksIfShortLived()
Releases any resource locks held by the transaction if the session is short-lived. This method should always be called after handling a request, regardless of the outcome, so that any held locks are released immediately without having to wait for the short-lived transaction to expire.
-
doInTx
void doInTx(Runnable runnable)
Executes the runnable within the tx. While there are active runnables being executed, the tx may not be committed or rolledback. Runnables may only be executed when the tx is in an OPEN state and has not expired.- Parameters:
runnable
- the code to execute within the tx
-
setBaseUri
void setBaseUri(String baseUri)
Sets the baseUri on the transaction- Parameters:
baseUri
- the baseUri of the requests
-
setUserAgent
void setUserAgent(String userAgent)
Sets the user-agent on the transaction- Parameters:
userAgent
- the request's user-agent
-
suppressEvents
void suppressEvents()
After invoking, any accumulated events will be suppressed.
-
-