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

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

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

Key.<init>介绍

[英]For GWT serialization
[中]用于GWT序列化

代码示例

代码示例来源:origin: querydsl/querydsl

@Override
  protected DBRef asReferenceKey(Class<?> entity, Object id) {
    String collection = morphia.getMapper().getCollectionName(entity);
    Key<?> key = new Key<Object>(entity, collection, id);
    return morphia.getMapper().keyToDBRef(key);
  }
}

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

/**
 * Creates a Key for a type and an ID value
 *
 * @param type the Class of the entity
 * @param id   the ID value
 * @param <T>  the type of the entity
 * @return the Key
 */
public <T> Key<T> manualRefToKey(final Class<T> type, final Object id) {
  return id == null ? null : new Key<T>(type, getCollectionName(type), id);
}

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

<T> Key<T> manualRefToKey(final String collection, final Object id) {
  return id == null ? null : new Key<T>((Class<? extends T>) getClassFromCollection(collection), collection, id);
}

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

<T> Key<T> createKey(final Class<T> clazz, final Serializable id) {
  return new Key<T>(clazz, getCollectionName(clazz), id);
}

代码示例来源:origin: katharsis-project/katharsis-framework

public Project findOne(ObjectId id, QueryParams requestParams) {
  return datastore.getByKey(Project.class, new Key<>(Project.class, id));
}

代码示例来源:origin: katharsis-project/katharsis-framework

public Task findOne(ObjectId id, QueryParams requestParams) {
  return datastore.getByKey(Task.class, new Key<>(Task.class, id));
}

代码示例来源:origin: groupon/DotCi

private Key extractKey(final Mapper mapper, final MappedField mf, final DBObject dbObject) {
  if (mapper == null || mf == null || dbObject == null || (dbObject instanceof BasicDBList))
    return null;
  final ObjectId objectId = (ObjectId) dbObject.get(mapper.ID_KEY);
  //HACKY GET RID OF SOON
  final Object obj = mapper.getOptions().getObjectFactory().createInstance(mapper, mf, dbObject);
  if (objectId == null || obj == null) return null;
  return new Key(obj.getClass(), objectId);
}

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

/**
 * Gets the Key for an entity and a specific collection
 *
 * @param entity     the entity to process
 * @param collection the collection to use in the Key rather than the mapped collection as defined on the entity's class
 * @param <T>        the type of the entity
 * @return the Key
 */
public <T> Key<T> getKey(final T entity, final String collection) {
  T unwrapped = entity;
  if (unwrapped instanceof ProxiedEntityReference) {
    final ProxiedEntityReference proxy = (ProxiedEntityReference) unwrapped;
    return (Key<T>) proxy.__getKey();
  }
  unwrapped = ProxyHelper.unwrap(unwrapped);
  if (unwrapped instanceof Key) {
    return (Key<T>) unwrapped;
  }
  final Object id = getId(unwrapped);
  final Class<T> aClass = (Class<T>) unwrapped.getClass();
  return id == null ? null : new Key<T>(aClass, collection, id);
}

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

@SuppressWarnings("unchecked")
private <T> List<Key<T>> postSaveOperations(final Iterable<T> entities, final Map<Object, DBObject> involvedObjects,
                      final DBCollection collection, final boolean fetchKeys) {
  List<Key<T>> keys = new ArrayList<Key<T>>();
  for (final T entity : entities) {
    final DBObject dbObj = involvedObjects.remove(entity);
    if (fetchKeys) {
      if (dbObj.get(Mapper.ID_KEY) == null) {
        throw new MappingException(format("Missing _id after save on %s", entity.getClass().getName()));
      }
      mapper.updateKeyAndVersionInfo(this, dbObj, createCache(), entity);
      keys.add(new Key<T>((Class<? extends T>) entity.getClass(), collection.getName(), mapper.getId(entity)));
    }
    mapper.getMappedClass(entity).callLifecycleMethods(PostPersist.class, entity, dbObj, mapper);
  }
  for (Entry<Object, DBObject> entry : involvedObjects.entrySet()) {
    final Object key = entry.getKey();
    mapper.getMappedClass(key).callLifecycleMethods(PostPersist.class, key, entry.getValue(), mapper);
  }
  return keys;
}

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

