Package org.springframework.transaction

Examples of org.springframework.transaction.IllegalTransactionStateException


      throw new InvalidTimeoutException("Invalid transaction timeout", definition.getTimeout());
    }

    // No existing transaction found -> check propagation behavior to find out how to proceed.
    if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_MANDATORY) {
      throw new IllegalTransactionStateException(
          "No existing transaction found for transaction marked with propagation 'mandatory'");
    }
    else if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRED ||
        definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW ||
        definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NESTED) {
View Full Code Here


  private TransactionStatus handleExistingTransaction(
      TransactionDefinition definition, Object transaction, boolean debugEnabled)
      throws TransactionException {

    if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NEVER) {
      throw new IllegalTransactionStateException(
          "Existing transaction found for transaction marked with propagation 'never'");
    }

    if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
      if (debugEnabled) {
        logger.debug("Suspending current transaction");
      }
      Object suspendedResources = suspend(transaction);
      boolean newSynchronization = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS);
      return prepareTransactionStatus(
          definition, null, false, newSynchronization, debugEnabled, suspendedResources);
    }

    if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW) {
      if (debugEnabled) {
        logger.debug("Suspending current transaction, creating new transaction with name [" +
            definition.getName() + "]");
      }
      SuspendedResourcesHolder suspendedResources = suspend(transaction);
      try {
        boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
        DefaultTransactionStatus status = newTransactionStatus(
            definition, transaction, true, newSynchronization, debugEnabled, suspendedResources);
        doBegin(transaction, definition);
        prepareSynchronization(status, definition);
        return status;
      }
      catch (RuntimeException beginEx) {
        resumeAfterBeginException(transaction, suspendedResources, beginEx);
        throw beginEx;
      }
      catch (Error beginErr) {
        resumeAfterBeginException(transaction, suspendedResources, beginErr);
        throw beginErr;
      }
    }

    if (definition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NESTED) {
      if (!isNestedTransactionAllowed()) {
        throw new NestedTransactionNotSupportedException(
            "Transaction manager does not allow nested transactions by default - " +
            "specify 'nestedTransactionAllowed' property with value 'true'");
      }
      if (debugEnabled) {
        logger.debug("Creating nested transaction with name [" + definition.getName() + "]");
      }
      if (useSavepointForNestedTransaction()) {
        // Create savepoint within existing Spring-managed transaction,
        // through the SavepointManager API implemented by TransactionStatus.
        // Usually uses JDBC 3.0 savepoints. Never activates Spring synchronization.
        DefaultTransactionStatus status =
            prepareTransactionStatus(definition, transaction, false, false, debugEnabled, null);
        status.createAndHoldSavepoint();
        return status;
      }
      else {
        // Nested transaction through nested begin and commit/rollback calls.
        // Usually only for JTA: Spring synchronization might get activated here
        // in case of a pre-existing JTA transaction.
        boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
        DefaultTransactionStatus status = newTransactionStatus(
            definition, transaction, true, newSynchronization, debugEnabled, null);
        doBegin(transaction, definition);
        prepareSynchronization(status, definition);
        return status;
      }
    }

    // Assumably PROPAGATION_SUPPORTS or PROPAGATION_REQUIRED.
    if (debugEnabled) {
      logger.debug("Participating in existing transaction");
    }
    if (isValidateExistingTransaction()) {
      if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        Integer currentIsolationLevel = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
        if (currentIsolationLevel == null || currentIsolationLevel != definition.getIsolationLevel()) {
          Constants isoConstants = DefaultTransactionDefinition.constants;
          throw new IllegalTransactionStateException("Participating transaction with definition [" +
              definition + "] specifies isolation level which is incompatible with existing transaction: " +
              (currentIsolationLevel != null ?
                  isoConstants.toCode(currentIsolationLevel, DefaultTransactionDefinition.PREFIX_ISOLATION) :
                  "(unknown)"));
        }
      }
      if (!definition.isReadOnly()) {
        if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
          throw new IllegalTransactionStateException("Participating transaction with definition [" +
              definition + "] is not marked as read-only but existing transaction is");
        }
      }
    }
    boolean newSynchronization = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
