List of usage examples for javax.persistence LockModeType WRITE
LockModeType WRITE
To view the source code for javax.persistence LockModeType WRITE.
Click Source Link
OPTIMISTIC_FORCE_INCREMENT
. From source file:org.apache.camel.bam.processor.ActivityMonitorEngine.java
@SuppressWarnings("unchecked") protected void fireExpiredEvent(final ActivityState activityState) { if (LOG.isDebugEnabled()) { LOG.debug("Trying to fire expiration of: " + activityState); }//from www . j av a2 s . c om template.execute(new JpaCallback() { public Object doInJpa(EntityManager entityManager) throws PersistenceException { // lets try lock the object first if (isUseLocking()) { LOG.info("Attempting to lock: " + activityState); entityManager.lock(activityState, LockModeType.WRITE); LOG.info("Grabbed lock: " + activityState); } try { rules.processExpired(activityState); } catch (Exception e) { LOG.error("Failed to process expiration of: " + activityState + ". Reason: " + e, e); } activityState.setTimeOverdue(null); //activityState.setEscalationLevel(escalateLevel + 1); return null; } }); }
From source file:org.apache.camel.component.jpa.JpaConsumer.java
/** * A strategy method to lock an object with an exclusive lock so that it can * be processed//w w w .j a v a 2 s. com * * @param entity the entity to be locked * @param entityManager entity manager * @return true if the entity was locked */ protected boolean lockEntity(Object entity, EntityManager entityManager) { if (!getEndpoint().isConsumeDelete() || !getEndpoint().isConsumeLockEntity()) { return true; } try { if (LOG.isDebugEnabled()) { LOG.debug("Acquiring exclusive lock on entity: " + entity); } entityManager.lock(entity, LockModeType.WRITE); return true; } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Failed to achieve lock on entity: " + entity + ". Reason: " + e, e); } return false; } }