/** * The underlying collection for this DAO */ public DBCollection getCollection() { return ds.getCollection(entityClazz); }
@PrePersist void prePersist() { if (myLongId == null) { String collName = ds.getCollection(getClass()).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); } myLongId = newId.getValue(); } }
boolean exists(Class c, final DBRef dbRef, EntityCache cache, Mapper mapr) { Key key = mapr.refToKey(dbRef); Boolean cached = cache.exists(key); if (cached != null) return cached; Datastore dsi = mapr.getDatastoreProvider().get(); DBCollection dbColl = dsi.getCollection(c); if (!dbColl.getName().equals(dbRef.getRef())) log.warning("Class " + c.getName() + " is stored in the '" + dbColl.getName() + "' collection but a reference was found for this type to another collection, '" + dbRef.getRef() + "'. The reference will be loaded using the class anyway. " + dbRef); boolean exists = (dsi.find(dbRef.getRef(), c).disableValidation().filter("_id", dbRef.getId()).asKeyList() .size() == 1); cache.notifyExists(key, exists); return exists; }