當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityTransaction.isActive方法代碼示例

本文整理匯總了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();
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:JpaTransactionManager.java

示例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;
}
 
開發者ID:mcarleio,項目名稱:strix,代碼行數:31,代碼來源:StrixManager.java

示例3: rollbackTransactionIfActive

import javax.persistence.EntityTransaction; //導入方法依賴的package包/類
protected void rollbackTransactionIfActive() {
    EntityTransaction transaction = manager.getTransaction();

    if (transaction != null && transaction.isActive()) {
        transaction.rollback();
    }
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:8,代碼來源:Executor.java

示例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();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:JpaTransactionManager.java

示例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();
		}
	}
}
 
開發者ID:IsadoraScusselFarias,項目名稱:ProjetoFinalInitium,代碼行數:28,代碼來源:TransactionInterceptor.java

示例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();
        }
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-extensions,代碼行數:33,代碼來源:EditingContext.java

示例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();
        }
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-extensions,代碼行數:35,代碼來源:EditingContext.java

示例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();
        }
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-extensions,代碼行數:31,代碼來源:EditingContext.java

示例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();
        }
    }
 
開發者ID:optimatika,項目名稱:ojAlgo-extensions,代碼行數:31,代碼來源:EditingContext.java


注:本文中的javax.persistence.EntityTransaction.isActive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。