Search in sources :

Example 1 with Aggregation

use of org.nhindirect.monitor.dao.entity.Aggregation in project nhin-d by DirectProject.

the class ConcurrentJPAAggregationRepository method get.

/**
	 * {@inheritDoc}
	 */
@Override
public Exchange get(CamelContext camelContext, String key) {
    Exchange retVal = null;
    try {
        // get the aggregation
        final Aggregation agg = dao.getAggregation(key);
        if (agg == null)
            return null;
        // deserialized to an exchange object
        retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
        // set the version of the exchange for later consistency checking
        retVal.setProperty(AGGREGATION_ENTITY_VERSON, agg.getVersion());
    } catch (Exception e) {
        // wrap exception in a runtime exception
        throw new RuntimeException("Error retrieving from repository aggregation with key " + key, e);
    }
    return retVal;
}
Also used : Exchange(org.apache.camel.Exchange) Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) Buffer(org.fusesource.hawtbuf.Buffer)

Example 2 with Aggregation

use of org.nhindirect.monitor.dao.entity.Aggregation in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationCompletedKeysTest method testGetAggregationCompletedKeys_singleEntryInRepository_assertKeysRetrieved.

@Test
public void testGetAggregationCompletedKeys_singleEntryInRepository_assertKeysRetrieved() 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");
    List<String> keys = notifDao.getAggregationCompletedKeys();
    assertEquals(1, keys.size());
    assertEquals("12345", keys.iterator().next());
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) Test(org.junit.Test)

Example 3 with Aggregation

use of org.nhindirect.monitor.dao.entity.Aggregation in project nhin-d by DirectProject.

the class AggregationDAOImpl_getAggregationKeysTest method testGetAggregationKeys_singleEntryInRepository_assertKeysRetrieved.

@Test
public void testGetAggregationKeys_singleEntryInRepository_assertKeysRetrieved() throws Exception {
    final Aggregation insert = new Aggregation();
    insert.setExchangeBlob(new byte[] { 0, 3, 2 });
    insert.setId("12345");
    insert.setVersion(0);
    notifDao.addUpdateAggregation(insert);
    List<String> keys = notifDao.getAggregationKeys();
    assertEquals(1, keys.size());
    assertEquals("12345", keys.iterator().next());
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) Test(org.junit.Test)

Example 4 with Aggregation

use of org.nhindirect.monitor.dao.entity.Aggregation in project nhin-d by DirectProject.

the class AggregationDAOImpl_removeAggregationTest method testRemoveAggregation_removeAggregation_incorrectVersion_assertException.

@Test
public void testRemoveAggregation_removeAggregation_incorrectVersion_assertException() 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(3);
    boolean exceptionOccured = false;
    try {
        notifDao.removeAggregation(remove, "12345");
    } catch (AggregationDAOException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) AggregationDAOException(org.nhindirect.monitor.dao.AggregationDAOException) Test(org.junit.Test)

Example 5 with Aggregation

use of org.nhindirect.monitor.dao.entity.Aggregation 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()));
}
Also used : Aggregation(org.nhindirect.monitor.dao.entity.Aggregation) AggregationCompleted(org.nhindirect.monitor.dao.entity.AggregationCompleted) Test(org.junit.Test)

Aggregations

Aggregation (org.nhindirect.monitor.dao.entity.Aggregation)25 Test (org.junit.Test)20 AggregationDAOException (org.nhindirect.monitor.dao.AggregationDAOException)7 AggregationCompleted (org.nhindirect.monitor.dao.entity.AggregationCompleted)6 OptimisticLockException (javax.persistence.OptimisticLockException)3 AggregationVersionException (org.nhindirect.monitor.dao.AggregationVersionException)3 EntityManager (javax.persistence.EntityManager)2 AggregationDAOImpl (org.nhindirect.monitor.dao.impl.AggregationDAOImpl)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Exchange (org.apache.camel.Exchange)1 Buffer (org.fusesource.hawtbuf.Buffer)1