public List<K> findIds(Query<T> q) { return (List<K>) keysToIds(q.asKeyList()); }
public List<K> findIds(String key, Object value) { return (List<K>) keysToIds(ds.find(entityClazz, key, value).asKeyList()); }
public List<K> findIds() { return (List<K>) keysToIds(ds.find(entityClazz).asKeyList()); }
/** * Queries the server to check for each DBRef. */ public <T> List<Key<T>> getKeysByRefs(List<DBRef> refs) { ArrayList<Key<T>> tempKeys = new ArrayList<Key<T>>(refs.size()); Map<String, List<DBRef>> kindMap = new HashMap<String, List<DBRef>>(); for (DBRef ref : refs) { if (kindMap.containsKey(ref.getRef())) kindMap.get(ref.getRef()).add(ref); else kindMap.put(ref.getRef(), new ArrayList<DBRef>(Collections.singletonList((DBRef) ref))); } for (String kind : kindMap.keySet()) { List<Object> objIds = new ArrayList<Object>(); List<DBRef> kindRefs = kindMap.get(kind); for (DBRef key : kindRefs) { objIds.add(key.getId()); } List<Key<T>> kindResults = this.<T>find(kind, null).disableValidation().filter("_id in", objIds).asKeyList(); tempKeys.addAll(kindResults); } //put them back in order, minus the missing ones. ArrayList<Key<T>> keys = new ArrayList<Key<T>>(refs.size()); for (DBRef ref : refs) { Key<T> testKey = mapr.refToKey(ref); if (tempKeys.contains(testKey)) keys.add(testKey); } return keys; }
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; }