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 ReadOnlyTransaction
INSTANCE
static String
READ_ONLY_TX_ID
-
Method Summary
All Methods Instance Methods Concrete 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
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 transactionInstant
updateExpiry(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:Transaction
Commit the transaction- Specified by:
commit
in interfaceTransaction
-
commitIfShortLived
public void commitIfShortLived()
Description copied from interface:Transaction
Commit the transaction only if the transaction is shortLived- Specified by:
commitIfShortLived
in interfaceTransaction
-
isCommitted
public boolean isCommitted()
- Specified by:
isCommitted
in interfaceTransaction
- Returns:
- returns true if this transaction has already been committed
-
rollback
public void rollback()
Description copied from interface:Transaction
Rollback the transaction- Specified by:
rollback
in interfaceTransaction
-
fail
public void fail()
Description copied from interface:Transaction
Marks the transaction as failed. Failed transactions cannot be committed but may be rolledback.- Specified by:
fail
in interfaceTransaction
-
isRolledBack
public boolean isRolledBack()
- Specified by:
isRolledBack
in interfaceTransaction
- Returns:
- true if this transaction has been rolled back
-
isOpenLongRunning
public boolean isOpenLongRunning()
- Specified by:
isOpenLongRunning
in 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:
isOpen
in interfaceTransaction
- Returns:
- true if the tx is in an OPEN state and has not expired
-
ensureCommitting
public void ensureCommitting()
Description copied from interface:Transaction
Throws an exception if the tx is not in a COMMITTING state- Specified by:
ensureCommitting
in interfaceTransaction
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceTransaction
- Returns:
- true the tx is read-only
-
getId
public String getId()
Description copied from interface:Transaction
Get the transaction id- Specified by:
getId
in interfaceTransaction
- Returns:
- the transaction id.
-
isShortLived
public boolean isShortLived()
Description copied from interface:Transaction
Check if the transaction is short-lived.- Specified by:
isShortLived
in interfaceTransaction
- Returns:
- is the transaction short-lived.
-
setShortLived
public void setShortLived(boolean shortLived)
Description copied from interface:Transaction
Set transaction short-lived state.- Specified by:
setShortLived
in interfaceTransaction
- Parameters:
shortLived
- boolean true (short-lived) or false (not short-lived)
-
expire
public void expire()
Description copied from interface:Transaction
Expire a transaction- Specified by:
expire
in interfaceTransaction
-
hasExpired
public boolean hasExpired()
Description copied from interface:Transaction
Has the transaction expired?- Specified by:
hasExpired
in interfaceTransaction
- Returns:
- true if expired
-
updateExpiry
public Instant updateExpiry(Duration amountToAdd)
Description copied from interface:Transaction
Update the expiry by the provided amount- Specified by:
updateExpiry
in interfaceTransaction
- Parameters:
amountToAdd
- the amount of time to add- Returns:
- the new expiration date
-
getExpires
public Instant getExpires()
Description copied from interface:Transaction
Get the date this session expires- Specified by:
getExpires
in interfaceTransaction
- Returns:
- expiration date, if one exists
-
refresh
public void refresh()
Description copied from interface:Transaction
Refresh the transaction to extend its expiration window.- Specified by:
refresh
in interfaceTransaction
-
lockResource
public void lockResource(FedoraId resourceId)
Description copied from interface:Transaction
Acquires a lock on the specified resource for this transaction.- Specified by:
lockResource
in interfaceTransaction
- Parameters:
resourceId
- the resource to lock
-
releaseResourceLocksIfShortLived
public void releaseResourceLocksIfShortLived()
Description copied from interface:Transaction
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.- Specified by:
releaseResourceLocksIfShortLived
in interfaceTransaction
-
doInTx
public void doInTx(Runnable runnable)
Description copied from interface:Transaction
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.- Specified by:
doInTx
in interfaceTransaction
- Parameters:
runnable
- the code to execute within the tx
-
setBaseUri
public void setBaseUri(String baseUri)
Description copied from interface:Transaction
Sets the baseUri on the transaction- Specified by:
setBaseUri
in interfaceTransaction
- Parameters:
baseUri
- the baseUri of the requests
-
setUserAgent
public void setUserAgent(String userAgent)
Description copied from interface:Transaction
Sets the user-agent on the transaction- Specified by:
setUserAgent
in interfaceTransaction
- Parameters:
userAgent
- the request's user-agent
-
-