Package org.hibernate.ejb.transaction

Examples of org.hibernate.ejb.transaction.JoinableCMTTransaction


        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = (JoinableCMTTransaction) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = (TransactionFactory.Context) session;
                    JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null )
                      log.warn( "Transaction not available on beforeCompletionPhase: assuming valid" );
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                        //transaction == null workaround a JBoss TMBug
                  }
                  catch (SystemException se) {
                    log.error( "could not determine transaction status", se );
                    //throwPersistenceException will mark the transaction as rollbacked
                    throwPersistenceException(
                        new PersistenceException(
                            "could not determine transaction status in beforeCompletion()",
                            se
                        )
                    );
                  }
                  catch (HibernateException he) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch (RuntimeException re) {
                    //throwPersistenceException will mark the transaction as rollbacked
                    if ( re instanceof HibernateException ) {
                      throwPersistenceException( (HibernateException) re );
                    }
                    else {
                      throwPersistenceException( new PersistenceException( re ) );
                    }
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch (HibernateException e) {
                    throwPersistenceException( e );
                  }
View Full Code Here


        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = ( TransactionFactory.Context ) session;
                    JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null ) {
                      log.warn(
                          "Transaction not available on beforeCompletionPhase: assuming valid"
                      );
                    }
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                    //transaction == null workaround a JBoss TMBug
                  }
                  catch ( SystemException se ) {
                    log.error( "could not determine transaction status", se );
                    PersistenceException pe = new PersistenceException(
                        "could not determine transaction status in beforeCompletion()",
                        se
                    );
                    // handlePersistenceException will mark the transaction as rollbacked
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( HibernateException he ) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch ( HibernateException he ) {
                    throw convert( he );
                  }
                  catch ( PersistenceException pe ) {
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( RuntimeException re ) {
                    PersistenceException wrapped = new PersistenceException( re );
                    handlePersistenceException( wrapped );
                    throw wrapped;
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          CallbackCoordinator callbackCoordinator = ( (SessionImplementor ) getSession() ).getJDBCContext().getJtaSynchronizationCallbackCoordinator();
          if ( callbackCoordinator == null ) {
            throw new AssertionFailure( "Expecting CallbackCoordinator to be non-null" );
          }
          callbackCoordinator.setBeforeCompletionManagedFlushChecker(
              new BeforeCompletionManagedFlushChecker() {
                public boolean shouldDoManagedFlush(TransactionFactory.Context ctx, javax.transaction.Transaction jtaTransaction)
                    throws SystemException {
                  if ( transaction == null ) {
                    log.warn( "Transaction not available on beforeCompletion: assuming valid" );
                  }
                  return !ctx.isFlushModeNever()
                      && ( jtaTransaction == null || !JTAHelper.isRollback( jtaTransaction.getStatus() ) );
                }
              }
          );
          callbackCoordinator.setAfterCompletionAction(
              new AfterCompletionAction() {
                public void doAction(TransactionFactory.Context ctx, int status) {
                  try {
                    if ( !ctx.isClosed() ) {
                      if ( Status.STATUS_ROLLEDBACK == status
                          && transactionType == PersistenceUnitTransactionType.JTA ) {
                        session.clear();
                      }
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = ( TransactionFactory.Context ) session;
                    JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null ) {
                      log.warn(
                          "Transaction not available on beforeCompletionPhase: assuming valid"
                      );
                    }
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                    //transaction == null workaround a JBoss TMBug
                  }
                  catch ( SystemException se ) {
                    log.error( "could not determine transaction status", se );
                    PersistenceException pe = new PersistenceException(
                        "could not determine transaction status in beforeCompletion()",
                        se
                    );
                    // handlePersistenceException will mark the transaction as rollbacked
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( HibernateException he ) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch ( HibernateException he ) {
                    throw convert( he );
                  }
                  catch( PersistenceException pe ) {
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( RuntimeException re ) {
                    PersistenceException wrapped = new PersistenceException( re );
                    handlePersistenceException( wrapped );
                    throw wrapped;
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = ( TransactionFactory.Context ) session;
                    JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null ) {
                      log.warn(
                          "Transaction not available on beforeCompletionPhase: assuming valid"
                      );
                    }
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                    //transaction == null workaround a JBoss TMBug
                  }
                  catch ( SystemException se ) {
                    log.error( "could not determine transaction status", se );
                    PersistenceException pe = new PersistenceException(
                        "could not determine transaction status in beforeCompletion()",
                        se
                    );
                    // handlePersistenceException will mark the transaction as rollbacked
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( HibernateException he ) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch ( HibernateException he ) {
                    throw convert( he );
                  }
                  catch( PersistenceException pe ) {
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( RuntimeException re ) {
                    PersistenceException wrapped = new PersistenceException( re );
                    handlePersistenceException( wrapped );
                    throw wrapped;
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = ( TransactionFactory.Context ) session;
                    JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null ) {
                      log.warn(
                          "Transaction not available on beforeCompletionPhase: assuming valid"
                      );
                    }
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                    //transaction == null workaround a JBoss TMBug
                  }
                  catch ( SystemException se ) {
                    log.error( "could not determine transaction status", se );
                    PersistenceException pe = new PersistenceException(
                        "could not determine transaction status in beforeCompletion()",
                        se
                    );
                    // handlePersistenceException will mark the transaction as rollbacked
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( HibernateException he ) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch ( HibernateException he ) {
                    throw convert( he );
                  }
                  catch( PersistenceException pe ) {
                    handlePersistenceException( pe );
                    throw pe;
                  }
                  catch ( RuntimeException re ) {
                    PersistenceException wrapped = new PersistenceException( re );
                    handlePersistenceException( wrapped );
                    throw wrapped;
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = (JoinableCMTTransaction) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = (TransactionFactory.Context) session;
                    JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null )
                      log.warn( "Transaction not available on beforeCompletionPhase: assuming valid" );
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                        //transaction == null workaround a JBoss TMBug
                  }
                  catch (SystemException se) {
                    log.error( "could not determine transaction status", se );
                    //throwPersistenceException will mark the transaction as rollbacked
                    throwPersistenceException(
                        new PersistenceException(
                            "could not determine transaction status in beforeCompletion()",
                            se
                        )
                    );
                  }
                  catch (HibernateException he) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch (RuntimeException re) {
                    //throwPersistenceException will mark the transaction as rollbacked
                    if ( re instanceof HibernateException ) {
                      throwPersistenceException( (HibernateException) re );
                    }
                    else {
                      throwPersistenceException( new PersistenceException( re ) );
                    }
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch (HibernateException e) {
                    throwPersistenceException( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = ( JoinableCMTTransaction ) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          CallbackCoordinator callbackCoordinator = ( (SessionImplementor ) getSession() ).getJDBCContext().getJtaSynchronizationCallbackCoordinator();
          if ( callbackCoordinator == null ) {
            throw new AssertionFailure( "Expecting CallbackCoordinator to be non-null" );
          }
          callbackCoordinator.setBeforeCompletionManagedFlushChecker(
              new BeforeCompletionManagedFlushChecker() {
                public boolean shouldDoManagedFlush(TransactionFactory.Context ctx, javax.transaction.Transaction jtaTransaction)
                    throws SystemException {
                  if ( transaction == null ) {
                    log.warn( "Transaction not available on beforeCompletion: assuming valid" );
                  }
                  return !ctx.isFlushModeNever()
                      && ( jtaTransaction == null || !JTAHelper.isRollback( jtaTransaction.getStatus() ) );
                }
              }
          );
          callbackCoordinator.setAfterCompletionAction(
              new AfterCompletionAction() {
                public void doAction(TransactionFactory.Context ctx, int status) {
                  try {
                    if ( !ctx.isClosed() ) {
                      if ( Status.STATUS_ROLLEDBACK == status
                          && transactionType == PersistenceUnitTransactionType.JTA ) {
                        session.clear();
                      }
                      JoinableCMTTransaction joinable = ( JoinableCMTTransaction ) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch ( HibernateException e ) {
                    throw convert( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = (JoinableCMTTransaction) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = (TransactionFactory.Context) session;
                    JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null )
                      log.warn( "Transaction not available on beforeCompletionPhase: assuming valid" );
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                        //transaction == null workaround a JBoss TMBug
                  }
                  catch (SystemException se) {
                    log.error( "could not determine transaction status", se );
                    //throwPersistenceException will mark the transaction as rollbacked
                    throwPersistenceException(
                        new PersistenceException(
                            "could not determine transaction status in beforeCompletion()",
                            se
                        )
                    );
                  }
                  catch (HibernateException he) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch (RuntimeException re) {
                    //throwPersistenceException will mark the transaction as rollbacked
                    if ( re instanceof HibernateException ) {
                      throwPersistenceException( (HibernateException) re );
                    }
                    else {
                      throwPersistenceException( new PersistenceException( re ) );
                    }
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch (HibernateException e) {
                    throwPersistenceException( e );
                  }
View Full Code Here

        log.debug( "Looking for a JTA transaction to join" );
        final Session session = getSession();
        final Transaction transaction = session.getTransaction();
        if ( transaction != null && transaction instanceof JoinableCMTTransaction ) {
          //can't handle it if not a joinnable transaction
          final JoinableCMTTransaction joinableCMTTransaction = (JoinableCMTTransaction) transaction;

          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.JOINED ) {
            log.debug( "Transaction already joined" );
            return; //no-op
          }
          joinableCMTTransaction.markForJoined();
          session.isOpen(); //register to the Tx
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.NOT_JOINED ) {
            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else
          if ( joinableCMTTransaction.getStatus() == JoinableCMTTransaction.JoinStatus.MARKED_FOR_JOINED ) {
            throw new AssertionFailure( "Transaction MARKED_FOR_JOINED after isOpen() call" );
          }
          //flush before completion and
          //register clear on rollback
          log.trace( "Adding flush() and close() synchronization" );
          joinableCMTTransaction.registerSynchronization(
              new Synchronization() {
                public void beforeCompletion() {
                  boolean flush = false;
                  TransactionFactory.Context ctx = null;
                  try {
                    ctx = (TransactionFactory.Context) session;
                    JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                    javax.transaction.Transaction transaction = joinable.getTransaction();
                    if ( transaction == null )
                      log.warn( "Transaction not available on beforeCompletionPhase: assuming valid" );
                    flush = !ctx.isFlushModeNever() &&
                        //ctx.isFlushBeforeCompletionEnabled() &&
                        //TODO probably make it ! isFlushBeforecompletion()
                        ( transaction == null || !JTAHelper.isRollback( transaction.getStatus() ) );
                        //transaction == null workaround a JBoss TMBug
                  }
                  catch (SystemException se) {
                    log.error( "could not determine transaction status", se );
                    //throwPersistenceException will mark the transaction as rollbacked
                    throwPersistenceException(
                        new PersistenceException(
                            "could not determine transaction status in beforeCompletion()",
                            se
                        )
                    );
                  }
                  catch (HibernateException he) {
                    throwPersistenceException( he );
                  }

                  try {
                    if ( flush ) {
                      log.trace( "automatically flushing session" );
                      ctx.managedFlush();
                    }
                    else {
                      log.trace( "skipping managed flushing" );
                    }
                  }
                  catch (RuntimeException re) {
                    //throwPersistenceException will mark the transaction as rollbacked
                    if ( re instanceof HibernateException ) {
                      throwPersistenceException( (HibernateException) re );
                    }
                    else {
                      throwPersistenceException( new PersistenceException( re ) );
                    }
                  }
                }

                public void afterCompletion(int status) {
                  try {
                    if ( Status.STATUS_ROLLEDBACK == status
                        && transactionType == PersistenceUnitTransactionType.JTA ) {
                      if ( session.isOpen() ) {
                        session.clear();
                      }
                    }
                    if ( session.isOpen() ) {
                      //only reset if the session is opened since you can't get the Transaction otherwise
                      JoinableCMTTransaction joinable = (JoinableCMTTransaction) session.getTransaction();
                      joinable.resetStatus();
                    }
                  }
                  catch (HibernateException e) {
                    throwPersistenceException( e );
                  }
View Full Code Here

TOP

Related Classes of org.hibernate.ejb.transaction.JoinableCMTTransaction

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.