/**
* Acquire the lock object.
*
* @param em the em
* @param lock the lock
* @return true, if successful
*/
private boolean acquire(final EntityManager em, final Lock lock) {
lock.setUniqueId(uniqueId);
if (lockTimeout > 0) {
final Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, lockTimeout);
lock.setExpirationDate(cal.getTime());
} else {
lock.setExpirationDate(null);
}
boolean success = false;
try {
if (lock.getApplicationId() != null) {
em.merge(lock);
} else {
lock.setApplicationId(applicationId);
em.persist(lock);
}
success = true;
} catch (final PersistenceException e) {
success = false;
if (logger.isDebugEnabled()) {
logger.debug("{} could not obtain {} lock.", uniqueId, applicationId, e);
} else {
logger.info("{} could not obtain {} lock.", uniqueId, applicationId);
}
}
return success;
}
JpaLockingStrategy.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:springboot-shiro-cas-mybatis
作者:
评论列表
文章目录