* @return the associated message, or <code>null</code> if none exists
* @throws JMSException for any error
*/
public synchronized MessageImpl getMessage(MessageRef reference)
throws JMSException {
MessageImpl message;
final String messageId = reference.getMessageId();
if (reference.isPersistent()) {
message = (MessageImpl) _persistent.get(messageId);
// if the message is not cached then try and retrieve it from the
// database and cache it.
if (message == null) {
// fault in at least the next message from the database
try {
DatabaseService service = DatabaseService.getInstance();
PersistenceAdapter adapter = service.getAdapter();
Connection connection = service.getConnection();
message = adapter.getMessage(connection, messageId);
} catch (PersistenceException exception) {
final String msg = "Failed to retrieve message";
_log.error(msg, exception);
throw new JMSException(msg + ": " + exception.getMessage());
}
// add the message to the persistent cache once it has been
// retrieved from the datastore
if (message != null) {
_persistent.put(messageId, message);
}
}
} else {
message = (MessageImpl) _transient.get(messageId);
}
if (message != null && !message.getReadOnly()) {
// mark the message as read-only
message.setReadOnly(true);
}
return message;
}