public String updateKind(Key key) { if (key.getKind() == null && key.getKindClass() == null) throw new IllegalStateException("Key is invalid! " + toString()); else if (key.getKind() == null) key.setKind(getMappedClass(key.getKindClass()).getCollectionName()); return key.getKind(); }
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)); }
clazz + "!=" + key.getKindClass() + ") for key and method parameter clazz"); List<Object> objIds = new ArrayList<Object>(); List<Key> kindKeys = kindMap.get(kind); 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(); }
/** * @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); }