Пример #1
0
  @SuppressWarnings("rawtypes")
  public <T> List<T> getByKeys(Class<T> clazz, Iterable<Key<T>> keys) {

    Map<String, List<Key>> kindMap = new HashMap<String, List<Key>>();
    List<T> entities = new ArrayList<T>();
    // String clazzKind = (clazz==null) ? null :
    // getMapper().getCollectionName(clazz);
    for (Key<?> key : keys) {
      mapr.updateKind(key);

      // if (clazzKind != null && !key.getKind().equals(clazzKind))
      // throw new IllegalArgumentException("Types are not equal (" +
      // clazz + "!=" + key.getKindClass() +
      // ") for key and method parameter clazz");
      //
      if (kindMap.containsKey(key.getKind())) kindMap.get(key.getKind()).add(key);
      else kindMap.put(key.getKind(), new ArrayList<Key>(Collections.singletonList((Key) key)));
    }
    for (String kind : kindMap.keySet()) {
      List<Object> objIds = new ArrayList<Object>();
      List<Key> kindKeys = kindMap.get(kind);
      for (Key key : kindKeys) {
        objIds.add(key.getId());
      }
      List kindResults = find(kind, null).disableValidation().filter("_id in", objIds).asList();
      entities.addAll(kindResults);
    }

    // TODO: order them based on the incoming Keys.
    return entities;
  }
Пример #2
0
 /** Test key from kind and name. */
 public void testKeyFromKindAndName() {
   Key key = new Key(kind, name);
   assertEquals(kind, key.getKind());
   assertEquals(name, key.getName());
   assertNull(key.getParent());
   assertEquals(0L, key.getId());
 }
Пример #3
0
 /** Test key from kind, parent and name. */
 public void testKeyFromKindParentAndName() {
   Key parent = new Key(kind);
   Key key = new Key(kind, parent, name);
   assertEquals(kind, key.getKind());
   assertEquals(name, key.getName());
   assertEquals(parent, key.getParent());
   assertEquals(0L, key.getId());
 }
Пример #4
0
 /** Test key from kind, parent and id. */
 public void testKeyFromKindParentAndId() {
   Key parent = new Key(kind);
   Key key = new Key(kind, parent, id);
   assertEquals(kind, key.getKind());
   assertNull(key.getName());
   assertEquals(id, key.getId());
   assertEquals(parent, key.getParent());
 }
Пример #5
0
  public Key<?> exists(Object entityOrKey) {
    entityOrKey = ProxyHelper.unwrap(entityOrKey);
    Key<?> key = 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();
  }
Пример #6
0
 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);
 }