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

x33g5p2x  于2022-01-18 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(102)

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

Datastore.getKey介绍

[英]Creates a (type-safe) reference to the entity; if stored this will become a com.mongodb.DBRef
[中]创建对实体的(类型安全)引用;如果存储,这将成为一个com。mongodb。DBRef

代码示例

代码示例来源: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

private void syncKeys() {
    final Datastore ds = getDatastore();

    listOfKeys.clear();
    for (final Object e : ((Collection) object)) {
      listOfKeys.add(ds.getKey(e));
    }
  }
}

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

@SuppressWarnings("unchecked")
private void syncKeys() {
  final Datastore ds = getDatastore();
  keyMap.clear();
  final Map<Object, Object> map = (Map) object;
  for (final Map.Entry<Object, Object> e : map.entrySet()) {
    keyMap.put(e.getKey(), ds.getKey(e.getValue()));
  }
}

代码示例来源: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;
}

相关文章