View Full Code Here

   * @see #doCommit
   * @see #rollback
   */
  public final void commit(TransactionStatus status) throws TransactionException {
    if (status.isCompleted()) {
      throw new IllegalTransactionStateException(
          "Transaction is already completed - do not call commit or rollback more than once per transaction");
    }

    DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
    if (defStatus.isLocalRollbackOnly()) {
View Full Code Here

   * @see #doRollback
   * @see #doSetRollbackOnly
   */
  public final void rollback(TransactionStatus status) throws TransactionException {
    if (status.isCompleted()) {
      throw new IllegalTransactionStateException(
          "Transaction is already completed - do not call commit or rollback more than once per transaction");
    }

    DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
    processRollback(defStatus);
View Full Code Here

   * supported. Subclasses are of course encouraged to provide such support.
   * @param status the status representation of the transaction
   * @throws TransactionException in case of system errors
   */
  protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException {
    throw new IllegalTransactionStateException(
        "Participating in existing transactions is not supported - when 'isExistingTransaction' " +
        "returns true, appropriate 'doSetRollbackOnly' behavior must be provided");
  }
View Full Code Here

    JtaTransactionObject txObject = (JtaTransactionObject) transaction;
    try {
      doJtaResume(txObject, suspendedResources);
    }
    catch (InvalidTransactionException ex) {
      throw new IllegalTransactionStateException("Tried to resume invalid JTA transaction", ex);
    }
    catch (IllegalStateException ex) {
      throw new TransactionSystemException("Unexpected internal transaction state", ex);
    }
    catch (SystemException ex) {
View Full Code Here

  @Override
  protected void doBegin(Object transaction, TransactionDefinition definition) {
    HibernateTransactionObject txObject = (HibernateTransactionObject) transaction;

    if (txObject.hasConnectionHolder() && !txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
      throw new IllegalTransactionStateException(
          "Pre-bound JDBC Connection found! HibernateTransactionManager does not support " +
          "running within DataSourceTransactionManager if told to manage the DataSource itself. " +
          "It is recommended to use a single HibernateTransactionManager for all transactions " +
          "on a single DataSource, no matter whether Hibernate or JDBC access.");
    }
View Full Code Here

  protected void doBegin(Object transaction, TransactionDefinition definition) {
    HibernateTransactionObject txObject = (HibernateTransactionObject) transaction;

    if (txObject.hasConnectionHolder() && !txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
      throw new IllegalTransactionStateException(
          "Pre-bound JDBC Connection found! HibernateTransactionManager does not support " +
          "running within DataSourceTransactionManager if told to manage the DataSource itself. " +
          "It is recommended to use a single HibernateTransactionManager for all transactions " +
          "on a single DataSource, no matter whether Hibernate or JDBC access.");
    }
View Full Code Here

    boolean joinTx = false;
    boolean newSynch = false;

    if (existingTx) {
      if (pb == TransactionDefinition.PROPAGATION_NEVER) {
        throw new IllegalTransactionStateException(
            "Transaction propagation 'never' but existing transaction found");
      }
      if (pb == TransactionDefinition.PROPAGATION_NESTED) {
        throw new NestedTransactionNotSupportedException(
            "Transaction propagation 'nested' not supported for WebSphere UOW transactions");
      }
      if (pb == TransactionDefinition.PROPAGATION_SUPPORTS ||
          pb == TransactionDefinition.PROPAGATION_REQUIRED || pb == TransactionDefinition.PROPAGATION_MANDATORY) {
        joinTx = true;
        newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
      }
      else if (pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
        uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION;
        newSynch = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS);
      }
      else {
        newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
      }
    }
    else {
      if (pb == TransactionDefinition.PROPAGATION_MANDATORY) {
        throw new IllegalTransactionStateException(
            "Transaction propagation 'mandatory' but no existing transaction found");
      }
      if (pb == TransactionDefinition.PROPAGATION_SUPPORTS ||
          pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED || pb == TransactionDefinition.PROPAGATION_NEVER) {
        uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION;
View Full Code Here

  protected void doBegin(Object transaction, TransactionDefinition definition) {
    JdoTransactionObject txObject = (JdoTransactionObject) transaction;

    if (txObject.hasConnectionHolder() && !txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
      throw new IllegalTransactionStateException(
          "Pre-bound JDBC Connection found! JdoTransactionManager does not support " +
          "running within DataSourceTransactionManager if told to manage the DataSource itself. " +
          "It is recommended to use a single JdoTransactionManager for all transactions " +
          "on a single DataSource, no matter whether JDO or JDBC access.");
    }
View Full Code Here

TOP

Related Classes of org.springframework.transaction.IllegalTransactionStateException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.