Query query = persister.newQuery(PChatMessage.class);
query.declareParameters("String desiredRoom, int earliest");//(6)
query.setFilter("chat == desiredRoom && date > earliest"); //(7)
query.setOrdering("date");
List<PChatMessage> messages = (List<PChatMessage>)query.execute(chat, timestamp);
ChatMessageList msgList = null;
// Get the most recent message.
if (messages.size() >= 1) {
PChatMessage lastMessage = messages.get(messages.size() - 1);
msgList = new ChatMessageList(chat, lastMessage.getDate());
} else {
msgList = new ChatMessageList(chat, System.currentTimeMillis());
}
for (PChatMessage msg : messages) {
msgList.addMessage(msg.asChatMessage());
}
return msgList;
} finally {
persister.close();
}