Java 类org.springframework.transaction.NestedTransactionNotSupportedException 实例源码

项目:spring4-understanding    文件:WebSphereUowTransactionManagerTests.java   
@Test
public void propagationNestedFailsInCaseOfExistingTransaction() {
    MockUOWManager manager = new MockUOWManager();
    manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);

    try {
        ptm.execute(definition, new TransactionCallback<String>() {
            @Override
            public String doInTransaction(TransactionStatus status) {
                return "result";
            }
        });
        fail("Should have thrown NestedTransactionNotSupportedException");
    }
    catch (NestedTransactionNotSupportedException ex) {
        // expected
    }
}
项目:class-guard    文件:WebSphereUowTransactionManagerTests.java   
public void testPropagationNestedFailsInCaseOfExistingTransaction() {
    MockUOWManager manager = new MockUOWManager();
    manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);

    try {
        ptm.execute(definition, new TransactionCallback() {
            @Override
            public Object doInTransaction(TransactionStatus status) {
                return "result";
            }
        });
        fail("Should have thrown NestedTransactionNotSupportedException");
    }
    catch (NestedTransactionNotSupportedException ex) {
        // expected
    }
}
项目:lams    文件:DefaultTransactionStatus.java   
/**
 * This implementation exposes the SavepointManager interface
 * of the underlying transaction object, if any.
 */
@Override
protected SavepointManager getSavepointManager() {
    if (!isTransactionSavepointManager()) {
        throw new NestedTransactionNotSupportedException(
            "Transaction object [" + getTransaction() + "] does not support savepoints");
    }
    return (SavepointManager) getTransaction();
}
项目:lams    文件:JdbcTransactionObjectSupport.java   
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    if (!hasConnectionHolder()) {
        throw new TransactionUsageException(
                "Cannot create nested transaction if not exposing a JDBC transaction");
    }
    return getConnectionHolder();
}
项目:lams    文件:JpaTransactionManager.java   
private SavepointManager getSavepointManager() {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    SavepointManager savepointManager = getEntityManagerHolder().getSavepointManager();
    if (savepointManager == null) {
        throw new NestedTransactionNotSupportedException(
                "JpaDialect does not support savepoints - check your JPA provider's capabilities");
    }
    return savepointManager;
}
项目:spring4-understanding    文件:JpaTransactionManager.java   
private SavepointManager getSavepointManager() {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    SavepointManager savepointManager = getEntityManagerHolder().getSavepointManager();
    if (savepointManager == null) {
        throw new NestedTransactionNotSupportedException(
                "JpaDialect does not support savepoints - check your JPA provider's capabilities");
    }
    return savepointManager;
}
项目:spring4-understanding    文件:DefaultTransactionStatus.java   
/**
 * This implementation exposes the SavepointManager interface
 * of the underlying transaction object, if any.
 */
@Override
protected SavepointManager getSavepointManager() {
    if (!isTransactionSavepointManager()) {
        throw new NestedTransactionNotSupportedException(
            "Transaction object [" + getTransaction() + "] does not support savepoints");
    }
    return (SavepointManager) getTransaction();
}
项目:spring4-understanding    文件:JdbcTransactionObjectSupport.java   
/**
 * This implementation creates a JDBC 3.0 Savepoint and returns it.
 * @see java.sql.Connection#setSavepoint
 */
@Override
public Object createSavepoint() throws TransactionException {
    ConnectionHolder conHolder = getConnectionHolderForSavepoint();
    try {
        if (!conHolder.supportsSavepoints()) {
            throw new NestedTransactionNotSupportedException(
                    "Cannot create a nested transaction because savepoints are not supported by your JDBC driver");
        }
        return conHolder.createSavepoint();
    }
    catch (SQLException ex) {
        throw new CannotCreateTransactionException("Could not create JDBC savepoint", ex);
    }
}
项目:spring4-understanding    文件:JdbcTransactionObjectSupport.java   
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    if (!hasConnectionHolder()) {
        throw new TransactionUsageException(
                "Cannot create nested transaction if not exposing a JDBC transaction");
    }
    return getConnectionHolder();
}
项目:xap-openspaces    文件:AbstractJiniTransactionManager.java   
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
    JiniTransactionObject txObject = (JiniTransactionObject) transaction;
    if (logger.isTraceEnabled())
        logger.trace(logMessage("Beginning transaction [" + txObject + "]"));
    try {
        doJiniBegin(txObject, definition);
    } catch (UnsupportedOperationException ex) {
        // assume nested transaction not supported
        throw new NestedTransactionNotSupportedException("Implementation does not ex nested transactions", ex);
    }
}
项目:ef-orm    文件:JefJpaDialect.java   
public Object createSavepoint() throws TransactionException {
    this.savepointCounter++;
    String savepointName = ConnectionHolder.SAVEPOINT_NAME_PREFIX + this.savepointCounter;
    try {
        Savepoint sp=this.entityManager.setSavepoint(savepointName);
        return sp;
    } catch (SavepointNotSupportedException e) {
        throw new NestedTransactionNotSupportedException("Cannot create a nested transaction because savepoints are not supported.");
    } catch (Throwable ex) {
        throw new CannotCreateTransactionException("Could not create JDBC savepoint", ex);
    }
}
项目:class-guard    文件:JpaTransactionManager.java   
private SavepointManager getSavepointManager() {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    SavepointManager savepointManager = getEntityManagerHolder().getSavepointManager();
    if (savepointManager == null) {
        throw new NestedTransactionNotSupportedException(
                "JpaDialect does not support savepoints - check your JPA provider's capabilities");
    }
    return savepointManager;
}
项目:class-guard    文件:DefaultTransactionStatus.java   
/**
 * This implementation exposes the SavepointManager interface
 * of the underlying transaction object, if any.
 */
