public Message getMessage(MessageId identity) throws IOException {
Message rc;
EntityManager manager = adapter.beginEntityManager(null);
try {
StoredMessage message = null;
if (identity.getBrokerSequenceId() != 0) {
message = manager.find(StoredMessage.class, identity.getBrokerSequenceId());
} else {
Query query = manager.createQuery("select m from StoredMessage m where m.messageId=?1");
query.setParameter(1, identity.toString());
message = (StoredMessage)query.getSingleResult();
}
rc = (Message)wireFormat.unmarshal(new ByteSequence(message.getData()));
} catch (Throwable e) {
adapter.rollbackEntityManager(null, manager);
throw IOExceptionSupport.create(e);
}
adapter.commitEntityManager(null, manager);