use of javax.persistence.OptimisticLockException in project nhin-d by DirectProject.
the class AggregationDAOImpl_addUpdateAggregationTest method testAddUpdateAggregationTest_optomisticLockException_assertAggregationVersionException.
@Test
public void testAddUpdateAggregationTest_optomisticLockException_assertAggregationVersionException() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new OptimisticLockException()).when(mgr).persist(any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
boolean exceptionOccured = false;
try {
final Aggregation insert = new Aggregation();
insert.setExchangeBlob(new byte[] { 0, 3, 2 });
insert.setId("12345");
insert.setVersion(0);
dao.addUpdateAggregation(insert);
} catch (AggregationVersionException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of javax.persistence.OptimisticLockException in project uPortal by Jasig.
the class JpaClusterLockDao method updateLock.
@Override
public void updateLock(final String mutexName) {
this.executeIgnoreRollback(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final EntityManager entityManager = getEntityManager();
final ClusterMutex clusterMutex = getClusterMutex(mutexName);
validateLockedMutex(clusterMutex);
clusterMutex.updateLock();
entityManager.persist(clusterMutex);
try {
entityManager.flush();
logger.trace("Updated {}", clusterMutex);
} catch (OptimisticLockException e) {
final IllegalMonitorStateException imse = new IllegalMonitorStateException("Failed to update " + mutexName + " due to another thread/server updating the mutex");
imse.initCause(e);
throw imse;
}
}
});
}
use of javax.persistence.OptimisticLockException in project uPortal by Jasig.
the class JpaClusterLockDao method releaseLock.
@Override
public void releaseLock(final String mutexName) {
this.executeIgnoreRollback(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final EntityManager entityManager = getEntityManager();
final ClusterMutex clusterMutex = getClusterMutex(mutexName);
validateLockedMutex(clusterMutex);
clusterMutex.unlock();
entityManager.persist(clusterMutex);
try {
entityManager.flush();
logger.trace("Released {}", clusterMutex);
} catch (OptimisticLockException e) {
final IllegalMonitorStateException imse = new IllegalMonitorStateException("Failed to unlock " + mutexName + " due to another thread/server updating the mutex");
imse.initCause(e);
throw imse;
}
}
});
}
Aggregations