@Override
protected SavepointManager getSavepointManager() {
    if (!isTransactionSavepointManager()) {
        throw new NestedTransactionNotSupportedException(
            "Transaction object [" + getTransaction() + "] does not support savepoints");
    }
    return (SavepointManager) getTransaction();
}
项目:class-guard    文件:JdbcTransactionObjectSupport.java   
protected ConnectionHolder getConnectionHolderForSavepoint() throws TransactionException {
    if (!isSavepointAllowed()) {
        throw new NestedTransactionNotSupportedException(
                "Transaction manager does not allow nested transactions");
    }
    if (!hasConnectionHolder()) {
        throw new TransactionUsageException(
                "Cannot create nested transaction if not exposing a JDBC transaction");
    }
    return getConnectionHolder();
}
项目:hazelcastmq    文件:HazelcastUtils.java   
/**
 * Returns the transaction context holder bound to the current transaction. If
 * one cannot be found and a transaction is active, a new one will be created
 * and bound to the thread. If one cannot be found and a transaction is not
 * active, this method returns null.
 *
 * @param hazelcastInstance the Hazelcast instance used to create begin a
 * transaction if needed
 *
 * @return the transaction context holder if a transaction is active, null
 * otherwise
 */
private static TransactionContext getHazelcastTransactionContext(
    HazelcastInstance hazelcastInstance,
    boolean synchedLocalTransactionAllowed) {

  HazelcastTransactionContextHolder conHolder =
      (HazelcastTransactionContextHolder) TransactionSynchronizationManager.
      getResource(hazelcastInstance);

  if (conHolder != null && (conHolder.hasTransactionContext() || conHolder.
      isSynchronizedWithTransaction())) {
    // We are already synchronized with the transaction which means
    // someone already requested a transactional resource or the transaction
    // is being managed at the top level by HazelcastTransactionManager.

    if (!conHolder.hasTransactionContext()) {
      // I think this means we are synchronized with the transaction but
      // we don't have a transactional context because the transaction was
      // suspended. I don't see how we can do this with Hazelcast because
      // it binds the transaction context to the thread and doesn't
      // supported nested transactions. Maybe I'm missing something.

      throw new NestedTransactionNotSupportedException("Trying to resume a "
          + "Hazelcast transaction? Can't do that.");
    }
  }
  else if (TransactionSynchronizationManager.isSynchronizationActive()
      && synchedLocalTransactionAllowed) {
    // No holder or no transaction context but we want to be
    // synchronized to the transaction.
    if (conHolder == null) {
      conHolder = new HazelcastTransactionContextHolder();
      TransactionSynchronizationManager.bindResource(hazelcastInstance,
          conHolder);
    }

    TransactionContext transactionContext = hazelcastInstance.
        newTransactionContext();
    transactionContext.beginTransaction();

    conHolder.setTransactionContext(transactionContext);
    conHolder.setSynchronizedWithTransaction(true);
    conHolder.setTransactionActive(true);
    TransactionSynchronizationManager.registerSynchronization(
        new HazelcastTransactionSynchronization(conHolder, hazelcastInstance));
  }

  return conHolder != null ? conHolder.getTransactionContext() : null;
}
项目:lams    文件:AbstractTransactionStatus.java   
/**
 * Return a SavepointManager for the underlying transaction, if possible.
 * <p>Default implementation always throws a NestedTransactionNotSupportedException.
 * @throws org.springframework.transaction.NestedTransactionNotSupportedException
 * if the underlying transaction does not support savepoints
 */
protected SavepointManager getSavepointManager() {
    throw new NestedTransactionNotSupportedException("This transaction does not support savepoints");
}
项目:spring4-understanding    文件:AbstractTransactionStatus.java   
/**
 * Return a SavepointManager for the underlying transaction, if possible.
 * <p>Default implementation always throws a NestedTransactionNotSupportedException.
 * @throws org.springframework.transaction.NestedTransactionNotSupportedException
 * if the underlying transaction does not support savepoints
 */
protected SavepointManager getSavepointManager() {
    throw new NestedTransactionNotSupportedException("This transaction does not support savepoints");
}
项目:class-guard    文件:AbstractTransactionStatus.java   
/**
 * Return a SavepointManager for the underlying transaction, if possible.
 * <p>Default implementation always throws a NestedTransactionNotSupportedException.
 * @throws org.springframework.transaction.NestedTransactionNotSupportedException
 * if the underlying transaction does not support savepoints
 */
protected SavepointManager getSavepointManager() {
    throw new NestedTransactionNotSupportedException("This transaction does not support savepoints");
}