@Override public Key<?> fromString(String str) { return Key.create(str); } }
/** 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); }
/** */ @Override public Key deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String text = jp.getText(); return Key.create(text); } }
/** */ @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)); } }
/** 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); }
@Override protected Void wrap(final Void orig) { for (com.google.cloud.datastore.Key key: keys) session.addValue(Key.create(key), null); return orig; } };
@Override public Key<T> next() { final com.google.cloud.datastore.Key key = source.next(); return Key.create(key); }
/** * @return the Key<?> for a registered pojo entity. */ public <T> Key<T> keyOf(final T pojo) { return Key.create(rawKeyOf(pojo)); }
@Override protected Key<?> toPojo(final Value<com.google.cloud.datastore.Key> value) { return Key.create(value.get()); }
/** * <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); }
@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); }
/** */ @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; }
/** * @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); }
/** * @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); }
/** * 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); } }
/** * 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); }
/** * 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); } }
/** * 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; } }
@Override protected Query<Account> getFilterQuery() { return ofy().load().type(Account.class).filterKey(Key.create(Account.class, fromAccountGoogleId)); }
@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; } });