use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl method purgeAll.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void purgeAll() throws AggregationDAOException {
try {
// purge using simple delete statements
Query delete = entityManager.createQuery("DELETE FROM Aggregation agg where agg.version > -1");
delete.executeUpdate();
delete = entityManager.createQuery("DELETE FROM AggregationCompleted agg where agg.version > -1");
delete.executeUpdate();
entityManager.flush();
}///CLOVER:OFF
catch (Exception e) {
throw new AggregationDAOException("Failed to purge all aggregation information.", e);
}
///CLOVER:ON
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl method addUpdateAggregation.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false, rollbackFor = { AggregationDAOException.class })
public void addUpdateAggregation(Aggregation aggr) throws AggregationDAOException {
try {
// find the aggregation
final Aggregation existingAggr = this.getAggregation(aggr.getId());
// if its not there by the requested aggregation has a version > 1, then somethine is wrong
if (existingAggr == null && aggr.getVersion() > 0)
throw new AggregationVersionException("Aggregation not found but expected to exist due to non 0 version number");
if (existingAggr != null) {
// make sure the version on the existing aggregator matches ours
if (existingAggr.getVersion() != aggr.getVersion())
throw new AggregationVersionException("Version number of aggreation does not match what is in the store.");
// lock the aggregation for update
entityManager.lock(existingAggr, LockModeType.WRITE);
existingAggr.setExchangeBlob(aggr.getExchangeBlob());
entityManager.persist(existingAggr);
} else {
// initial add... set the version number to 1
aggr.setVersion(aggr.getVersion() + 1);
entityManager.persist(aggr);
}
// commit
entityManager.flush();
} catch (AggregationDAOException ae) {
throw ae;
} catch (OptimisticLockException ol) {
throw new AggregationVersionException("Aggregation was updated by another thread or process before it could be committed.");
} catch (Exception e) {
throw new AggregationDAOException("Failed to add or update aggregation.", e);
}
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationCompletedKeysTest method testGetAggregationCompletedKeys_entityManagerException_assertNoAggregation.
@Test
public void testGetAggregationCompletedKeys_entityManagerException_assertNoAggregation() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new RuntimeException()).when(mgr).createQuery((String) any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
boolean exceptionOccured = false;
try {
dao.getAggregationCompletedKeys();
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_entityManagerException_assertException.
@Test
public void testGetAggregationCompleted_entityManagerException_assertException() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new RuntimeException()).when(mgr).find((Class<?>) any(), any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
boolean exceptionOccured = false;
try {
dao.getAggregationCompleted("12345", true);
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.nhindirect.monitor.dao.AggregationDAOException in project nhin-d by DirectProject.
the class AggregationDAOImpl_removeAggregationTest method testRemoveAggregation_emptyRepository_assertExcpetion.
@Test
public void testRemoveAggregation_emptyRepository_assertExcpetion() throws Exception {
final Aggregation remove = new Aggregation();
remove.setExchangeBlob(new byte[] { 0, 3, 2 });
remove.setId("12345");
remove.setVersion(0);
boolean exceptionOccured = false;
try {
notifDao.removeAggregation(remove, "12345");
} catch (AggregationDAOException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
Aggregations