@@ -0,0 +1,938 @@
+package net.davidvoid.thor.lightning.data.access;%0D%0A%0D%0Aimport net.davidvoid.thor.lightning.data.source.MongoDataSource;%0D%0A%0D%0Aimport org.springframework.beans.factory.annotation.Autowired;%0D%0Aimport org.springframework.stereotype.Component;%0D%0A%0D%0Aimport com.mongodb.BasicDBObject;%0D%0Aimport com.mongodb.DBCollection;%0D%0Aimport com.mongodb.DBObject;%0D%0A%0D%0A/**%0D%0A * Created by david on 3/22/16.%0D%0A * %7B_id: XX, name: string, seq: long %7D%0D%0A * index 1: name, unique%0D%0A *%0D%0A */%0D%0A@Component%0D%0Apublic class Counter %7B%0D%0A%09@Autowired%0D%0A%09MongoDataSource data_source = null;%0D%0A%0D%0A%09public long getNextId(String col_name) %7B%0D%0A%09%09BasicDBObject query = new BasicDBObject(%22name%22, col_name);%0D%0A%09%09BasicDBObject update = new BasicDBObject(%22$inc%22, new BasicDBObject(%22seq%22, 1));%0D%0A%0D%0A%09%09DBCollection col = data_source.getDatabase().getCollection(%22counter%22);%0D%0A%09%09DBObject returned = col.findAndModify(query, null, null, false, update, true, true);%0D%0A%0D%0A%09%09return (long) returned.get(%22seq%22);%0D%0A%09%7D%0D%0A%7D%0D%0A

add a counter class to generate auto incremental ids