コード例 #1
0
  /**
   * Commit the current transaction, writing any unflushed changes to the database.
   *
   * @throws IllegalStateException if isActive() is false.
   * @throws RollbackException if the commit fails.
   */
  public void commit() {
    assertActive();

    if (tx.getRollbackOnly()) {
      // This is thrown by the underlying transaction but we want to have a RollbackException here
      // so intercept it
      if (NucleusLogger.TRANSACTION.isDebugEnabled()) {
        NucleusLogger.TRANSACTION.debug(Localiser.msg("015020"));
      }
      throw new RollbackException(Localiser.msg("015020"));
    }

    try {
      tx.commit();
    } catch (NucleusTransactionException nte) {
      Throwable cause = nte.getCause();
      Throwable pe = null;
      if (cause instanceof NucleusException) {
        pe = NucleusJPAHelper.getJPAExceptionForNucleusException((NucleusException) cause);
      } else {
        pe = cause;
      }
      throw new RollbackException(Localiser.msg("015007"), pe);
    } catch (NucleusException ne) {
      throw NucleusJPAHelper.getJPAExceptionForNucleusException(ne);
    }
  }
コード例 #2
0
 /**
  * Start a resource transaction.
  *
  * @throws IllegalStateException if the transaction is active
  */
 public void begin() {
   assertNotActive();
   try {
     tx.begin();
   } catch (NucleusException ne) {
     throw NucleusJPAHelper.getJPAExceptionForNucleusException(ne);
   }
 }
コード例 #3
0
  /**
   * Roll back the current transaction.
   *
   * @throws IllegalStateException if isActive() is false.
   * @throws PersistenceException if an unexpected error condition is encountered.
   */
  public void rollback() {
    assertActive();

    try {
      tx.rollback();
    } catch (NucleusException ne) {
      throw NucleusJPAHelper.getJPAExceptionForNucleusException(ne);
    }
  }