Package javax.persistence

Examples of javax.persistence.EntityManager.lock()


                    }
                    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

        EntityManager em = emf.createEntityManager();
       
        em.getTransaction().begin();
        LockEmployeeNonVersion emp = em.find(LockEmployeeNonVersion.class, 1);
        assertNotNull(emp);
        em.lock(emp, lockMode);
        String lastLastName = emp.getLastName();
        em.getTransaction().commit();
       
        em.clear();
       
View Full Code Here

        emp = em.find(LockEmployeeNonVersion.class, 1);
        assertNotNull(emp);
        assertEquals(lastLastName, emp.getLastName());
       
        emp = em.find(LockEmployeeNonVersion.class, 2);
        em.lock(emp, lockMode);
        emp.setLastName(lockMode.toString());
        em.getTransaction().commit();
       
        emp = em.find(LockEmployeeNonVersion.class, 2);
        assertNotNull(emp);
View Full Code Here

    }

    public void lock(Object o, LockModeType lockModeType) {
        EntityManager entityManager = getEntityManager(false);
        if (entityManager != null) {
             entityManager.lock(o, lockModeType);
        } else {
            entityManager = createEntityManager();
            try {
                 entityManager.lock(o, lockModeType);
            } finally {
View Full Code Here

        if (entityManager != null) {
             entityManager.lock(o, lockModeType);
        } else {
            entityManager = createEntityManager();
            try {
                 entityManager.lock(o, lockModeType);
            } finally {
                entityManager.close();
            }
        }
    }
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());
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.