本文整理匯總了Java中javax.persistence.EntityTransaction.isActive方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityTransaction.isActive方法的具體用法?Java EntityTransaction.isActive怎麽用?Java EntityTransaction.isActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.EntityTransaction
的用法示例。
在下文中一共展示了EntityTransaction.isActive方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doRollback
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
@Override
protected void doRollback(DefaultTransactionStatus status) {
JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
if (status.isDebug()) {
logger.debug("Rolling back JPA transaction on EntityManager [" +
txObject.getEntityManagerHolder().getEntityManager() + "]");
}
try {
EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
if (tx.isActive()) {
tx.rollback();
}
}
catch (PersistenceException ex) {
throw new TransactionSystemException("Could not roll back JPA transaction", ex);
}
finally {
if (!txObject.isNewEntityManagerHolder()) {
// Clear all pending inserts/updates/deletes in the EntityManager.
// Necessary for pre-bound EntityManagers, to avoid inconsistent state.
txObject.getEntityManagerHolder().getEntityManager().clear();
}
}
}
示例2: startTimeoutChecker
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
/**
* Starts a thread which will close the {@code em} after the specified {@code timeoutTime}.
*
* @param timeoutTime Time in milliseconds
* @param em The {@link EntityManager}, which may be used of the aspected method
* @param transaction The {@link EntityTransaction}, which will be marked as rollback-only if the timeout is reached
* @return The started timeout thread
*/
static Thread startTimeoutChecker(final int timeoutTime, EntityManager em, EntityTransaction transaction) {
LOG.trace("Starts the timeout thread with {}ms", timeoutTime);
Thread thread = new Thread(() -> {
try {
Thread.currentThread().setName("STRIX-TT");
Thread.sleep(timeoutTime);
LOG.trace("Timeout thread reached timeout time ({}ms)", timeoutTime);
if (em.isOpen()) {
if (transaction.isActive()) {
LOG.trace("Mark the transaction to rollbackOnly");
transaction.setRollbackOnly();
}
LOG.trace("Close EntityManager");
em.close();
}
} catch (InterruptedException ex) {
// Ignore InterruptedException
}
});
thread.start();
return thread;
}
示例3: rollbackTransactionIfActive
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
protected void rollbackTransactionIfActive() {
EntityTransaction transaction = manager.getTransaction();
if (transaction != null && transaction.isActive()) {
transaction.rollback();
}
}
示例4: setRollbackOnly
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void setRollbackOnly() {
EntityTransaction tx = this.entityManagerHolder.getEntityManager().getTransaction();
if (tx.isActive()) {
tx.setRollbackOnly();
}
if (hasConnectionHolder()) {
getConnectionHolder().setRollbackOnly();
}
}
示例5: invoke
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
@AroundInvoke
public Object invoke(InvocationContext context) throws Exception {
EntityTransaction transaction = manager.getTransaction();
boolean owner = false;
try {
if (!transaction.isActive()) {
transaction.begin();
transaction.rollback();
transaction.begin();
owner = true;
}
return context.proceed();
} catch (Exception e) {
if (transaction != null && owner) {
transaction.rollback();
}
throw e;
} finally {
if (transaction != null && transaction.isActive() && owner) {
transaction.commit();
}
}
}
示例6: delete
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void delete(final AbstractBO<?> aBO) {
if (!aBO.getEditingContext().equals(this)) {
throw new IllegalStateException();
}
final EntityManager tmpEntityManager = myEntityManager;
final EntityTransaction tmpTransaction = tmpEntityManager.getTransaction();
aBO.prependAdditionalDeletes(this);
tmpTransaction.begin();
tmpEntityManager.remove(aBO.getEntityBean());
try {
tmpTransaction.commit();
} catch (final Exception anException) {
BasicLogger.error(anException.toString());
if ((tmpTransaction != null) && tmpTransaction.isActive()) {
tmpTransaction.rollback();
}
} finally {
this.flushCaches();
}
}
示例7: insert
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void insert(final AbstractBO<?> aBO) {
if (!aBO.getEditingContext().equals(this)) {
throw new IllegalStateException();
}
final EntityManager tmpEntityManager = myEntityManager;
final EntityTransaction tmpTransaction = tmpEntityManager.getTransaction();
aBO.appendAdditionalInserts(this);
tmpTransaction.begin();
tmpEntityManager.persist(aBO.getEntityBean());
try {
tmpTransaction.commit();
this.putDataAccessObject(aBO.getEntityBean(), aBO);
} catch (final Exception anException) {
BasicLogger.error(anException.toString());
if ((tmpTransaction != null) && tmpTransaction.isActive()) {
tmpTransaction.rollback();
}
} finally {
this.flushCaches();
}
}
示例8: refresh
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void refresh(final AbstractBO<?> aBO) {
if (!aBO.getEditingContext().equals(this)) {
throw new IllegalStateException();
}
final EntityManager tmpEntityManager = myEntityManager;
final EntityTransaction tmpTransaction = tmpEntityManager.getTransaction();
tmpTransaction.begin();
tmpEntityManager.refresh(aBO.getEntityBean());
try {
tmpTransaction.commit();
} catch (final Exception anException) {
BasicLogger.error(anException.toString());
if ((tmpTransaction != null) && tmpTransaction.isActive()) {
tmpTransaction.rollback();
}
} finally {
this.flushCaches();
}
}
示例9: update
import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
public void update(final AbstractBO<?> aBO) {
if (!aBO.getEditingContext().equals(this)) {
throw new IllegalStateException();
}
final EntityManager tmpEntityManager = myEntityManager;
final EntityTransaction tmpTransaction = tmpEntityManager.getTransaction();
tmpTransaction.begin();
tmpEntityManager.merge(aBO.getEntityBean());
try {
tmpTransaction.commit();
} catch (final Exception anException) {
BasicLogger.error(anException.toString());
if ((tmpTransaction != null) && tmpTransaction.isActive()) {
tmpTransaction.rollback();
}
} finally {
this.flushCaches();
}
}