/** Key.create(Blah.class, name) is easier to type than new Key<Blah>(Blah.class, name) */ public static <T> Key<T> create(final Class<? extends T> kindClass, final String name) { return new Key<>(kindClass, name); }
/** Key.create(parent, Blah.class, id) is easier to type than new Key<Blah>(parent, Blah.class, id) */ public static <T> Key<T> create(final Key<?> parent, final Class<? extends T> kindClass, final long id) { return new Key<>(parent, kindClass, id); }
/** * Easy null-safe conversion of the raw key. */ public static <V> Key<V> key(final com.google.cloud.datastore.Key raw) { if (raw == null) return null; else return new Key<>(raw); }
/** Key.create(Blah.class, id) is easier to type than new Key<Blah>(Blah.class, id) */ public static <T> Key<T> create(final Class<? extends T> kindClass, final long id) { return new Key<>(kindClass, id); }
/** Key.create(parent, Blah.class, name) is easier to type than new Key<Blah>(parent, Blah.class, name) */ public static <T> Key<T> create(final Key<?> parent, final Class<? extends T> kindClass, final String name) { return new Key<>(parent, kindClass, name); }
/** Key.create(key) is easier to type than new Key<Blah>(key) */ public static <T> Key<T> create(final com.google.cloud.datastore.Key raw) { if (raw == null) throw new NullPointerException("Cannot create a Key<?> from a null datastore Key"); return new Key<>(raw); }
/** Key.create(urlSafeString) is easier to type than new Key<Blah>(urlSafeString) */ public static <T> Key<T> create(final String urlSafeString) { if (urlSafeString == null) throw new NullPointerException("Cannot create a Key<?> from a null String"); return new Key<>(urlSafeString); }
/** * @return the parent key, or null if there is no parent. Note that * the parent could potentially have any type. */ @SuppressWarnings("unchecked") public <V> Key<V> getParent() { if (this.parent == null && this.raw.getParent() != null) this.parent = new Key<V>(this.raw.getParent()); return (Key<V>)this.parent; }
@Override protected Key<T> translate(com.google.appengine.api.datastore.Key from) { return new Key<T>(from); } };
/** * Easy null-safe conversion of the raw key. */ public static <V> Key<V> typed(com.google.appengine.api.datastore.Key raw) { if (raw == null) return null; else return new Key<V>(raw); }
/** Key.create(Blah.class, id) is easier to type than new Key<Blah>(Blah.class, id) */ public static <T> Key<T> create(Class<? extends T> kindClass, long id) { return new Key<T>(kindClass, id); }
/** Key.create(parent, Blah.class, name) is easier to type than new Key<Blah>(parent, Blah.class, name) */ public static <T> Key<T> create(Key<?> parent, Class<? extends T> kindClass, String name) { return new Key<T>(parent, kindClass, name); }
/** Key.create(parent, Blah.class, id) is easier to type than new Key<Blah>(parent, Blah.class, id) */ public static <T> Key<T> create(Key<?> parent, Class<? extends T> kindClass, long id) { return new Key<T>(parent, kindClass, id); }
/** Key.create(Blah.class, name) is easier to type than new Key<Blah>(Blah.class, name) */ public static <T> Key<T> create(Class<? extends T> kindClass, String name) { return new Key<T>(kindClass, name); }
@Override public Object forPojo(Object value, Class<?> fieldType, ConverterLoadContext ctx, Object onPojo) { if (Key.class.isAssignableFrom(fieldType) && value instanceof com.google.appengine.api.datastore.Key) return new Key<Object>((com.google.appengine.api.datastore.Key)value); else return null; } }
@Override public <T> Result<T> find(Class<? extends T> clazz, long id) { return this.find(new Key<T>(clazz, id)); }
/** * Converts a String generated with {@code keyToString()} back into an Objectify * Key. The String could also have been generated by the GAE {@code KeyFactory}. * * @param stringifiedKey is generated by either {@code ObjectifyFactory.keyToString()} or * {@code KeyFactory.keyToString()}. * @return a Key<?> */ public <T> Key<T> stringToKey(String stringifiedKey) { return new Key<T>(KeyFactory.stringToKey(stringifiedKey)); }
@Override public <T> Result<Void> delete(Class<T> clazz, long id) { return this.delete(new Key<T>(clazz, id)); }
@Override public <T> Result<Void> delete(Class<T> clazz, String name) { return this.delete(new Key<T>(clazz, name)); }
/** * @return the parent key, or null if there is no parent. Note that * the parent could potentially have any type. */ @SuppressWarnings("unchecked") public <V> Key<V> getParent() { if (this.parent == null && this.raw.getParent() != null) this.parent = new Key<V>(this.raw.getParent()); return (Key<V>)this.parent; }