org.mongodb.morphia.Key.getId()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中org.mongodb.morphia.Key.getId()方法的一些代码示例,展示了Key.getId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Key.getId()方法的具体详情如下:
包路径:org.mongodb.morphia.Key
类名称:Key
方法名:getId

Key.getId介绍

暂无

代码示例

代码示例来源:origin: org.mongodb.morphia/morphia

Object keyToId(final Key key) {
  return key == null ? null : key.getId();
}

代码示例来源:origin: org.mongodb.morphia/morphia

/**
 * Converts from a List<Key> to their id values
 */
protected List<?> keysToIds(final List<Key<T>> keys) {
  final List<Object> ids = new ArrayList<Object>(keys.size() * 2);
  for (final Key<T> key : keys) {
    ids.add(key.getId());
  }
  return ids;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

public Object getId(Object object) {
  if (object == null) return "";
  return datastore.getKey(object).getId();
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public <T> T getByKey(final Class<T> clazz, final Key<T> key) {
  final String collectionName = mapper.getCollectionName(clazz);
  final String keyCollection = mapper.updateCollection(key);
  if (!collectionName.equals(keyCollection)) {
    throw new RuntimeException("collection names don't match for key and class: " + collectionName + " != " + keyCollection);
  }
  Object id = key.getId();
  if (id instanceof DBObject) {
    ((DBObject) id).removeField(Mapper.CLASS_NAME_FIELDNAME);
  }
  return get(clazz, id);
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
  if ("finalize".equals(method.getName()) && args != null && args.length == 0) {
    return null;
  }
  /*
   * If the method being invoked is annotated with @IdGetter and the delegate reference is an EntityObjectReference,
   * return the id of the EntityObjectReference's key. This allows us to return the referenced entity's id without
   * fetching the entity from the datastore.
   */
  if (method.getAnnotation(IdGetter.class) != null) {
    ObjectReference<Object> delegateReference = getDelegateReference();
    if (delegateReference instanceof EntityObjectReference) {
      EntityObjectReference entityObjectReference = (EntityObjectReference) delegateReference;
      return entityObjectReference.__getKey().getId();
    }
  }
  return super.invoke(proxy, method, args);
}

代码示例来源:origin: org.mongodb.morphia/morphia

private Object getDBRefs(final MappedField field, final Iterable value) {
  final List<Object> refs = new ArrayList<Object>();
  Reference annotation = field.getAnnotation(Reference.class);
  boolean idOnly = annotation != null && annotation.idOnly();
  for (final Object o : value) {
    Key<?> key = (o instanceof Key) ? (Key<?>) o : getKey(o);
    refs.add(idOnly ? key.getId() : keyToDBRef(key));
  }
  return refs;
}

代码示例来源:origin: org.mongodb.morphia/morphia

private Query<?> buildExistsQuery(final Object entityOrKey) {
  final Object unwrapped = ProxyHelper.unwrap(entityOrKey);
  final Key<?> key = mapper.getKey(unwrapped);
  final Object id = key.getId();
  if (id == null) {
    throw new MappingException("Could not get id for " + unwrapped.getClass().getName());
  }
  return find(key.getCollection(), key.getType()).filter(Mapper.ID_KEY, key.getId());
}

代码示例来源:origin: org.mongodb.morphia/morphia

objIds.add(key.getId());

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

@SuppressWarnings("unchecked")
@Override
public void reloadObject(DbConnection con, String registryName, Object obj) throws MException {
  Object id = datastore.getKey(obj).getId();
  Object clone = datastore.get(obj.getClass(), id);
  try {
    PojoModel model = getModelFor(obj.getClass());
    for ( PojoAttribute<Object> f : model) {
      Object v = f.get(clone);
      f.set(obj, v);
    }
  } catch (IOException e) {
    throw new MException(e);
  }
}

代码示例来源:origin: de.mhus.lib/mhu-lib-persistence

@Override
public boolean objectChanged(Object obj) throws MException {
  Object id = datastore.getKey(obj).getId();
  Object clone = datastore.get(obj.getClass(), id);
  try {
    PojoModel model = getModelFor(obj.getClass());
    for ( PojoAttribute<?> f : model) {
      Object v1 = f.get(obj);
      Object v2 = f.get(clone);
      if (!MSystem.equals(v1, v2)) return true;
    }
  } catch (IOException e) {
    throw new MException(e);
  }
  return false;
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
@SuppressWarnings("unchecked")
public <T> UpdateResults update(final Key<T> key, final UpdateOperations<T> operations) {
  Class<T> clazz = (Class<T>) key.getType();
  if (clazz == null) {
    clazz = (Class<T>) mapper.getClassFromCollection(key.getCollection());
  }
  return updateFirst(createQuery(clazz).disableValidation().filter(Mapper.ID_KEY, key.getId()), operations);
}

代码示例来源:origin: org.mongodb.morphia/morphia

/**
 * Converts a Key to a DBRef
 *
 * @param key the Key to convert
 * @return the DBRef
 */
public DBRef keyToDBRef(final Key key) {
  if (key == null) {
    return null;
  }
  if (key.getType() == null && key.getCollection() == null) {
    throw new IllegalStateException("How can it be missing both?");
  }
  if (key.getCollection() == null) {
    key.setCollection(getCollectionName(key.getType()));
  }
  Object id = key.getId();
  if (isMapped(id.getClass())) {
    id = toMongoObject(id, true);
  }
  return new DBRef(key.getCollection(), id);
}

相关文章