Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


          sequence.setRecUpdateDatetime(new Date());
          sequence.setSite(site);
          em.persist(sequence);
        }
        else {
          em.lock(sequence, LockModeType.WRITE);
        }
      }
      Long sequenceNum = sequence.getNextSequenceNum();
      sequenceNum = Long.valueOf(sequenceNum.longValue() + 1);
      sequence.setNextSequenceNum(sequenceNum);
View Full Code Here


                    }
                    employee = employees.get(id);
                    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:
View Full Code Here

                    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

        final Object entity2 = em2.find(entityClass, oid);
        final long timeout = 1000;
        try {
            Map<String,Object> hint = new HashMap<String, Object>();
            hint.put("javax.persistence.lock.timeout", timeout);
            em2.lock(entity2, LockModeType.PESSIMISTIC_WRITE, hint);
            fail("Expected " + PessimisticLockException.class.getName());
        } catch (Throwable t) {
           assertError(t, PessimisticLockException.class);
           assertTrue(em2.getTransaction().isActive());
        } finally {
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.persist( lock );
    em.getTransaction().commit();

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

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

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.