Package javax.persistence

Examples of javax.persistence.RollbackException


  @Test
  public void testTransactionCommitWithRollbackException() {
    given(manager.getTransaction()).willReturn(tx);
    given(tx.getRollbackOnly()).willReturn(true);
    willThrow(new RollbackException()).given(tx).commit();

    final List<String> l = new ArrayList<String>();
    l.add("test");

    assertTrue(!TransactionSynchronizationManager.hasResource(factory));
View Full Code Here


  @Test
  public void testParticipatingTransactionWithRollbackOnly() {
    given(manager.getTransaction()).willReturn(tx);
    given(tx.isActive()).willReturn(true);
    given(tx.getRollbackOnly()).willReturn(true);
    willThrow(new RollbackException()).given(tx).commit();

    final List<String> l = new ArrayList<String>();
    l.add("test");

    assertTrue(!TransactionSynchronizationManager.hasResource(factory));
View Full Code Here

    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 HibernateException) {
        wrappedException = entityManager.convert( (HibernateException)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 committing the transaction", wrappedException );
    }
    finally {
      rollbackOnly = false;
    }
    //if closed and we commit, the mode should have been adjusted already
View Full Code Here

    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

                        // all change sets and are cleared, but the cache is
                        // kept
                        this.wrapper.localUOW.clearForClose(false);
                    }
                } else {
                    throw new RollbackException(ExceptionLocalization.buildMessage("rollback_because_of_rollback_only"));
                }
            }
        } catch (RuntimeException exception) {
            try {
                if (this.wrapper.localUOW != null) {
                    this.wrapper.getEntityManager().removeExtendedPersistenceContext();
                    this.wrapper.localUOW.release();
                    this.wrapper.localUOW.getParent().release();
                }
            } catch (Exception ignore) {} // Throw first exception.
            if (exception instanceof RollbackException) {
                throw exception;
            } else if (exception instanceof org.eclipse.persistence.exceptions.OptimisticLockException) {
                throw new RollbackException(new javax.persistence.OptimisticLockException(exception));
            } else {
                throw new RollbackException(exception);
            }
        } finally {
            this.active = false;
            this.rollbackOnly = false;
            this.wrapper.setLocalUnitOfWork(null);
View Full Code Here

                  this.wrapper.localUOW.commit();
                  // all change sets and are cleared, but the cache is kept
                  this.wrapper.localUOW.clearForClose(false);
                }
            } else {
                throw new RollbackException(ExceptionLocalization.buildMessage("rollback_because_of_rollback_only"));
            }
        }
    }catch (RuntimeException ex){
        if (this.wrapper.localUOW != null){
            wrapper.getEntityManager().removeExtendedPersistenceContext();
            this.wrapper.localUOW.release();
            this.wrapper.localUOW.getParent().release();
        }
        if(! this.rollbackOnly) {
            throw new RollbackException(ex);
        } else {
            // it's a RollbackException
            throw ex;
        }
    } finally {
View Full Code Here

                        // all change sets and are cleared, but the cache is
                        // kept
                        this.wrapper.localUOW.clearForClose(false);
                    }
                } else {
                    throw new RollbackException(ExceptionLocalization.buildMessage("rollback_because_of_rollback_only"));
                }
            }
        } catch (RuntimeException ex) {
            if (this.wrapper.localUOW != null) {
                this.wrapper.getEntityManager().removeExtendedPersistenceContext();
                this.wrapper.localUOW.release();
                this.wrapper.localUOW.getParent().release();
            }
            if (!this.rollbackOnly) {
                throw new RollbackException(ex);
            } else {
                // it's a RollbackException
                throw ex;
            }
        } finally {
View Full Code Here

                        // all change sets and are cleared, but the cache is
                        // kept
                        this.wrapper.localUOW.clearForClose(false);
                    }
                } else {
                    throw new RollbackException(ExceptionLocalization.buildMessage("rollback_because_of_rollback_only"));
                }
            }
        } catch (RuntimeException exception) {
            try {
                if (this.wrapper.localUOW != null) {
                    this.wrapper.getEntityManager().removeExtendedPersistenceContext();
                    this.wrapper.localUOW.release();
                    this.wrapper.localUOW.getParent().release();
                }
            } catch (Exception ignore) {} // Throw first exception.
            if (exception instanceof RollbackException) {
                throw exception;
            } else if (exception instanceof org.eclipse.persistence.exceptions.OptimisticLockException) {
                throw new RollbackException(new javax.persistence.OptimisticLockException(exception));
            } else {
                throw new RollbackException(exception);
            }
        } finally {
            this.active = false;
            this.rollbackOnly = false;
            this.wrapper.setLocalUnitOfWork(null);
View Full Code Here

   */
  public void commit() {
    assertActive();

    if (getRollbackOnly()) {
      throw new RollbackException("Transaction cannot be committed, it is marked as rollback only.");
    }

    try {
      mDataSource.commit();
      mIsActive = false;
    }
    catch (DataSourceException e) {
      throw new RollbackException(e);
    }
  }
View Full Code Here

    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 HibernateException) {
        wrappedException = entityManager.convert( (HibernateException)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 committing the transaction", wrappedException );
    }
    finally {
      rollbackOnly = false;
    }
    //if closed and we commit, the mode should have been adjusted already
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.