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

The following examples show how to use org.springframework.transaction.support.DefaultTransactionStatus#isReadOnly() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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()));
}