@Override public void lock(Object entity, LockModeType lockMode) { em.lock(entity, lockMode); }
@Override public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) { em.lock(entity, lockMode, properties); }
@Override public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) { em().lock(entity, lockMode, properties); }
@Override public void lock(Object entity, LockModeType lockMode) { em().lock(entity, lockMode); }
em.lock(null, LockModeType.NONE, null); Assert.fail("Should have gone to catch block!");
@Override public void lock(Object entity, LockModeType lockMode) { delegate.lock(entity, lockMode); }
/** * Pessimistic write lock on entity */ @Override public void lock(T entity) { entityManager.lock(entity, LockModeType.PESSIMISTIC_WRITE); }
public void save(A aggregate) { if (entityManager.contains(aggregate)){ //locking Aggregate Root logically protects whole aggregate entityManager.lock(aggregate, LockModeType.OPTIMISTIC_FORCE_INCREMENT); } else{ entityManager.persist(aggregate); } }
@Override public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) { entityManager().lock(entity, lockMode, properties); }
protected void lock(Object entity, LockModeType lockMode) { getEntityManager().lock(entity, lockMode); }
@Test public void testPessimisticNoWaitJPA() throws InterruptedException { LOGGER.info("Test PESSIMISTIC_READ blocks PESSIMISTIC_WRITE, NO WAIT fails fast"); doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap("javax.persistence.lock.timeout", 0) ); }); }
@Test public void testPessimisticTimeoutJPA() throws InterruptedException { doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap("javax.persistence.lock.timeout", TimeUnit.SECONDS.toMillis(3)) ); }); }
@Test public void testCascadeLockOnManagedEntityWithJPA() throws InterruptedException { LOGGER.info("Test lock cascade for managed entity"); doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap( AvailableSettings.LOCK_SCOPE, PessimisticLockScope.EXTENDED )); }); }
@Test public void testCascadeLockOnManagedEntityWithJPA() throws InterruptedException { LOGGER.info("Test lock cascade for managed entity"); doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap( AvailableSettings.LOCK_SCOPE, PessimisticLockScope.EXTENDED )); }); }
@Test public void testCascadeLockOnManagedEntityWithAssociationsUninitializedAndJpa() throws InterruptedException { LOGGER.info("Test lock cascade for managed entity"); doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap( AvailableSettings.LOCK_SCOPE, PessimisticLockScope.EXTENDED )); }); }
@Test public void testCascadeLockOnManagedEntityWithJPA() throws InterruptedException { LOGGER.info("Test lock cascade for managed entity"); doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE, Collections.singletonMap( AvailableSettings.LOCK_SCOPE, PessimisticLockScope.EXTENDED )); }); }
public void lock(final Object entity, final LockModeType lockMode) { assertTransactionActive(); final Timer timer = Op.lock.start(this); try { getEntityManager().lock(entity, lockMode); } finally { timer.stop(); } }
public void lock(final Object entity, final LockModeType lockMode, final Map<String, Object> properties) { assertTransactionActive(); final Timer timer = Op.lock.start(this); try { getEntityManager().lock(entity, lockMode, properties); } finally { timer.stop(); } }
@Test public void testPessimisticWriteAfterFetch() { doInJPA(entityManager -> { Post post = entityManager.find(Post.class, 1L); entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE); }); }
@Test public void testPessimisticWriteAfterFetchWithDetachedForJPA() { Post post = doInJPA(entityManager -> { return entityManager.find(Post.class, 1L); }); try { doInJPA(entityManager -> { entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE); }); } catch (IllegalArgumentException e) { assertEquals("entity not in the persistence context", e.getMessage()); } }