Package javax.persistence

Examples of javax.persistence.OptimisticLockException


            verifyOpen();
            try {
                try {
                getActivePersistenceContext(checkForTransaction(true)).writeChanges();
                } catch (org.eclipse.persistence.exceptions.OptimisticLockException eclipselinkOLE) {
                    throw new OptimisticLockException(eclipselinkOLE);
                }
            } catch (RuntimeException e) {
                if (EclipseLinkException.class.isAssignableFrom(e.getClass())) {
                    throw new PersistenceException(e);
                }
View Full Code Here


      Serializable identifier = sose.getIdentifier();
      if (identifier != null) {
        Object entity = session.load( sose.getEntityName(), identifier );
        if ( entity instanceof Serializable ) {
          //avoid some user errors regarding boundary crossing
          pe = new OptimisticLockException( null, e, entity );
        }
        else {
          pe = new OptimisticLockException( e );
        }
      }
      else {
        pe = new OptimisticLockException( e );
      }
    }
    else {
      pe = new OptimisticLockException( e );
    }
    return pe;
  }
View Full Code Here

      else {
        return new PessimisticLockException( ple.getMessage(), ple );
      }
    }
    else {
      return new OptimisticLockException( e.getMessage(), e );
    }
  }
View Full Code Here

      Serializable identifier = sose.getIdentifier();
      if ( identifier != null ) {
        Object entity = session.load( sose.getEntityName(), identifier );
        if ( entity instanceof Serializable ) {
          //avoid some user errors regarding boundary crossing
          return new OptimisticLockException( null, e, entity );
        }
        else {
          return new OptimisticLockException( e );
        }
      }
      else {
        return new OptimisticLockException( e );
      }
    }
    else {
      return new OptimisticLockException( e );
    }
  }
View Full Code Here

  @Test
  public void testApplicationManagedEntityManagerWithTransactionAndCommitException() throws Exception {
    Object testEntity = new Object();

    EntityTransaction mockTx = mock(EntityTransaction.class);
    willThrow(new OptimisticLockException()).given(mockTx).commit();

    // This one's for the tx (shared)
    EntityManager sharedEm = mock(EntityManager.class);
    given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
View Full Code Here

    NonUniqueResultException nonUniqueResult = new NonUniqueResultException();
    assertSame(IncorrectResultSizeDataAccessException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass());

    OptimisticLockException optimisticLock = new OptimisticLockException();
    assertSame(JpaOptimisticLockingFailureException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass());

    EntityExistsException entityExists = new EntityExistsException("foo");
    assertSame(DataIntegrityViolationException.class,
View Full Code Here

    dialect.beginTransaction(entityManager, definition);
  }

  @Test
  public void testTranslateException() {
    OptimisticLockException ex = new OptimisticLockException();
    assertEquals(
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex).getCause(),
        dialect.translateExceptionIfPossible(ex).getCause());
  }
View Full Code Here

      if ( identifier != null ) {
        try {
          Object entity = getRawSession().load( sose.getEntityName(), identifier );
          if ( entity instanceof Serializable ) {
            //avoid some user errors regarding boundary crossing
            pe = new OptimisticLockException( null, e, entity );
          }
          else {
            pe = new OptimisticLockException( e );
          }
        }
        catch ( EntityNotFoundException enfe ) {
          pe = new OptimisticLockException( e );
        }
      }
      else {
        pe = new OptimisticLockException( e );
      }
    }
    else {
      pe = new OptimisticLockException( e );
    }
    return pe;
  }
View Full Code Here

  public PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions) {
    PersistenceException pe;
    if ( e instanceof org.hibernate.OptimisticLockException ) {
      org.hibernate.OptimisticLockException ole = ( org.hibernate.OptimisticLockException ) e;
      pe = new OptimisticLockException( ole.getMessage(), ole, ole.getEntity() );
    }
    else if ( e instanceof org.hibernate.PessimisticLockException ) {
      org.hibernate.PessimisticLockException ple = ( org.hibernate.PessimisticLockException ) e;
      if ( lockOptions != null && lockOptions.getTimeOut() > -1 ) {
        // assume lock timeout occurred if a timeout or NO WAIT was specified
        pe = new LockTimeoutException( ple.getMessage(), ple, ple.getEntity() );
      }
      else {
        pe = new PessimisticLockException( ple.getMessage(), ple, ple.getEntity() );
      }
    }
    else {
      pe = new OptimisticLockException( e );
    }
    return pe;
  }
View Full Code Here

      Serializable identifier = sose.getIdentifier();
      if ( identifier != null ) {
        Object entity = session.load( sose.getEntityName(), identifier );
        if ( entity instanceof Serializable ) {
          //avoid some user errors regarding boundary crossing
          pe = new OptimisticLockException( null, e, entity );
        }
        else {
          pe = new OptimisticLockException( e );
        }
      }
      else {
        pe = new OptimisticLockException( e );
      }
    }
    else {
      pe = new OptimisticLockException( e );
    }
    return pe;
  }
View Full Code Here

TOP

Related Classes of javax.persistence.OptimisticLockException

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.