Class MorphiaGuiceTransaction
java.lang.Object
dev.getelements.elements.dao.mongo.guice.MorphiaGuiceTransaction
- All Implemented Interfaces:
Transaction,AutoCloseable
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.getelements.elements.sdk.dao.Transaction
Transaction.RetryException -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and releases the transaction.voidcommit()Commits the transaction.<DaoT> DaoTGets the requested Dao type, bound to thisTransaction.com.google.inject.Injectorintdev.morphia.transactions.MorphiaSessionlongbooleanisActive()Returns true if this transaction is still active and open.voidrollback()Rolls back the transaction undoing any pending changes to the database.voidsetBufferedEventPublisher(MongoTransactionBufferedEventPublisher bufferedEventPublisher) voidsetInjector(com.google.inject.Injector injector) voidsetMaxRetries(int maxRetries) voidsetMorphiaSession(dev.morphia.transactions.MorphiaSession morphiaSession) voidsetRetryTimeout(long retryTimeout) voidstart()Starts the transaction.<T> Function<Transaction, T> wrap(Function<Transaction, T> original) Optionally, wraps the transaction operation in anotherFunctionto properly handle any retry exceptions specific to the transaction's implementation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.getelements.elements.sdk.dao.Transaction
performAndClose, performAndCloseV
-
Field Details
-
MAX_RETRIES
- See Also:
-
RETRY_TIMEOUT
- See Also:
-
-
Constructor Details
-
MorphiaGuiceTransaction
public MorphiaGuiceTransaction()
-
-
Method Details
-
getDao
Description copied from interface:TransactionGets the requested Dao type, bound to thisTransaction. The returned DAO is only valid for the life of thisTransactionobject.- Specified by:
getDaoin interfaceTransaction- Type Parameters:
DaoT- the DAO Type- Parameters:
daoT- theClass<DaoT>- Returns:
- the DAO Instance
-
isActive
public boolean isActive()Description copied from interface:TransactionReturns true if this transaction is still active and open.- Specified by:
isActivein interfaceTransaction- Returns:
- true if active, false if it has been committed or rolled back.
-
wrap
Description copied from interface:TransactionOptionally, wraps the transaction operation in anotherFunctionto properly handle any retry exceptions specific to the transaction's implementation. This ensures that any executed code will properly honor the semantics ofTransaction.RetryException.- Specified by:
wrapin interfaceTransaction- Type Parameters:
T- the return type- Parameters:
original- the operation- Returns:
- the wrapped function, or the original function
-
commit
public void commit()Description copied from interface:TransactionCommits the transaction. In the event the transaction fails due to a transient condition, aTransaction.RetryExceptionis thrown. The caller should then rollback the transaction, wait for the recommended delay and then restart and re-execute the entire transaction.- Specified by:
commitin interfaceTransaction
-
start
public void start()Description copied from interface:TransactionStarts the transaction. Note, transactions are stared automatically when the Transaction object is created so this is only necessary if the transaction has been explicitly aborted via rollback operation.- Specified by:
startin interfaceTransaction
-
rollback
public void rollback()Description copied from interface:TransactionRolls back the transaction undoing any pending changes to the database.- Specified by:
rollbackin interfaceTransaction
-
close
public void close()Description copied from interface:TransactionCloses and releases the transaction. Once closed, the transaction is no longer active and any DAOs acquired will have undefined behavior if used.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransaction
-
getMaxRetries
public int getMaxRetries() -
setMaxRetries
@Inject public void setMaxRetries(@Named("dev.getelements.elements.mongo.transaction.retry.count") int maxRetries) -
getRetryTimeout
public long getRetryTimeout() -
setRetryTimeout
@Inject public void setRetryTimeout(@Named("dev.getelements.elements.mongo.transaction.retry.timeout") long retryTimeout) -
getInjector
public com.google.inject.Injector getInjector() -
setInjector
@Inject public void setInjector(com.google.inject.Injector injector) -
getMorphiaSession
public dev.morphia.transactions.MorphiaSession getMorphiaSession() -
setMorphiaSession
@Inject public void setMorphiaSession(dev.morphia.transactions.MorphiaSession morphiaSession) -
getBufferedEventPublisher
-
setBufferedEventPublisher
@Inject public void setBufferedEventPublisher(MongoTransactionBufferedEventPublisher bufferedEventPublisher)
-