Package org.fcrepo.kernel.api
Class ReadOnlyTransaction
- java.lang.Object
-
- org.fcrepo.kernel.api.ReadOnlyTransaction
-
- All Implemented Interfaces:
Transaction
public class ReadOnlyTransaction extends Object implements Transaction
A read-only tx that never expires and cannot be committed.- Author:
- pwinckles
-
-
Field Summary
Fields Modifier and Type Field Description static ReadOnlyTransactionINSTANCEstatic StringREAD_ONLY_TX_ID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()Commit the transactionvoidcommitIfShortLived()Commit the transaction only if the transaction is shortLivedvoiddoInTx(Runnable runnable)Executes the runnable within the tx.voidensureCommitting()Throws an exception if the tx is not in a COMMITTING statevoidexpire()Expire a transactionvoidfail()Marks the transaction as failed.InstantgetExpires()Get the date this session expiresStringgetId()Get the transaction idbooleanhasExpired()Has the transaction expired?booleanisCommitted()booleanisOpen()booleanisOpenLongRunning()booleanisReadOnly()booleanisRolledBack()booleanisShortLived()Check if the transaction is short-lived.voidlockResource(FedoraId resourceId)Acquires a lock on the specified resource for this transaction.voidrefresh()Refresh the transaction to extend its expiration window.voidreleaseResourceLocksIfShortLived()Releases any resource locks held by the transaction if the session is short-lived.voidrollback()Rollback the transactionvoidsetBaseUri(String baseUri)Sets the baseUri on the transactionvoidsetShortLived(boolean shortLived)Set transaction short-lived state.voidsetUserAgent(String userAgent)Sets the user-agent on the transactionInstantupdateExpiry(Duration amountToAdd)Update the expiry by the provided amount
-
-
-
Field Detail
-
INSTANCE
public static final ReadOnlyTransaction INSTANCE
-
READ_ONLY_TX_ID
public static final String READ_ONLY_TX_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
commit
public void commit()
Description copied from interface:TransactionCommit the transaction- Specified by:
commitin interfaceTransaction
-
commitIfShortLived
public void commitIfShortLived()
Description copied from interface:TransactionCommit the transaction only if the transaction is shortLived- Specified by:
commitIfShortLivedin interfaceTransaction
-
isCommitted
public boolean isCommitted()
- Specified by:
isCommittedin interfaceTransaction- Returns:
- returns true if this transaction has already been committed
-
rollback
public void rollback()
Description copied from interface:TransactionRollback the transaction- Specified by:
rollbackin interfaceTransaction
-
fail
public void fail()
Description copied from interface:TransactionMarks the transaction as failed. Failed transactions cannot be committed but may be rolledback.- Specified by:
failin interfaceTransaction
-
isRolledBack
public boolean isRolledBack()
- Specified by:
isRolledBackin interfaceTransaction- Returns:
- true if this transaction has been rolled back
-
isOpenLongRunning
public boolean isOpenLongRunning()
- Specified by:
isOpenLongRunningin interfaceTransaction- 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
public boolean isOpen()
- Specified by:
isOpenin interfaceTransaction- Returns:
- true if the tx is in an OPEN state and has not expired
-
ensureCommitting
public void ensureCommitting()
Description copied from interface:TransactionThrows an exception if the tx is not in a COMMITTING state- Specified by:
ensureCommittingin interfaceTransaction
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceTransaction- Returns:
- true the tx is read-only
-
getId
public String getId()
Description copied from interface:TransactionGet the transaction id- Specified by:
getIdin interfaceTransaction- Returns:
- the transaction id.
-
isShortLived
public boolean isShortLived()
Description copied from interface:TransactionCheck if the transaction is short-lived.- Specified by:
isShortLivedin interfaceTransaction- Returns:
- is the transaction short-lived.
-
setShortLived
public void setShortLived(boolean shortLived)
Description copied from interface:TransactionSet transaction short-lived state.- Specified by:
setShortLivedin interfaceTransaction- Parameters:
shortLived- boolean true (short-lived) or false (not short-lived)
-
expire
public void expire()
Description copied from interface:TransactionExpire a transaction- Specified by:
expirein interfaceTransaction
-
hasExpired
public boolean hasExpired()
Description copied from interface:TransactionHas the transaction expired?- Specified by:
hasExpiredin interfaceTransaction- Returns:
- true if expired
-
updateExpiry
public Instant updateExpiry(Duration amountToAdd)
Description copied from interface:TransactionUpdate the expiry by the provided amount- Specified by:
updateExpiryin interfaceTransaction- Parameters:
amountToAdd- the amount of time to add- Returns:
- the new expiration date
-
getExpires
public Instant getExpires()
Description copied from interface:TransactionGet the date this session expires- Specified by:
getExpiresin interfaceTransaction- Returns:
- expiration date, if one exists
-
refresh
public void refresh()
Description copied from interface:TransactionRefresh the transaction to extend its expiration window.- Specified by:
refreshin interfaceTransaction
-
lockResource
public void lockResource(FedoraId resourceId)
Description copied from interface:TransactionAcquires a lock on the specified resource for this transaction.- Specified by:
lockResourcein interfaceTransaction- Parameters:
resourceId- the resource to lock
-
releaseResourceLocksIfShortLived
public void releaseResourceLocksIfShortLived()
Description copied from interface:TransactionReleases 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.- Specified by:
releaseResourceLocksIfShortLivedin interfaceTransaction
-
doInTx
public void doInTx(Runnable runnable)
Description copied from interface:TransactionExecutes 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.- Specified by:
doInTxin interfaceTransaction- Parameters:
runnable- the code to execute within the tx
-
setBaseUri
public void setBaseUri(String baseUri)
Description copied from interface:TransactionSets the baseUri on the transaction- Specified by:
setBaseUriin interfaceTransaction- Parameters:
baseUri- the baseUri of the requests
-
setUserAgent
public void setUserAgent(String userAgent)
Description copied from interface:TransactionSets the user-agent on the transaction- Specified by:
setUserAgentin interfaceTransaction- Parameters:
userAgent- the request's user-agent
-
-