}
}
boolean exists(final Class c, final Object ref, final EntityCache cache, final Mapper mapper, final boolean idOnly) {
final Key key = idOnly ? mapper.manualRefToKey(c, ref) : mapper.refToKey((DBRef) ref);
final DBRef dbRef = idOnly ? null : (DBRef) ref;
final Boolean cached = cache.exists(key);
if (cached != null) {
return cached;
}
final DatastoreImpl dsi = (DatastoreImpl) mapper.getDatastoreProvider().get();
final DBCollection dbColl = dsi.getCollection(c);
if (!idOnly && !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);
}
final boolean exists;
if (idOnly) {
exists = (dsi.find(dbColl.getName(), c).disableValidation().filter("_id", ref).asKeyList().size() == 1);
} else {
exists = (dsi.find(dbRef.getRef(), c).disableValidation().filter("_id", dbRef.getId()).asKeyList().size() == 1);
}
cache.notifyExists(key, exists);
return exists;
}