本文整理了Java中javax.persistence.EntityManager.lock()
方法的一些代码示例,展示了EntityManager.lock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.lock()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:lock
[英]Lock an entity instance that is contained in the persistence context with the specified lock mode type.
If a pessimistic lock mode type is specified and the entity contains a version attribute, the persistence provider must also perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database locking failure causes transaction-level rollbackLockTimeoutException
will be thrown if the database locking failure causes only statement-level rollbackOptimisticLockException
。PessimisticLockException
LockTimeoutException
代码示例来源:origin: rapidoid/rapidoid
@Override
public void lock(Object entity, LockModeType lockMode) {
em.lock(entity, lockMode);
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) {
em.lock(entity, lockMode, properties);
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties) {
em().lock(entity, lockMode, properties);
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public void lock(Object entity, LockModeType lockMode) {
em().lock(entity, lockMode);
}
代码示例来源:origin: Impetus/Kundera
em.lock(null, LockModeType.NONE, null);
Assert.fail("Should have gone to catch block!");
代码示例来源:origin: org.evolvis.bsi/kolab-ws
@Override
public void
lock(Object entity, LockModeType lockMode)
{
delegate.lock(entity, lockMode);
}
代码示例来源:origin: aerogear/aerogear-unifiedpush-server
/**
* Pessimistic write lock on entity
*/
@Override
public void lock(T entity) {
entityManager.lock(entity, LockModeType.PESSIMISTIC_WRITE);
}
代码示例来源:origin: BottegaIT/ddd-leaven-v2
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);
}
}
代码示例来源:origin: org.apache.deltaspike.modules/deltaspike-data-module-impl
@Override
public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties)
{
entityManager().lock(entity, lockMode, properties);
}
代码示例来源:origin: org.jboss.seam/jboss-seam
protected void lock(Object entity, LockModeType lockMode)
{
getEntityManager().lock(entity, lockMode);
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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)
);
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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))
);
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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
));
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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
));
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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
));
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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
));
});
}
代码示例来源:origin: org.apache.openejb/openejb-core
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();
}
}
代码示例来源:origin: org.apache.openejb/openejb-core
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();
}
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@Test
public void testPessimisticWriteAfterFetch() {
doInJPA(entityManager -> {
Post post = entityManager.find(Post.class, 1L);
entityManager.lock(post, LockModeType.PESSIMISTIC_WRITE);
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@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());
}
}
内容来源于网络,如有侵权,请联系作者删除!