Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


  public void lock(Object entity, LockModeType lockMode)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      em.lock(entity, lockMode);
      return;
    }
   
    em = createEntityManager();
   
View Full Code Here


    }
   
    em = createEntityManager();
   
    try {
      em.lock(entity, lockMode);
    } finally {
      freeEntityManager(em);
    }
  }
View Full Code Here

                   Map<String, Object> properties)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      em.lock(entity, lockMode, properties);
      return;
    }
   
    em = createEntityManager();
   
View Full Code Here

    }
   
    em = createEntityManager();
   
    try {
      em.lock(entity, lockMode, properties);
    } finally {
      freeEntityManager(em);
    }
  }
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

    }
    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

    em.persist( lock );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    em.lock( lock, LockModeType.READ );
    lock.setName( "surname" );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.find( Lock.class, lock.getId() );
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.WRITE );
    em.getTransaction().commit();

    em.getTransaction().begin();
    lock = em.getReference( Lock.class, lock.getId() );
    try {
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

     customerInfo = new CustomerInfo(customer);
     */
        EntityManager em = entityManagerFactory.createEntityManager();
        em.getTransaction().begin();
    Customer c = em.find(Customer.class, customerID);
    em.lock(c, LockModeType.WRITE);
    em.refresh(c);
    // TODO: lowp: test and set for update performance?
    c.setFirstName(firstName);
    c.setLastName(lastName);
    c.setAddr1(addr1);
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.