Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


    lock = em.getReference( UnversionedLock.class, lock.getId() );
    try {
      // getting a READ (optimistic) lock on unversioned entity is not expected to work.
      // To get the same functionality as prior release, change the  LockModeType.READ lock to:
      // em.lock(lock,LockModeType.PESSIMISTIC_READ);
      em.lock( lock, LockModeType.READ );
      fail("expected OptimisticLockException exception");
    } catch(OptimisticLockException expected) {}
    em.getTransaction().rollback();

    // the previous code block can be rewritten as follows (to get the previous behavior)
View Full Code Here


    em.getTransaction().rollback();

    // the previous code block can be rewritten as follows (to get the previous behavior)
    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.lock( lock, LockModeType.PESSIMISTIC_READ );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( UnversionedLock.class, lock.getId() );
    em.remove( lock );
View Full Code Here

    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    Integer version = lock.getVersion();
    em.lock( lock, LockModeType.PESSIMISTIC_FORCE_INCREMENT );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    try {
View Full Code Here

    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    Integer version = lock.getVersion();
    em.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    try {
View Full Code Here

     EntityManager em2 = createIsolatedEntityManager();
     em2.getTransaction().begin();
     lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC );
     assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) );
     em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT );
     assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) );
     em2.getTransaction().commit();
     em2.getTransaction().begin();
     em2.remove( lock );
     em2.getTransaction().commit();
View Full Code Here

            log.info("testContendedPessimisticReadLockTimeout: (BG) read write-locked entity");
            Map<String,Object> props = new HashMap<String, Object>();
            // timeout is in milliseconds
            props.put("javax.persistence.lock.timeout", new Integer(1000));
            try {
              em2.lock( lock2, LockModeType.PESSIMISTIC_READ, props);
            }
            catch( LockTimeoutException e) {
              // success
              log.info("testContendedPessimisticReadLockTimeout: (BG) got expected timeout exception");
               timedOut = true;
View Full Code Here

            log.info("testContendedPessimisticWriteLockTimeout: (BG) read write-locked entity");
            Map<String,Object> props = new HashMap<String, Object>();
            // timeout is in milliseconds
            props.put("javax.persistence.lock.timeout", new Integer(1000));
            try {
              em2.lock( lock2, LockModeType.PESSIMISTIC_WRITE, props);
            }
            catch( LockTimeoutException e) {
              // success
              log.info("testContendedPessimisticWriteLockTimeout: (BG) got expected timeout exception");
               timedOut = true;
View Full Code Here

            log.info("testContendedPessimisticWriteLockNoWait: (BG) read write-locked entity");
            Map<String,Object> props = new HashMap<String, Object>();
            // timeout of zero means no wait (for lock)
            props.put("javax.persistence.lock.timeout", new Integer(0));
            try {
              em2.lock( lock2, LockModeType.PESSIMISTIC_WRITE, props);
            }
            catch( LockTimeoutException e) {
              // success
              log.info("testContendedPessimisticWriteLockNoWait: (BG) got expected timeout exception");
               timedOut = true;
View Full Code Here

            Lock lock2 = em2.getReference( Lock.class, id );
            lock2.getName();    //  force entity to be read
            log.info("testLockTimeoutEMProps: (BG) read write-locked entity");
            // em2 already has javax.persistence.lock.timeout of 1 second applied
            try {
              em2.lock( lock2, LockModeType.PESSIMISTIC_WRITE);
            }
            catch( LockTimeoutException e) {
              // success
              log.info("testLockTimeoutEMProps: (BG) got expected timeout exception");
               timedOut = true;
View Full Code Here

    try {
      tx.begin();
      org.apache.juddi.model.Subscription modelSubscription = em.find(org.apache.juddi.model.Subscription.class, resultList.getSubscription().getSubscriptionKey());
      log.debug("Taking out a write lock on this subscription, and bail if we can't get it since that would mean"
       + " another jUDDI instance is in the process of sending out the notification.");
      em.lock(modelSubscription, LockModeType.WRITE);
      Date startPoint = resultList.getCoveragePeriod().getStartPoint().toGregorianCalendar().getTime();
      Date endPoint   = resultList.getCoveragePeriod().getEndPoint().toGregorianCalendar().getTime();
      if (modelSubscription.getLastNotified()!=null
          && startPoint.before(modelSubscription.getLastNotified())
          && endPoint.after(modelSubscription.getLastNotified())) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.