/** * You can extend the servlet and override this method if you are doing something unusual with the factory. */ protected EntityMemcacheStats getMemcacheStats() { return ObjectifyService.factory().getMemcacheStats(); }
/** * Like now(), but throws NotFoundException instead of returning null. * @throws NotFoundException if the loaded value was not found */ public final T safe() throws NotFoundException { T t = now(); if (t == null) throw new NotFoundException(key); else return t; } }
@Override public T apply(Result<T> input) { return input.now(); } }
@Override public Key<?> fromString(String str) { return Key.create(str); } }
/** * <p>An alternative to run() which is somewhat easier to use with testing (ie, @Before and @After) frameworks. * You must close the return value at the end of the request in a finally block. It's better/safer to use run().</p> * * <p>This method is not typically necessary - in a normal request, the ObjectifyFilter takes care of this housekeeping * for you. However, in unit tests or remote API calls it can be useful.</p> */ public static Closeable begin() { return factory().open(); } }
/** * Obtain the entity value, throwing an exception if the entity was not found. * * @return the entity referenced. Never returns null. * @throws NotFoundException if the specified entity was not found */ final public T safe() throws NotFoundException { T t = this.get(); if (t == null) throw new NotFoundException(key()); else return t; }
/** * Easy null-safe conversion of the typed key. */ public static com.google.cloud.datastore.Key key(final Key<?> typed) { if (typed == null) return null; else return typed.getRaw(); }
/** This is a shortcut for {@code ObjectifyService.init(new ObjectifyFactory())}*/ public static void init() { init(new ObjectifyFactory()); }
/** Type safe comparison for key equivalence */ public boolean equivalent(Key<T> other) { return key().equivalent(other); }
/** * This method exists to facilitate serialization via javabeans conventions. Unlike get(), * it will return null if isLoaded() is false. * * @return the entity referenced, or null if either the entity was not found or isLoaded() is false. */ final public T getValue() { return isLoaded() ? get() : null; }
/** * Same as key() but conforms to JavaBeans conventions in case this is being processed by a JSON * converter or expression language. */ final public Key<T> getKey() { return key(); }
/** * 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); }