/**
 * Gets the Key for an entity
 *
 * @param entity the entity to process
 * @param <T>    the type of the entity
 * @return the Key
 */
public <T> Key<T> getKey(final T entity) {
  T unwrapped = entity;
  if (unwrapped instanceof ProxiedEntityReference) {
    final ProxiedEntityReference proxy = (ProxiedEntityReference) unwrapped;
    return (Key<T>) proxy.__getKey();
  }
  unwrapped = ProxyHelper.unwrap(unwrapped);
  if (unwrapped instanceof Key) {
    return (Key<T>) unwrapped;
  }
  final Object id = getId(unwrapped);
  final Class<T> aClass = (Class<T>) unwrapped.getClass();
  return id == null ? null : new Key<T>(aClass, getCollectionName(aClass), id);
}

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

private Key<?> getKey(final Object entity, final Mapper mapper) {
  try {
    if (entity instanceof ProxiedEntityReference) {
      final ProxiedEntityReference proxy = (ProxiedEntityReference) entity;
      return proxy.__getKey();
    }
    final MappedClass mappedClass = mapper.getMappedClass(entity);
    Object id = mappedClass.getIdField().get(entity);
    if (id == null) {
      throw new MappingException("@Id field cannot be null!");
    }
    return new Key(mappedClass.getClazz(), mappedClass.getCollectionName(), id);
  } catch (IllegalAccessException iae) {
    throw new RuntimeException(iae);
  }
}

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

/**
 * Converts a DBRef to a Key
 *
 * @param ref the DBRef to convert
 * @param <T> the type of the referenced entity
 * @return the Key
 */
public <T> Key<T> refToKey(final DBRef ref) {
  return ref == null ? null : new Key<T>((Class<? extends T>) getClassFromCollection(ref.getCollectionName()),
                      ref.getCollectionName(), ref.getId());
}

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

<T> Key<T> createKey(final Class<T> clazz, final Object id) {
  if (id instanceof Serializable) {
    return createKey(clazz, (Serializable) id);
  }
  //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does.
  final BSONEncoder enc = new BasicBSONEncoder();
  return new Key<T>(clazz, getCollectionName(clazz), enc.encode(toDBObject(id)));
}

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

@Override
public Object decode(final Class targetClass, final Object o, final MappedField optionalExtraInfo) {
  if (o == null) {
    return null;
  }
  if (!(o instanceof DBRef)) {
    throw new ConverterException(String.format("cannot convert %s to Key because it isn't a DBRef", o.toString()));
  }
  DBRef ref = (DBRef) o;
  MappedField actualType = getActualType(optionalExtraInfo);
  final Class<?> keyType = actualType != null
               ? actualType.getConcreteType()
               : getMapper().getClassFromCollection(ref.getCollectionName());
  final Key<?> key = new Key<Object>(keyType, ref.getCollectionName(), ref.getId());
  return key;
}

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

final Key<T> key = new Key(entity.getClass(), getCollectionName(entity.getClass()), dbObject.get(ID_KEY));
final T cachedInstance = cache.getEntity(key);
if (cachedInstance != null) {
  final Key key = new Key(entity.getClass(), getCollectionName(entity.getClass()), updated.get(ID_KEY));
  cache.putEntity(key, entity);

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

@Override
  @SuppressWarnings("unchecked")
  protected Key<T> convertItem(final DBObject dbObj) {
    Object id = dbObj.get(Mapper.ID_KEY);
    if (id instanceof DBObject) {
      Class type = getMapper().getMappedClass(getClazz()).getMappedIdField().getType();
      id = getMapper().fromDBObject(getDatastore(), type, (DBObject) id, getMapper().createEntityCache());
    }
    return new Key<T>(getClazz(), getCollection(), id);
  }
}

相关文章

微信公众号

最新文章

更多