create last message count in DB if it doesn't exist, to avoid NPE

This commit is contained in:
Axel Uhl
2011-11-21 11:01:05 +01:00
parent fd09acf6c8
commit 9930349e70
@@ -153,6 +153,9 @@ public class StoreAndForward implements Runnable {
private long getLastMessageCount() {
DBObject lastMessageCountRecord = lastMessageCountCollection.findOne();
if (lastMessageCountRecord == null) {
lastMessageCountCollection.insert(new BasicDBObject().append(FieldNames.LAST_MESSAGE_COUNT.name(), "0"));
}
return lastMessageCountRecord == null ? 0 : (Long) lastMessageCountRecord.get(FieldNames.LAST_MESSAGE_COUNT.name());
}