use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository method recover.
/**
* {@inheritDoc}
* This specific implementation locks the recovered exchange for a period of time specified by the DAO.
* If the exchange is locked by the DAO, then null is returned.
*/
@Override
public Exchange recover(CamelContext camelContext, String exchangeId) {
Exchange retVal = null;
try {
// recover the exchnage from the repository
final AggregationCompleted agg = dao.getAggregationCompleted(exchangeId, true);
// not found or is locked... return null
if (agg == null)
return null;
// deserialize exchange
retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
// set the version number of the exchange
retVal.setProperty(AGGREGATION_COMPLETE_ENTITY_VERSON, agg.getVersion());
} catch (Exception e) {
// wrap exception in a runtime exception
throw new RuntimeException("Error recovering exchange from repository with exchangeId " + exchangeId, e);
}
return retVal;
}
use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_emptyRepository_assertNoAggregation.
@Test
public void testGetAggregationCompleted_emptyRepository_assertNoAggregation() throws Exception {
final AggregationCompleted aggr = notifDao.getAggregationCompleted("doenst matter", true);
assertNull(aggr);
}
use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.
the class AggregationDAOImpl_getAggregationCompletedTest method testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound.
@Test
public void testGetAggregationCompleted_optomisticLockException_assertAggregationCompletedNotFound() throws Exception {
EntityManager mgr = mock(EntityManager.class);
doThrow(new OptimisticLockException()).when(mgr).find((Class<?>) any(), any());
final AggregationDAOImpl dao = new AggregationDAOImpl();
dao.setEntityManager(mgr);
final AggregationCompleted lockedAggr = dao.getAggregationCompleted("12345", true);
assertNull(lockedAggr);
}
use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.
the class AggregationDAOImpl_removeAggregationTest method testRemoveAggregation_removeAggregation_assertRemovedAndCompletedRepositry.
@Test
public void testRemoveAggregation_removeAggregation_assertRemovedAndCompletedRepositry() throws Exception {
final Aggregation insert = new Aggregation();
insert.setExchangeBlob(new byte[] { 0, 3, 2 });
insert.setId("12345");
insert.setVersion(0);
notifDao.addUpdateAggregation(insert);
assertNotNull(notifDao.getAggregation("12345"));
final Aggregation remove = new Aggregation();
remove.setExchangeBlob(new byte[] { 0, 3, 2 });
remove.setId("12345");
remove.setVersion(1);
notifDao.removeAggregation(remove, "12345");
assertNull(notifDao.getAggregation("12345"));
final AggregationCompleted completed = notifDao.getAggregationCompleted("12345", true);
assertNotNull(completed);
assertEquals("12345", completed.getId());
assertEquals(3, completed.getVersion());
assertTrue(Arrays.equals(remove.getExchangeBlob(), completed.getExchangeBlob()));
}
use of org.nhindirect.monitor.dao.entity.AggregationCompleted in project nhin-d by DirectProject.
the class AggregationDAOImpl method confirmAggregation.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void confirmAggregation(String id) throws AggregationDAOException {
try {
// find the aggregation
final AggregationCompleted completed = entityManager.find(AggregationCompleted.class, id);
if (completed != null) {
// remove it
entityManager.remove(completed);
entityManager.flush();
}
} catch (Exception e) {
throw new AggregationDAOException("Failed to confirm aggregation.", e);
}
}
Aggregations