Java Code Examples for org.springframework.transaction.support.DefaultTransactionStatus#isNewTransaction()

The following examples show how to use org.springframework.transaction.support.DefaultTransactionStatus#isNewTransaction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
	if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
		HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
		Session session = txObject.getSessionHolder().getSession();
		if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
			logger.debug("Performing an early flush for Hibernate transaction");
			try {
				session.flush();
			}
			catch (HibernateException ex) {
				throw convertHibernateAccessException(ex);
			}
			finally {
				session.setFlushMode(FlushMode.MANUAL);
			}
		}
	}
}
 
Example 2
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
	if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
		HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
		Session session = txObject.getSessionHolder().getSession();
		if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
			logger.debug("Performing an early flush for Hibernate transaction");
			try {
				session.flush();
			}
			catch (HibernateException ex) {
				throw convertHibernateAccessException(ex);
			}
			finally {
				session.setFlushMode(FlushMode.MANUAL);
			}
		}
	}
}
 
Example 3
Source File: PostgreSqlTransactionManager.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
  MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Rollback transaction [{}]", transaction.getId());
  }

  DefaultTransactionStatus jpaTransactionStatus =
      new DefaultTransactionStatus(
          transaction.getDataSourceTransaction(),
          status.isNewTransaction(),
          status.isNewSynchronization(),
          status.isReadOnly(),
          status.isDebug(),
          status.getSuspendedResources());

  if (!status.isReadOnly()) {
    transactionListeners.forEach(j -> j.rollbackTransaction(transaction.getId()));
  }

  super.doRollback(jpaTransactionStatus);
}
 
Example 4
Source File: PostgreSqlTransactionManager.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) {
  MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Commit transaction [{}]", transaction.getId());
  }

  DefaultTransactionStatus jpaTransactionStatus =
      new DefaultTransactionStatus(
          transaction.getDataSourceTransaction(),
          status.isNewTransaction(),
          status.isNewSynchronization(),
          status.isReadOnly(),
          status.isDebug(),
          status.getSuspendedResources());

  if (!status.isReadOnly()) {
    transactionListeners.forEach(j -> j.commitTransaction(transaction.getId()));
  }

  try {
    super.doCommit(jpaTransactionStatus);
  } catch (TransactionException e) {
    throw translateTransactionException(e);
  }

  if (!status.isReadOnly()) {
    transactionListeners.forEach(j -> j.afterCommitTransaction(transaction.getId()));
  }
}
 
Example 5
Source File: PostgreSqlTransactionManager.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
  MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();

  DefaultTransactionStatus jpaTransactionStatus =
      new DefaultTransactionStatus(
          transaction.getDataSourceTransaction(),
          status.isNewTransaction(),
          status.isNewSynchronization(),
          status.isReadOnly(),
          status.isDebug(),
          status.getSuspendedResources());

  super.doSetRollbackOnly(jpaTransactionStatus);
}
 
Example 6
Source File: PersistenceTransactionalTestConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Override
protected void prepareSynchronization(DefaultTransactionStatus status, TransactionDefinition definition) {
    super.prepareSynchronization(status, definition);
    if (status.isNewTransaction()) {
        if ( adapterSpyThreadLocal.get() == null ){
            TransactionSynchronizationAdapterSpy spy = new TransactionSynchronizationAdapterSpy();
            TransactionSynchronizationManager.registerSynchronization(spy);
            adapterSpyThreadLocal.set(spy);
        }
        adapterSpyThreadLocal.get().create();
    }
}
 
Example 7
Source File: ContextSourceAndHibernateTransactionManager.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
protected void doCommit(DefaultTransactionStatus status) {

        ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) status
                .getTransaction();

        try {
            super.doCommit(new DefaultTransactionStatus(actualTransactionObject
                    .getHibernateTransactionObject(), status
                    .isNewTransaction(), status.isNewSynchronization(), status
                    .isReadOnly(), status.isDebug(), status
                    .getSuspendedResources()));
        } catch (TransactionException ex) {
            if (isRollbackOnCommitFailure()) {
                logger.debug("Failed to commit db resource, rethrowing", ex);
                // If we are to rollback on commit failure, just rethrow the
                // exception - this will cause a rollback to be performed on
                // both resources.
                throw ex;
            } else {
                logger
                        .warn("Failed to commit and resource is rollbackOnCommit not set -"
                                + " proceeding to commit ldap resource.");
            }
        }
        ldapManagerDelegate.doCommit(new DefaultTransactionStatus(
                actualTransactionObject.getLdapTransactionObject(), status
                        .isNewTransaction(), status.isNewSynchronization(),
                status.isReadOnly(), status.isDebug(), status
                        .getSuspendedResources()));
    }
 
Example 8
Source File: ContextSourceAndHibernateTransactionManager.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
protected void doRollback(DefaultTransactionStatus status) {
    ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) status
            .getTransaction();

    super.doRollback(new DefaultTransactionStatus(actualTransactionObject
            .getHibernateTransactionObject(), status.isNewTransaction(),
            status.isNewSynchronization(), status.isReadOnly(), status
                    .isDebug(), status.getSuspendedResources()));
    ldapManagerDelegate.doRollback(new DefaultTransactionStatus(
            actualTransactionObject.getLdapTransactionObject(), status
                    .isNewTransaction(), status.isNewSynchronization(),
            status.isReadOnly(), status.isDebug(), status
                    .getSuspendedResources()));
}
 
Example 9
Source File: ContextSourceAndDataSourceTransactionManager.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
protected void doCommit(DefaultTransactionStatus status) {

        ContextSourceAndDataSourceTransactionObject actualTransactionObject = (ContextSourceAndDataSourceTransactionObject) status
                .getTransaction();

        try {
            super.doCommit(new DefaultTransactionStatus(actualTransactionObject
                    .getDataSourceTransactionObject(), status
                    .isNewTransaction(), status.isNewSynchronization(), status
                    .isReadOnly(), status.isDebug(), status
                    .getSuspendedResources()));
        } catch (TransactionException ex) {
            if (isRollbackOnCommitFailure()) {
                logger.debug("Failed to commit db resource, rethrowing", ex);
                // If we are to rollback on commit failure, just rethrow the
                // exception - this will cause a rollback to be performed on
                // both resources.
                throw ex;
            } else {
                logger
                        .warn("Failed to commit and resource is rollbackOnCommit not set -"
                                + " proceeding to commit ldap resource.");
            }
        }
        ldapManagerDelegate.doCommit(new DefaultTransactionStatus(
                actualTransactionObject.getLdapTransactionObject(), status
                        .isNewTransaction(), status.isNewSynchronization(),
                status.isReadOnly(), status.isDebug(), status
                        .getSuspendedResources()));
    }
 
Example 10
Source File: ContextSourceAndDataSourceTransactionManager.java    From spring-ldap with Apache License 2.0 5 votes vote down vote up
protected void doRollback(DefaultTransactionStatus status) {
    ContextSourceAndDataSourceTransactionObject actualTransactionObject = (ContextSourceAndDataSourceTransactionObject) status
            .getTransaction();

    super.doRollback(new DefaultTransactionStatus(actualTransactionObject
            .getDataSourceTransactionObject(), status.isNewTransaction(),
            status.isNewSynchronization(), status.isReadOnly(), status
                    .isDebug(), status.getSuspendedResources()));
    ldapManagerDelegate.doRollback(new DefaultTransactionStatus(
            actualTransactionObject.getLdapTransactionObject(), status
                    .isNewTransaction(), status.isNewSynchronization(),
            status.isReadOnly(), status.isDebug(), status
                    .getSuspendedResources()));
}