public static <T extends Model> Long generateLongId(Class<T> clazz){
synchronized (clazz) {
String collName = ds().getCollection(clazz).getName();
Query<StoredId> q = ds().find(StoredId.class, "_id", collName);
UpdateOperations<StoredId> uOps = ds().createUpdateOperations(StoredId.class).inc("value");
StoredId newId = ds().findAndModify(q, uOps);
if (newId == null) {
newId = new StoredId(collName);
ds().save(newId);
}
return newId.getValue();
}
}