Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


                    log.trace("Employee=" + employee);
                    Map<String, Object> lockProps = buildPropsMap(args, 3);
                    if (lockProps != null) {
                        em.lock(employee, lockMode, lockProps);
                    } else {
                        em.lock(employee, lockMode);
                    }
                    break;
                case LockObject:
                    em.lock(args[1], (LockModeType) args[2]);
                    break;
View Full Code Here


                    } else {
                        em.lock(employee, lockMode);
                    }
                    break;
                case LockObject:
                    em.lock(args[1], (LockModeType) args[2]);
                    break;
                case UpdateEmployee:
                    id = 1;
                    if (args.length > 1) {
                        id = (Integer) args[1];
View Full Code Here

                case Trace:
                    log.trace(args[1]);
                    break;

                case Test:
                    em.lock("xxx", LockModeType.WRITE);
                    break;
                default:
                }
            } catch (Exception ex) {
                // only remember the first exception caught
View Full Code Here

        em.getTransaction().begin();
        OptimisticLockInstance oli = (OptimisticLockInstance) em.createQuery(
            "SELECT o FROM OptimisticLockInstance o WHERE o.str = 'foo'")
            .getSingleResult();
        assertNotNull(oli);
        em.lock(oli, LockModeType.READ);

        EntityManager em2 = emf.createEntityManager();
        em2.getTransaction().begin();
        em2.createQuery("UPDATE OptimisticLockInstance o SET o.str = 'foo', "
            + "o.intField = o.intField + 1"
View Full Code Here

        OptimisticLockInstance oli = em.find(OptimisticLockInstance.class, pk);
        Object oid = JPAFacadeHelper.toOpenJPAObjectId(
            JPAFacadeHelper.getMetaData(oli),
            OpenJPAPersistence.cast(em).getObjectId(oli));
        int firstOpLockValue = oli.getOpLock();
        em.lock(oli, LockModeType.READ);

        // 2. make a change to the instance's optimistic lock column
        // via direct SQL in a separate transaction
        int secondOpLockValue = firstOpLockValue + 1;
View Full Code Here

            + "violations occur", secondOpLockValue, oli.getOpLock());

        // 6. get a read lock on the instance and commit the tx; this
        // time it should go through
        em.getTransaction().begin();
        em.lock(oli, LockModeType.READ);
        try {
            em.getTransaction().commit();
        } catch (RollbackException e) {
            throw e;
        } finally {
View Full Code Here

        EntityManager em;
       
        // 1. start a new tx
        em = emf.createEntityManager();
        em.getTransaction().begin();
        em.lock(em.find(OptimisticLockInstance.class, pk), LockModeType.READ);
       
        // 2. start another tx, and cause a version increment
        EntityManager em2 = emf.createEntityManager();
        em2.getTransaction().begin();
        em2.lock(em2.find(OptimisticLockInstance.class, pk),
View Full Code Here

        em.lock(em.find(OptimisticLockInstance.class, pk), LockModeType.READ);
       
        // 2. start another tx, and cause a version increment
        EntityManager em2 = emf.createEntityManager();
        em2.getTransaction().begin();
        em2.lock(em2.find(OptimisticLockInstance.class, pk),
            LockModeType.WRITE);
        em2.getTransaction().commit();
        em2.close();
       
        // 3. try to commit. this should fail, as this is a regular optimistic
View Full Code Here

    }
    catch (TransactionRequiredException e) {
      //success
    }
    try {
      em.lock( book, LockModeType.READ );
      fail( "lock has to be inside a Tx" );
    }
    catch (TransactionRequiredException e) {
      //success
    }
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.