Package javax.persistence

Examples of javax.persistence.RollbackException


    if ( tx == null || !tx.isActive() ) {
      throw new IllegalStateException( "Transaction not active" );
    }
    if ( rollbackOnly ) {
      tx.rollback();
      throw new RollbackException( "Transaction marked as rollbackOnly" );
    }
    try {
      tx.commit();
    }
    catch (Exception e) {
      Exception wrappedException;
      if (e instanceof StaleStateException) {
        wrappedException = entityManager.wrapStaleStateException( (StaleStateException) e );
      }
      else {
        wrappedException = e;
      }
      try {
        //as per the spec we should rollback if commit fails
        tx.rollback();
      }
      catch (Exception re) {
        //swallow
      }
      throw new RollbackException( "Error while commiting the transaction", wrappedException );
    }
    finally {
      rollbackOnly = false;
    }
    //if closed and we commit, the mode should have been adjusted already
View Full Code Here


  public void testTransactionCommitWithRollbackException() {
    managerControl.expectAndReturn(manager.getTransaction(), tx);
    txControl.expectAndReturn(tx.getRollbackOnly(), true);
    managerControl.expectAndReturn(manager.getTransaction(), tx);
    tx.commit();
    txControl.setThrowable(new RollbackException());
    manager.flush();

    factoryControl.replay();
    managerControl.replay();
    txControl.replay();
View Full Code Here

          txControl.reset();
          txControl.expectAndReturn(tx.isActive(), true);
          tx.setRollbackOnly();
          txControl.expectAndReturn(tx.getRollbackOnly(), true);
          tx.commit();
          txControl.setThrowable(new RollbackException());
          txControl.replay();

          assertTrue(TransactionSynchronizationManager.hasResource(factory));

          return tt.execute(new TransactionCallback() {
View Full Code Here

            // 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
        {
            ec.getTransaction().commit();
        }
        catch (NucleusTransactionException nte)
        {
            Throwable cause = nte.getCause();
            PersistenceException pe = null;
            if (cause instanceof JDOException)
            {
                // TODO Do we still need this? Where is JDOException thrown? bytecode enhancement?
                pe = NucleusJPAHelper.getJPAExceptionForJDOException((JDOException)cause);
            }
            else
            {
                pe = NucleusJPAHelper.getJPAExceptionForNucleusException((NucleusException)cause);
            }
            throw new RollbackException(LOCALISER.msg("015007"), pe);
        }
        catch (NucleusException ne)
        {
            throw NucleusJPAHelper.getJPAExceptionForNucleusException(ne);
        }
View Full Code Here

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

        try
        {
            om.getTransaction().commit();
        }
        catch (JPOXTransactionException jpte)
        {
            PersistenceException pe = JPOXJPAHelper.getJPAExceptionForJPOXException((JPOXException)jpte.getCause());
            throw new RollbackException(LOCALISER.msg("015007"), pe);
        }
        catch (JPOXException jpe)
        {
            throw JPOXJPAHelper.getJPAExceptionForJPOXException(jpe);
        }
View Full Code Here

    /*
     * Ensure that parameter values are not included in exception text by default.
     */
    public void testNoParamsByDefault() {
        RollbackException e = getRollbackException(PObject.class, CLEAR_TABLES);

        assertFalse(Pattern.matches(_regex, e.toString()));
        Throwable nested = e.getCause();
        while (nested != null) {
            if (Pattern.matches(".*INSERT.*", nested.toString())) {
                // only check if the message contains the insert statement.
                assertFalse(Pattern.matches(_regex, nested.toString()));
            }
View Full Code Here

    /*
     * If the EMF is created with PrintParameters=true the parameter values will be logged in exception text.
     */
    public void testParamsEnabledByConfig() {
        RollbackException e =
            getRollbackException(PObject.class, CLEAR_TABLES, "openjpa.ConnectionFactoryProperties",
                "PrintParameters=true");
        assertFalse(Pattern.matches(_regex, e.toString()));
        Throwable nested = e.getCause();
        assertNotNull(nested); // expecting at least one nested exception.
        while (nested != null) {
            if (Pattern.matches(".*INSERT.*", nested.toString())) {
                // only check if the message contains the insert statement.
                assertTrue(Pattern.matches(_regex, nested.toString()));
View Full Code Here

    /*
     * Ensure that parameter values are not included in exception text by default.
     */
    public void testNoParamsByDefault() {
        RollbackException e = getRollbackException(PObject.class, CLEAR_TABLES);

        assertFalse(Pattern.matches(_regex, e.toString()));
        Throwable nested = e.getCause();
        while (nested != null) {
            if (Pattern.matches(".*INSERT.*", nested.toString())) {
                // only check if the message contains the insert statement.
                assertFalse(Pattern.matches(_regex, nested.toString()));
            }
View Full Code Here

    /*
     * If the EMF is created with PrintParameters=true the parameter values will be logged in exception text.
     */
    public void testParamsEnabledByConfig() {
        RollbackException e =
            getRollbackException(PObject.class, CLEAR_TABLES, "openjpa.ConnectionFactoryProperties",
                "PrintParameters=true");
        assertFalse(Pattern.matches(_regex, e.toString()));
        Throwable nested = e.getCause();
        assertNotNull(nested); // expecting at least one nested exception.
        while (nested != null) {
            if (Pattern.matches(".*INSERT.*", nested.toString())) {
                // only check if the message contains the insert statement.
                assertTrue(Pattern.matches(_regex, nested.toString()));
View Full Code Here

    public void testCreate(final UserTO userTO) {
        SyncopeUser user = new SyncopeUser();
        userDataBinder.create(user, userTO);
        userDAO.save(user);

        throw new RollbackException();
    }
View Full Code Here

TOP

Related Classes of javax.persistence.RollbackException

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.