Class JtaTransaction
- java.lang.Object
-
- io.ebeaninternal.server.transaction.JtaTransaction
-
- All Implemented Interfaces:
Transaction
,SpiTransaction
,TxnProfileEventCodes
,AutoCloseable
public class JtaTransaction extends Object
Jta based transaction.
-
-
Field Summary
-
Fields inherited from interface io.ebean.Transaction
READ_COMMITTED, READ_UNCOMMITTED, REPEATABLE_READ, SERIALIZABLE
-
Fields inherited from interface io.ebeaninternal.api.TxnProfileEventCodes
EVT_CALLABLESQL, EVT_COMMIT, EVT_DELETE, EVT_DELETE_PERMANENT, EVT_DELETE_SOFT, EVT_INSERT, EVT_ORMUPDATE, EVT_ROLLBACK, EVT_UPDATE, EVT_UPDATESQL, FIND_ATTRIBUTE, FIND_COUNT, FIND_DELETE, FIND_ID_LIST, FIND_ITERATE, FIND_MANY, FIND_MANY_LAZY, FIND_ONE, FIND_ONE_LAZY, FIND_SUBQUERY, FIND_UPDATE
-
-
Constructor Summary
Constructors Constructor Description JtaTransaction(String id, boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager)
Create the JtaTransaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBeanChange(BeanChange beanChange)
Add a bean change to the change log.void
addModification(String tableName, boolean inserts, boolean updates, boolean deletes)
Add table modification information to the TransactionEvent.boolean
checkBatchEscalationOnCascade(PersistRequestBean<?> request)
Return true if batch mode got escalated for this request (and associated cascades).void
checkBatchEscalationOnCollection()
Potentially escalate batch mode on saving or deleting a collection.void
close()
Alias for end(), which enables this class to be used in try-with-resources.void
commit()
Commit the transaction.void
commitAndContinue()
Perform a commit, fire callbacks and notify l2 cache etc.int
depth()
Return the current depth.void
depth(int diff)
Return the depth of the current persist request plus the diff.void
end()
If the transaction is active then perform rollback.void
flush()
Flush any queued persist requests.void
flushBatch()
This is a synonym for flush() and will be deprecated.void
flushBatchOnCascade()
Flush after completing persist cascade.void
flushBatchOnCollection()
Flush batch if we escalated batch mode on saving or deleting a collection.void
flushBatchOnRollback()
If batch was on then effectively clear the batch such that we can handle exceptions and continue.BatchControl
getBatchControl()
Return the BatchControl used to batch up persist requests.Boolean
getBatchGetGeneratedKeys()
Return the getGeneratedKeys setting for this transaction.int
getBatchSize()
Return the batchSize specifically set for this transaction or 0.Connection
getConnection()
Return the underlying connection for public use.int
getDocStoreBatchSize()
Return the batch size to us for ElasticSearch Bulk API calls as a result of this transaction.io.ebean.annotation.DocStoreMode
getDocStoreMode()
Return the batchSize specifically set for this transaction or 0.DocStoreTransaction
getDocStoreTransaction()
Return a document store transaction.TransactionEvent
getEvent()
Return the underlying TransactionEvent.String
getId()
Return the transaction id.Connection
getInternalConnection()
Return the underlying connection for internal use.String
getLabel()
Return the user defined label for the transaction.String
getLogPrefix()
Return the string prefix with the transaction id and label used in logging.PersistenceContext
getPersistenceContext()
Return the persistence context associated with this transaction.ProfileLocation
getProfileLocation()
Return the profile location for this transaction.long
getStartNanoTime()
Return the start timestamp for the transaction (JVM side).Object
getTenantId()
Return the current Tenant Id.Object
getUserObject(String name)
Get an object added withTransaction.putUserObject(String, Object)
.boolean
isActive()
Return true if the transaction is active.boolean
isBatchMode()
Return the batch mode at the transaction level.boolean
isBatchOnCascade()
Return the batch mode at the request level.boolean
isBatchThisRequest()
Return true if this request should be batched.boolean
isExplicit()
Return true if this was an explicitly created transaction.boolean
isFlushOnQuery()
Return true if the batch (of persisted beans or executed UpdateSql etc) should be flushed prior to executing a query.boolean
isLogSql()
Return true if generated SQL and Bind values should be logged to the transaction log.boolean
isLogSummary()
Return true if summary level events should be logged to the transaction log.boolean
isNestedUseSavepoint()
Return true when nested transactions should create Savepoints.boolean
isPersistCascade()
Whether persistCascade is on for save and delete.boolean
isReadOnly()
Return true if this transaction is read only.boolean
isRegisteredBean(Object bean)
Return true if this is a bean that has already been saved.boolean
isRegisteredDeleteBean(Integer persistingBean)
Return true if this is a bean that has already been saved/deleted.boolean
isRollbackOnly()
Return true if the transaction is marked as rollback only.boolean
isSaveAssocManyIntersection(String intersectionTable, String beanName)
Return true if the m2m intersection save is allowed from a given bean direction.boolean
isSkipCache()
Return true if the L2 cache should be skipped.boolean
isSkipCacheExplicit()
Return true if explicitly set to skip cache (ignores skipOnWrite).Boolean
isUpdateAllLoadedProperties()
Return true if this transaction has updateAllLoadedProperties set.void
logSql(String msg)
Log a message to the SQL logger.void
logSummary(String msg)
Log a message to the SUMMARY logger.void
markNotQueryOnly()
Mark the transaction explicitly as not being query only.void
profileEvent(SpiProfileTransactionEvent event)
Check if the event should be added to a profiling transaction.long
profileOffset()
Return the offset time from the start of the transaction.ProfileStream
profileStream()
Return the stream that profiling events are written to.void
putUserObject(String name, Object value)
Add an arbitrary user object to the transaction.void
register(TransactionCallback callback)
Register a TransactionCallback with this transaction.void
registerDeferred(PersistDeferredRelationship derived)
Register a "Deferred Relationship" that requires an additional update later.void
registerDeleteBean(Integer persistingBean)
Add a bean to the registed list.void
rollback()
Rollback the transaction.void
rollback(Throwable e)
Rollback the transaction.void
sendChangeLog(ChangeSet changesRequest)
Send the change set to be prepared and then logged.void
setBatchControl(BatchControl batchControl)
Set the BatchControl to the transaction.void
setBatchMode(boolean batchMode)
Turn on or off use of JDBC statement batching.void
setBatchOnCascade(boolean batchMode)
Set the JDBC batch mode to use for a save() or delete() when cascading to children.void
setBatchSize(int batchSize)
Specify the number of statements before a batch is flushed automatically.void
setDocStoreBatchSize(int docStoreBatchSize)
Set the batch size to use for sending messages to the document store.void
setDocStoreMode(io.ebean.annotation.DocStoreMode docStoreMode)
Set the behavior for document store updates on this transaction.void
setFlushOnMixed(boolean batchFlushOnMixed)
By default when mixing UpdateSql (or CallableSql) with Beans the batch is automatically flushed when you change (between persisting beans and executing UpdateSql or CallableSql).void
setFlushOnQuery(boolean batchFlushOnQuery)
By default executing a query will automatically flush any batched statements (persisted beans, executed UpdateSql etc).void
setGetGeneratedKeys(boolean getGeneratedKeys)
Specify if you want batched inserts to use getGeneratedKeys.void
setLabel(String label)
Set a label on the transaction.void
setNestedUseSavepoint()
Set when we want nested transactions to use Savepoint's.void
setPersistCascade(boolean persistCascade)
Explicitly turn off or on the cascading nature of save() and delete().void
setPersistenceContext(PersistenceContext context)
Set the persistence context to this transaction.void
setProfileLocation(ProfileLocation profileLocation)
Set the profile location for this transaction.void
setProfileStream(ProfileStream profileStream)
Set the profileStream to catch and time all the events for this transaction.void
setReadOnly(boolean readOnly)
Set whether this transaction should be readOnly.void
setRollbackOnly()
Mark the transaction as rollback only.void
setSkipCache(boolean skipCache)
Set if the L2 cache should be skipped for "find by id" and "find by natural key" queries.void
setTenantId(Object tenantId)
Set the current Tenant Id.void
setUpdateAllLoadedProperties(boolean updateAllLoadedProperties)
Set to true when you want all loaded properties to be included in the update (rather than just the changed properties).String
toString()
javax.persistence.PersistenceException
translate(String message, SQLException cause)
Translate the SQLException.void
unregisterBeans()
Unregister the persisted beans (when persisting at the top level).-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.ebean.Transaction
isBatchFlushOnQuery, setBatchFlushOnMixed, setBatchFlushOnQuery, setBatchGetGeneratedKeys
-
-
-
-
Constructor Detail
-
JtaTransaction
public JtaTransaction(String id, boolean explicit, UserTransaction utx, DataSource ds, TransactionManager manager)
Create the JtaTransaction.
-
-
Method Detail
-
commit
public void commit()
Commit the transaction.- Specified by:
commit
in interfaceTransaction
-
rollback
public void rollback()
Rollback the transaction.- Specified by:
rollback
in interfaceTransaction
-
rollback
public void rollback(Throwable e)
Rollback the transaction.- Specified by:
rollback
in interfaceTransaction
-
setLabel
public void setLabel(String label)
Description copied from interface:Transaction
Set a label on the transaction.This label is used to group transaction execution times for performance metrics reporting.
- Specified by:
setLabel
in interfaceTransaction
-
getLabel
public String getLabel()
Description copied from interface:SpiTransaction
Return the user defined label for the transaction.- Specified by:
getLabel
in interfaceSpiTransaction
-
getStartNanoTime
public long getStartNanoTime()
Description copied from interface:SpiTransaction
Return the start timestamp for the transaction (JVM side).- Specified by:
getStartNanoTime
in interfaceSpiTransaction
-
profileOffset
public long profileOffset()
Description copied from interface:SpiTransaction
Return the offset time from the start of the transaction.- Specified by:
profileOffset
in interfaceSpiTransaction
-
profileEvent
public void profileEvent(SpiProfileTransactionEvent event)
Description copied from interface:SpiTransaction
Check if the event should be added to a profiling transaction.- Specified by:
profileEvent
in interfaceSpiTransaction
-
setProfileStream
public void setProfileStream(ProfileStream profileStream)
Description copied from interface:SpiTransaction
Set the profileStream to catch and time all the events for this transaction.- Specified by:
setProfileStream
in interfaceSpiTransaction
-
profileStream
public ProfileStream profileStream()
Description copied from interface:SpiTransaction
Return the stream that profiling events are written to.- Specified by:
profileStream
in interfaceSpiTransaction
-
setProfileLocation
public void setProfileLocation(ProfileLocation profileLocation)
Description copied from interface:SpiTransaction
Set the profile location for this transaction.- Specified by:
setProfileLocation
in interfaceSpiTransaction
-
getProfileLocation
public ProfileLocation getProfileLocation()
Description copied from interface:SpiTransaction
Return the profile location for this transaction.- Specified by:
getProfileLocation
in interfaceSpiTransaction
-
isSkipCacheExplicit
public boolean isSkipCacheExplicit()
Description copied from interface:SpiTransaction
Return true if explicitly set to skip cache (ignores skipOnWrite).- Specified by:
isSkipCacheExplicit
in interfaceSpiTransaction
-
isSkipCache
public boolean isSkipCache()
Description copied from interface:Transaction
Return true if the L2 cache should be skipped. More accurately if true then find by id and find by natural key queries should NOT automatically use the L2 bean cache.- Specified by:
isSkipCache
in interfaceTransaction
-
setSkipCache
public void setSkipCache(boolean skipCache)
Description copied from interface:Transaction
Set if the L2 cache should be skipped for "find by id" and "find by natural key" queries.By default
ServerConfig.isSkipCacheAfterWrite()
is true and that means that for "find by id" and "find by natural key" queries which normally hit L2 bean cache automatically - will not do so after a persist/write on the transaction.This method provides explicit control over whether "find by id" and "find by natural key" will skip the L2 bean cache or not (regardless of whether the transaction is considered "read only").
Refer to
ServerConfig.setSkipCacheAfterWrite(boolean)
for configuring the default behavior for using the L2 bean cache in transactions spanning multiple query/persist requests.// assume Customer has L2 bean caching enabled ... try (Transaction transaction = DB.beginTransaction()) { // this uses L2 bean cache as the transaction // ... is considered "query only" at this point Customer.find.byId(42); // transaction no longer "query only" once // ... a bean has been saved etc someBean.save(); // will NOT use L2 bean cache as the transaction // ... is no longer considered "query only" Customer.find.byId(55); // explicit control - please use L2 bean cache transaction.setSkipCache(false); Customer.find.byId(77); // hit the l2 bean cache // explicit control - please don't use L2 bean cache transaction.setSkipCache(true); Customer.find.byId(99); // skips l2 bean cache transaction.commit(); }
- Specified by:
setSkipCache
in interfaceTransaction
- See Also:
ServerConfig.isSkipCacheAfterWrite()
-
getLogPrefix
public String getLogPrefix()
Description copied from interface:SpiTransaction
Return the string prefix with the transaction id and label used in logging.- Specified by:
getLogPrefix
in interfaceSpiTransaction
-
addBeanChange
public void addBeanChange(BeanChange beanChange)
Description copied from interface:SpiTransaction
Add a bean change to the change log.- Specified by:
addBeanChange
in interfaceSpiTransaction
-
sendChangeLog
public void sendChangeLog(ChangeSet changesRequest)
Description copied from interface:SpiTransaction
Send the change set to be prepared and then logged.- Specified by:
sendChangeLog
in interfaceSpiTransaction
-
register
public void register(TransactionCallback callback)
Description copied from interface:Transaction
Register a TransactionCallback with this transaction.- Specified by:
register
in interfaceTransaction
-
getDocStoreBatchSize
public int getDocStoreBatchSize()
Description copied from interface:SpiTransaction
Return the batch size to us for ElasticSearch Bulk API calls as a result of this transaction.- Specified by:
getDocStoreBatchSize
in interfaceSpiTransaction
-
setDocStoreBatchSize
public void setDocStoreBatchSize(int docStoreBatchSize)
Description copied from interface:Transaction
Set the batch size to use for sending messages to the document store.You might set this if you know the changes in this transaction result in especially large or especially small payloads and want to adjust the batch size to match.
Setting this overrides the default of
DocStoreConfig.getBulkBatchSize()
- Specified by:
setDocStoreBatchSize
in interfaceTransaction
-
getDocStoreMode
public io.ebean.annotation.DocStoreMode getDocStoreMode()
Description copied from interface:SpiTransaction
Return the batchSize specifically set for this transaction or 0.Returning 0 implies to use the system wide default batch size.
- Specified by:
getDocStoreMode
in interfaceSpiTransaction
-
setDocStoreMode
public void setDocStoreMode(io.ebean.annotation.DocStoreMode docStoreMode)
Description copied from interface:Transaction
Set the behavior for document store updates on this transaction.For example, set the mode to DocStoreEvent.IGNORE for this transaction and then any changes via this transaction are not sent to the doc store. This would be used when doing large bulk inserts into the database and we want to control how that is sent to the document store.
- Specified by:
setDocStoreMode
in interfaceTransaction
-
registerDeferred
public void registerDeferred(PersistDeferredRelationship derived)
Description copied from interface:SpiTransaction
Register a "Deferred Relationship" that requires an additional update later.- Specified by:
registerDeferred
in interfaceSpiTransaction
-
registerDeleteBean
public void registerDeleteBean(Integer persistingBean)
Add a bean to the registed list.This is to handle bi-directional relationships where both sides Cascade.
- Specified by:
registerDeleteBean
in interfaceSpiTransaction
-
isRegisteredDeleteBean
public boolean isRegisteredDeleteBean(Integer persistingBean)
Return true if this is a bean that has already been saved/deleted.- Specified by:
isRegisteredDeleteBean
in interfaceSpiTransaction
-
unregisterBeans
public void unregisterBeans()
Unregister the persisted beans (when persisting at the top level).- Specified by:
unregisterBeans
in interfaceSpiTransaction
-
isRegisteredBean
public boolean isRegisteredBean(Object bean)
Return true if this is a bean that has already been saved. This will register the bean if it is not already.- Specified by:
isRegisteredBean
in interfaceSpiTransaction
-
isSaveAssocManyIntersection
public boolean isSaveAssocManyIntersection(String intersectionTable, String beanName)
Return true if the m2m intersection save is allowed from a given bean direction. This is to stop m2m intersection management via both directions of a m2m.- Specified by:
isSaveAssocManyIntersection
in interfaceSpiTransaction
-
depth
public void depth(int diff)
Return the depth of the current persist request plus the diff. This has the effect of changing the current depth and returning the new value. Pass diff=0 to return the current depth.The depth of 0 is for the initial persist request. It is modified as the cascading of the save or delete traverses to the the associated Ones (-1) and associated Manys (+1).
The depth is used to help the ordering of batched statements.
- Specified by:
depth
in interfaceSpiTransaction
- Parameters:
diff
- the amount to add or subtract from the depth.
-
depth
public int depth()
Return the current depth.- Specified by:
depth
in interfaceSpiTransaction
-
markNotQueryOnly
public void markNotQueryOnly()
Description copied from interface:SpiTransaction
Mark the transaction explicitly as not being query only.- Specified by:
markNotQueryOnly
in interfaceSpiTransaction
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:Transaction
Return true if this transaction is read only.- Specified by:
isReadOnly
in interfaceTransaction
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:Transaction
Set whether this transaction should be readOnly.- Specified by:
setReadOnly
in interfaceTransaction
-
setUpdateAllLoadedProperties
public void setUpdateAllLoadedProperties(boolean updateAllLoadedProperties)
Description copied from interface:Transaction
Set to true when you want all loaded properties to be included in the update (rather than just the changed properties).You might set this when using JDBC batch in order to get multiple updates with slightly different sets of changed properties into the same statement and hence better JDBC batch performance.
- Specified by:
setUpdateAllLoadedProperties
in interfaceTransaction
-
isUpdateAllLoadedProperties
public Boolean isUpdateAllLoadedProperties()
Description copied from interface:SpiTransaction
Return true if this transaction has updateAllLoadedProperties set. If null is returned the server default is used (set on ServerConfig).- Specified by:
isUpdateAllLoadedProperties
in interfaceSpiTransaction
-
setBatchMode
public void setBatchMode(boolean batchMode)
Description copied from interface:Transaction
Turn on or off use of JDBC statement batching.Calls to save(), delete(), insert() and execute() all support batch processing. This includes normal beans, CallableSql and UpdateSql.
try (Transaction transaction = database.beginTransaction()) { // turn on JDBC batch transaction.setBatchMode(true); // tune the batch size transaction.setBatchSize(50); ... transaction.commit(); }
getGeneratedKeys
Often with large batch inserts we want to turn off getGeneratedKeys. We do this via
Transaction.setGetGeneratedKeys(boolean)
. Also note that some JDBC drivers do not support getGeneratedKeys in JDBC batch mode.try (Transaction transaction = database.beginTransaction()) { transaction.setBatchMode(true); transaction.setBatchSize(100); // insert but don't bother getting back the generated keys transaction.setBatchGetGeneratedKeys(false); // perform lots of inserts ... ... transaction.commit(); }
Flush
The batch is automatically flushed when it hits the batch size and also when we execute queries or when we mix UpdateSql and CallableSql with save and delete of beans.
We use
Transaction.flush()
to explicitly flush the batch and we can useTransaction.setFlushOnQuery(boolean)
andTransaction.setFlushOnMixed(boolean)
to control the automatic flushing behaviour.Example: batch processing of CallableSql executing every 10 rows
String data = "This is a simple test of the batch processing" + " mode and the transaction execute batch method"; String[] da = data.split(" "); String sql = "{call sp_t3(?,?)}"; CallableSql cs = new CallableSql(sql); cs.registerOut(2, Types.INTEGER); // (optional) inform Ebean this stored procedure // inserts into a table called sp_test cs.addModification("sp_test", true, false, false); try (Transaction txn = DB.beginTransaction()) { txn.setBatchMode(true); txn.setBatchSize(10); for (int i = 0; i < da.length;) { cs.setParameter(1, da[i]); DB.execute(cs); } // Note: commit implicitly flushes txn.commit(); }
- Specified by:
setBatchMode
in interfaceTransaction
-
isBatchMode
public boolean isBatchMode()
Description copied from interface:Transaction
Return the batch mode at the transaction level.- Specified by:
isBatchMode
in interfaceTransaction
-
setBatchOnCascade
public void setBatchOnCascade(boolean batchMode)
Description copied from interface:Transaction
Set the JDBC batch mode to use for a save() or delete() when cascading to children.This only takes effect when batch mode on the transaction has not already meant that JDBC batch mode is being used.
This is useful when the single save() or delete() cascades. For example, inserting a 'master' cascades and inserts a collection of 'detail' beans. The detail beans can be inserted using JDBC batch.
This is effectively already turned on for all platforms apart from older Sql Server.
- Specified by:
setBatchOnCascade
in interfaceTransaction
- Parameters:
batchMode
- the batch mode to use per save(), insert(), update() or delete()- See Also:
ServerConfig.setPersistBatchOnCascade(PersistBatch)
-
isBatchOnCascade
public boolean isBatchOnCascade()
Description copied from interface:Transaction
Return the batch mode at the request level.- Specified by:
isBatchOnCascade
in interfaceTransaction
-
getBatchGetGeneratedKeys
public Boolean getBatchGetGeneratedKeys()
Description copied from interface:SpiTransaction
Return the getGeneratedKeys setting for this transaction.- Specified by:
getBatchGetGeneratedKeys
in interfaceSpiTransaction
-
setGetGeneratedKeys
public void setGetGeneratedKeys(boolean getGeneratedKeys)
Description copied from interface:Transaction
Specify if you want batched inserts to use getGeneratedKeys.By default batched inserts will try to use getGeneratedKeys if it is supported by the underlying jdbc driver and database.
You may want to turn getGeneratedKeys off when you are inserting a large number of objects and you don't care about getting back the ids.
- Specified by:
setGetGeneratedKeys
in interfaceTransaction
-
setFlushOnMixed
public void setFlushOnMixed(boolean batchFlushOnMixed)
Description copied from interface:Transaction
By default when mixing UpdateSql (or CallableSql) with Beans the batch is automatically flushed when you change (between persisting beans and executing UpdateSql or CallableSql).If you want to execute both WITHOUT having the batch automatically flush you need to call this with batchFlushOnMixed = false.
Note that UpdateSql and CallableSql are ALWAYS executed first (before the beans are executed). This is because the UpdateSql and CallableSql have already been bound to their PreparedStatements. The beans on the other hand have a 2 step process (delayed binding).
- Specified by:
setFlushOnMixed
in interfaceTransaction
-
getBatchSize
public int getBatchSize()
Return the batchSize specifically set for this transaction or 0.Returning 0 implies to use the system wide default batch size.
- Specified by:
getBatchSize
in interfaceSpiTransaction
- Specified by:
getBatchSize
in interfaceTransaction
-
setBatchSize
public void setBatchSize(int batchSize)
Description copied from interface:Transaction
Specify the number of statements before a batch is flushed automatically.- Specified by:
setBatchSize
in interfaceTransaction
-
isFlushOnQuery
public boolean isFlushOnQuery()
Description copied from interface:Transaction
Return true if the batch (of persisted beans or executed UpdateSql etc) should be flushed prior to executing a query.The default is for this to be true.
- Specified by:
isFlushOnQuery
in interfaceTransaction
-
setFlushOnQuery
public void setFlushOnQuery(boolean batchFlushOnQuery)
Description copied from interface:Transaction
By default executing a query will automatically flush any batched statements (persisted beans, executed UpdateSql etc).Calling this method with batchFlushOnQuery = false means that you can execute a query and the batch will not be automatically flushed.
- Specified by:
setFlushOnQuery
in interfaceTransaction
-
isBatchThisRequest
public boolean isBatchThisRequest()
Return true if this request should be batched. Returning false means that this request should be executed immediately.- Specified by:
isBatchThisRequest
in interfaceSpiTransaction
-
checkBatchEscalationOnCollection
public void checkBatchEscalationOnCollection()
Description copied from interface:SpiTransaction
Potentially escalate batch mode on saving or deleting a collection.- Specified by:
checkBatchEscalationOnCollection
in interfaceSpiTransaction
-
flushBatchOnCollection
public void flushBatchOnCollection()
Description copied from interface:SpiTransaction
Flush batch if we escalated batch mode on saving or deleting a collection.- Specified by:
flushBatchOnCollection
in interfaceSpiTransaction
-
translate
public javax.persistence.PersistenceException translate(String message, SQLException cause)
Description copied from interface:SpiTransaction
Translate the SQLException.- Specified by:
translate
in interfaceSpiTransaction
-
flushBatchOnCascade
public void flushBatchOnCascade()
Flush after completing persist cascade.- Specified by:
flushBatchOnCascade
in interfaceSpiTransaction
-
flushBatchOnRollback
public void flushBatchOnRollback()
Description copied from interface:SpiTransaction
If batch was on then effectively clear the batch such that we can handle exceptions and continue.- Specified by:
flushBatchOnRollback
in interfaceSpiTransaction
-
checkBatchEscalationOnCascade
public boolean checkBatchEscalationOnCascade(PersistRequestBean<?> request)
Description copied from interface:SpiTransaction
Return true if batch mode got escalated for this request (and associated cascades).- Specified by:
checkBatchEscalationOnCascade
in interfaceSpiTransaction
-
getBatchControl
public BatchControl getBatchControl()
Description copied from interface:SpiTransaction
Return the BatchControl used to batch up persist requests.- Specified by:
getBatchControl
in interfaceSpiTransaction
-
setBatchControl
public void setBatchControl(BatchControl batchControl)
Set the BatchControl to the transaction. This is done once per transaction on the first persist request.- Specified by:
setBatchControl
in interfaceSpiTransaction
-
flush
public void flush()
Flush any queued persist requests.This is general will result in a number of batched PreparedStatements executing.
- Specified by:
flush
in interfaceTransaction
-
flushBatch
public void flushBatch()
Description copied from interface:Transaction
This is a synonym for flush() and will be deprecated.flush() is preferred as it matches the JPA flush() method.
- Specified by:
flushBatch
in interfaceTransaction
-
getPersistenceContext
public PersistenceContext getPersistenceContext()
Return the persistence context associated with this transaction.- Specified by:
getPersistenceContext
in interfaceSpiTransaction
-
setPersistenceContext
public void setPersistenceContext(PersistenceContext context)
Set the persistence context to this transaction.This could be considered similar to EJB3 Extended PersistanceContext. In that you get the PersistanceContext from a transaction, hold onto it, and then set it back later to a second transaction.
- Specified by:
setPersistenceContext
in interfaceSpiTransaction
-
getEvent
public TransactionEvent getEvent()
Return the underlying TransactionEvent.- Specified by:
getEvent
in interfaceSpiTransaction
-
isExplicit
public boolean isExplicit()
Return true if this was an explicitly created transaction.- Specified by:
isExplicit
in interfaceSpiTransaction
-
isLogSql
public boolean isLogSql()
Description copied from interface:SpiTransaction
Return true if generated SQL and Bind values should be logged to the transaction log.- Specified by:
isLogSql
in interfaceSpiTransaction
-
isLogSummary
public boolean isLogSummary()
Description copied from interface:SpiTransaction
Return true if summary level events should be logged to the transaction log.- Specified by:
isLogSummary
in interfaceSpiTransaction
-
logSql
public void logSql(String msg)
Description copied from interface:SpiTransaction
Log a message to the SQL logger.- Specified by:
logSql
in interfaceSpiTransaction
-
logSummary
public void logSummary(String msg)
Description copied from interface:SpiTransaction
Log a message to the SUMMARY logger.- Specified by:
logSummary
in interfaceSpiTransaction
-
getId
public String getId()
Return the transaction id.- Specified by:
getId
in interfaceSpiTransaction
-
setTenantId
public void setTenantId(Object tenantId)
Description copied from interface:SpiTransaction
Set the current Tenant Id.- Specified by:
setTenantId
in interfaceSpiTransaction
-
getTenantId
public Object getTenantId()
Description copied from interface:SpiTransaction
Return the current Tenant Id.- Specified by:
getTenantId
in interfaceSpiTransaction
-
getInternalConnection
public Connection getInternalConnection()
Return the underlying connection for internal use.- Specified by:
getInternalConnection
in interfaceSpiTransaction
-
getConnection
public Connection getConnection()
Return the underlying connection for public use.- Specified by:
getConnection
in interfaceTransaction
-
commitAndContinue
public void commitAndContinue()
Perform a commit, fire callbacks and notify l2 cache etc.This leaves the transaction active and expects another commit to occur later (which closes the underlying connection etc).
- Specified by:
commitAndContinue
in interfaceTransaction
-
isRollbackOnly
public boolean isRollbackOnly()
Return true if the transaction is marked as rollback only.- Specified by:
isRollbackOnly
in interfaceTransaction
-
setRollbackOnly
public void setRollbackOnly()
Mark the transaction as rollback only.- Specified by:
setRollbackOnly
in interfaceTransaction
-
isNestedUseSavepoint
public boolean isNestedUseSavepoint()
Description copied from interface:SpiTransaction
Return true when nested transactions should create Savepoints.- Specified by:
isNestedUseSavepoint
in interfaceSpiTransaction
-
setNestedUseSavepoint
public void setNestedUseSavepoint()
Description copied from interface:Transaction
Set when we want nested transactions to use Savepoint's.This means that for a nested transaction:
- begin transaction maps to creating a savepoint
- commit transaction maps to releasing a savepoint
- rollback transaction maps to rollback a savepoint
- Specified by:
setNestedUseSavepoint
in interfaceTransaction
-
end
public void end() throws javax.persistence.PersistenceException
If the transaction is active then perform rollback.- Specified by:
end
in interfaceTransaction
- Throws:
javax.persistence.PersistenceException
-
isActive
public boolean isActive()
Return true if the transaction is active.- Specified by:
isActive
in interfaceTransaction
-
isPersistCascade
public boolean isPersistCascade()
Description copied from interface:SpiTransaction
Whether persistCascade is on for save and delete.- Specified by:
isPersistCascade
in interfaceSpiTransaction
-
setPersistCascade
public void setPersistCascade(boolean persistCascade)
Description copied from interface:Transaction
Explicitly turn off or on the cascading nature of save() and delete(). This gives the developer exact control over what beans are saved and deleted rather than Ebean cascading detecting 'dirty/modified' beans etc.This is useful if you can getting back entity beans from a layer of code (potentially remote) and you prefer to have exact control.
This may also be useful if you are using jdbc batching with jdbc drivers that do not support getGeneratedKeys.
- Specified by:
setPersistCascade
in interfaceTransaction
-
addModification
public void addModification(String tableName, boolean inserts, boolean updates, boolean deletes)
Description copied from interface:Transaction
Add table modification information to the TransactionEvent.Use this in conjunction with getConnection() and raw JDBC.
This effectively informs Ebean of the data that has been changed by the transaction and this information is normally automatically handled by Ebean when you save entity beans or use UpdateSql etc.
If you use raw JDBC then you can use this method to inform Ebean for the tables that have been modified. Ebean uses this information to keep its caches in synch and maintain text indexes.
- Specified by:
addModification
in interfaceTransaction
-
getDocStoreTransaction
public DocStoreTransaction getDocStoreTransaction()
Description copied from interface:SpiTransaction
Return a document store transaction.- Specified by:
getDocStoreTransaction
in interfaceSpiTransaction
-
putUserObject
public void putUserObject(String name, Object value)
Description copied from interface:Transaction
Add an arbitrary user object to the transaction. The objects added have no impact on any internals of ebean and are solely meant as a convenient method push user information (although somewhat replaced by TransactionCallback).- Specified by:
putUserObject
in interfaceTransaction
-
getUserObject
public Object getUserObject(String name)
Description copied from interface:Transaction
Get an object added withTransaction.putUserObject(String, Object)
.- Specified by:
getUserObject
in interfaceTransaction
-
close
public void close()
Alias for end(), which enables this class to be used in try-with-resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceTransaction
-
-