com.googlecode.objectify.Key.create()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(90)

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

Key.create介绍

[英]Key.create(key) is easier to type than new Key(key)
[中]钥匙创建(键)比键入新键(键)更容易

代码示例

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

@Override
  public Key<?> fromString(String str) {
    return Key.create(str);
  }
}

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

/** This is an alias for Key.create(String) which exists for JAX-RS compliance. */
public static <T> Key<T> valueOf(final String webSafeString) {
  return Key.create(webSafeString);
}

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

/** */
  @Override
  public Key deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String text = jp.getText();
    return Key.create(text);
  }
}

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

/**
   */
  @Override
  public Ref deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    if (jp.getCurrentToken() != JsonToken.VALUE_STRING)
      throw new IllegalStateException("Cannot yet deserialize Refs that were serialized to a full entity object (as opposed to just string key representation)");

    String text = jp.getText();
    return Ref.create(Key.create(text));
  }
}

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

/** Creates a Ref from a registered pojo entity */
public static <T> Ref<T> create(T value) {
  Key<T> key = Key.create(value);
  return create(key);
}

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

@Override
  protected Void wrap(final Void orig) {
    for (com.google.cloud.datastore.Key key: keys)
      session.addValue(Key.create(key), null);
    return orig;
  }
};

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

@Override
public Key<T> next() {
  final com.google.cloud.datastore.Key key = source.next();
  return Key.create(key);
}

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

/**
 * @return the Key<?> for a registered pojo entity.
 */
public <T> Key<T> keyOf(final T pojo) {
  return Key.create(rawKeyOf(pojo));
}

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

@Override
protected Key<?> toPojo(final Value<com.google.cloud.datastore.Key> value) {
  return Key.create(value.get());
}

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

/**
 * <p>Gets the Key<T> given an object that might be a Key, Key<T>, or entity.</p>
 *
 * @param keyOrEntity must be a Key, Key<T>, or registered entity.
 * @throws NullPointerException if keyOrEntity is null
 * @throws IllegalArgumentException if keyOrEntity is not a Key, Key<T>, or registered entity
 */
@SuppressWarnings("unchecked")
public <T> Key<T> anythingToKey(final Object keyOrEntity) {
  if (keyOrEntity instanceof Key<?>)
    return (Key<T>)keyOrEntity;
  else if (keyOrEntity instanceof com.google.cloud.datastore.Key)
    return Key.create((com.google.cloud.datastore.Key)keyOrEntity);
  else if (keyOrEntity instanceof Ref)
    return ((Ref<T>)keyOrEntity).key();
  else if (keyOrEntity instanceof FullEntity<?>)
    return Key.create(getKey((FullEntity<?>)keyOrEntity));
  else
    return keyOf((T)keyOrEntity);
}

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

@Override
protected Ref<?> loadValue(final Value<com.google.cloud.datastore.Key> value, final LoadContext ctx, final Path path) throws SkipException {
  return ctx.loadRef(Key.create(value.get()), loadConditions);
}

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

/** */
@Override
public Map<Key<?>, Object> nowUncached() {
  final Map<Key<?>, Object> result = new HashMap<>(raw.now().size() * 2);
  ctx = new LoadContext(LoadEngine.this);
  for (final Entity ent: raw.now().values()) {
    final Key<?> key = Key.create(ent.getKey());
    final Object entity = load(ent, ctx);
    result.put(key, entity);
  }
  return result;
}

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

/**
 * @param parent can be null for root keys
 */
public <T> Key<T> createKey(final Key<?> parent, final Class<T> kind, final long id) {
  final com.google.cloud.datastore.Key key = createRaw(raw(parent), Key.getKind(kind), id);
  return Key.create(key);
}

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

/**
 * @param parent can be null for root keys
 */
public <T> Key<T> createKey(final Key<?> parent, final Class<T> kind, final String name) {
  final com.google.cloud.datastore.Key key = createRaw(raw(parent), Key.getKind(kind), name);
  return Key.create(key);
}

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

/**
 * Eliminate any deferred operations against the entity. Used when an explicit save (or delete) was
 * executed against the key, so we no longer need the deferred operation.
 *
 * @param keyOrEntity can be a Key, Key<?>, Entity, or entity pojo
 */
public void undefer(final Object keyOrEntity) {
  if (keyOrEntity instanceof Key<?>) {
    operations.remove((Key<?>)keyOrEntity);
  }
  else if (keyOrEntity instanceof com.google.cloud.datastore.Key) {
    operations.remove(Key.create((com.google.cloud.datastore.Key)keyOrEntity));
  }
  else if (factory().keys().requiresAutogeneratedId(keyOrEntity)) {	// note might be FullEntity without complete key
    autogeneratedIdSaves.remove(keyOrEntity);
  }
  else {
    final Key<?> key = factory().keys().keyOf(keyOrEntity);
    operations.remove(key);
  }
}

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

/**
 * Make a key for the given id, which could be either string or long
 */
private <T> Key<T> makeKey(final Object id) {
  final com.google.cloud.datastore.Key key = factory().keys().createRawAny(Keys.raw(this.parent), kind, id);
  return Key.create(key);
}

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

/**
 * Converts an entity to an object of the appropriate type for this metadata structure.
 * Does not check that the entity is appropriate; that should be done when choosing
 * which EntityMetadata to call.
 */
public P load(final BaseEntity<?> ent, final LoadContext ctx) {
  try {
    // The context needs to know the root entity for any given point
    ctx.setCurrentRoot(Key.create((com.google.cloud.datastore.Key)ent.getKey()));
    final EntityValue entityValue = makeLoadEntityValue(ent);
    return translator.load(entityValue, ctx, Path.root());
  }
  catch (LoadException ex) { throw ex; }
  catch (Exception ex) {
    throw new LoadException(ent, ex.getMessage(), ex);
  }
}

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

/**
   * The fundamental delete() operation.
   */
  public Result<Void> delete(final Iterable<com.google.cloud.datastore.Key> keys) {
    for (com.google.cloud.datastore.Key key: keys)
      deferrer.undefer(Key.create(key));

    final Future<Void> fut = datastore.delete(keys);
    final Result<Void> adapted = new ResultAdapter<>(fut);
    final Result<Void> result = new ResultWrapper<Void, Void>(adapted) {
      @Override
      protected Void wrap(final Void orig) {
        for (com.google.cloud.datastore.Key key: keys)
          session.addValue(Key.create(key), null);

        return orig;
      }
    };

    if (ofy.getTransaction() != null)
      ((PrivateAsyncTransaction)ofy.getTransaction()).enlist(result);

    return result;
  }
}

代码示例来源:origin: TEAMMATES/teammates

@Override
protected Query<Account> getFilterQuery() {
  return ofy().load().type(Account.class).filterKey(Key.create(Account.class, fromAccountGoogleId));
}

代码示例来源:origin: TEAMMATES/teammates

@Override
  public String load(String courseId) {
    List<Instructor> instructors =
        ofy().load().type(Instructor.class).filter("courseId =", courseId).list();
    for (Instructor instructor : instructors) {
      if (StringHelper.isEmpty(instructor.getGoogleId())) {
        continue;
      }
      Account account = ofy().load().key(Key.create(Account.class, instructor.getGoogleId())).now();
      if (account != null && !StringHelper.isEmpty(account.getInstitute())) {
        return account.getInstitute();
      }
    }
    return UNKNOWN_INSTITUTE;
  }
});

相关文章