/** * Converts from a List<Key> to their id values * * @param keys * @return The ids of the keys */ protected List<?> keysToIds(List<Key<T>> keys) { ArrayList ids = new ArrayList(keys.size() * 2); for (Key<T> key : keys) ids.add(key.getId()); return ids; }
/** * @param clazz * @param key * @param <T> * @return */ public <T> T getByKey(Class<T> clazz, Key<T> key) { String kind = mapr.getCollectionName(clazz); String keyKind = mapr.updateKind(key); if (!kind.equals(keyKind)) throw new RuntimeException("collection names don't match for key and class: " + kind + " != " + keyKind); return get(clazz, key.getId()); }
@Override public Key<E> saveAndIndex(E entity) { Key<E> save = super.save(entity); String collection = entityManager.getCollection(clazz); if (collection != null) { commonService.indexEntity(ds, save.getKind(), save.getId().toString(), entity); } return save; }
@Override public Key<E> saveAndIndex(final E entity) { final Key<E> save = super.save(entity); final String collection = entityManager.getCollection(clazz); if (collection != null) { commonService.indexEntity(ds, save.getKind(), save.getId().toString(), entity); } return save; } }
Class<T> kindClass = clazz == null ? kindKeys.get(0).getKindClass() : clazz; for (Key key : kindKeys) { objIds.add(key.getId());
/** * @param entityOrKey * @return */ public Key<?> exists(Object entityOrKey) { entityOrKey = ProxyHelper.unwrap(entityOrKey); Key<?> key = mapr.getKey(entityOrKey); Object id = key.getId(); if (id == null) throw new MappingException("Could not get id for " + entityOrKey.getClass().getName()); String collName = key.getKind(); if (collName == null) collName = getCollection(key.getKindClass()).getName(); return find(collName, key.getKindClass()).filter(Mapper.ID_KEY, key.getId()).getKey(); }
public DBRef keyToRef(Key key) { if (key == null) return null; if (key.getKindClass() == null && key.getKind() == null) throw new IllegalStateException("How can it be missing both?"); if (key.getKind() == null) key.setKind(getCollectionName(key.getKindClass())); return new DBRef(null, key.getKind(), toMongoObject(key.getId(), false)); }
/** * @param key * @param ops * @param <T> * @return */ public <T> UpdateResults<T> update(Key<T> key, UpdateOperations<T> ops) { Class<T> clazz = (Class<T>) key.getKindClass(); if (clazz == null) clazz = (Class<T>) mapr.getClassFromKind(key.getKind()); return updateFirst(createQuery(clazz).disableValidation().filter(Mapper.ID_KEY, key.getId()), ops); }