/** * 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(); }
/** Null-safe extraction of the raw key */ public static com.google.cloud.datastore.Key raw(final Key<?> key) { return key == null ? null : key.getRaw(); }
@Override protected Value<com.google.cloud.datastore.Key> toDatastore(final Key<?> value) { return KeyValue.of(value.getRaw()); } }
/** * Callback that we found a Ref in the object graph. Subclasses of this context may want to do something * special with this. */ public Key saveRef(final Ref<?> value, final LoadConditions loadConditions) { return value.key().getRaw(); } }
@Override public Result<Void> keys(final Iterable<? extends Key<?>> keys) { final List<com.google.cloud.datastore.Key> rawKeys = new ArrayList<>(); for (final Key<?> key: keys) rawKeys.add(key.getRaw()); return ofy.createWriteEngine().delete(rawKeys); }
/** * <p>Gets the raw datstore Key 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 */ public com.google.cloud.datastore.Key anythingToRawKey(final Object keyOrEntity) { if (keyOrEntity instanceof com.google.cloud.datastore.Key) return (com.google.cloud.datastore.Key)keyOrEntity; else if (keyOrEntity instanceof Key<?>) return ((Key<?>)keyOrEntity).getRaw(); else if (keyOrEntity instanceof Ref) return ((Ref<?>)keyOrEntity).key().getRaw(); else if (keyOrEntity instanceof FullEntity<?>) return getKey((FullEntity<?>)keyOrEntity); else return rawKeyOf(keyOrEntity); }
/** * Preallocate a contiguous range of unique ids within the namespace of the * specified entity class and the parent key. These ids can be used in concert with the normal * automatic allocation of ids when put()ing entities with null Long id fields. * * @param parentKeyOrEntity must be a legitimate parent for the class type. It need not * point to an existent entity, but it must be the correct type for clazz. * @param clazz must be a registered entity class with a Long or long id field, and * a parent key of the correct type. * @param num must be >= 1 and <= 1 billion */ public <T> KeyRange<T> allocateIds(final Object parentKeyOrEntity, final Class<T> clazz, final int num) { final Key<?> parent = keys().anythingToKey(parentKeyOrEntity); final String kind = Key.getKind(clazz); final IncompleteKey incompleteKey = com.google.cloud.datastore.Key.newBuilder(parent.getRaw(), kind).build(); return allocate(incompleteKey, num); }
@Override public Object forDatastore(Object value, ConverterSaveContext ctx) { if (value instanceof Key<?>) return ((Key<?>)value).getRaw(); else return null; }
/** * Easy null-safe conversion of the typed key. */ public static com.google.appengine.api.datastore.Key raw(Key<?> typed) { if (typed == null) return null; else return typed.getRaw(); }
log.trace("Adding to round (session miss): {}", key); this.pending.add(key.getRaw());
/** @return the raw key even if the field is an Key */ private com.google.appengine.api.datastore.Key getRawKey(Field keyField, Object obj) throws IllegalAccessException { Object key = keyField.get(obj); if (key == null) return null; else if (key instanceof com.google.appengine.api.datastore.Key) return (com.google.appengine.api.datastore.Key)key; else return ((Key<?>)key).getRaw(); }
@Override public void serialize( Key value, JsonGenerator jgen, SerializerProvider provider ) throws IOException { jgen.writeStartObject(); jgen.writeObjectField( KeyConstant.RAW, value.getRaw() ); jgen.writeEndObject(); } }
/** * Assembles the Key for this entity. If an Entity has a Parent Key, that key will be included in the returned Key * heirarchy. */ public com.google.appengine.api.datastore.Key getKey() { return this.getTypedKey().getRaw(); }
/** * Assembles the Key for this entity. If an Entity has a Parent Key, that key will be included in the returned Key * heirarchy. */ public com.google.appengine.api.datastore.Key getKey() { return this.getTypedKey().getRaw(); }
/** * Assembles the Key for this entity. If an Entity has a Parent Key, that key will be included in the returned Key * heirarchy. */ public com.google.appengine.api.datastore.Key getKey() { return this.getTypedKey().getRaw(); }
/** * <p>Converts a Key<?> into a web-safe string suitable for http parameters * in URLs. Note that you can convert back and forth with the {@code keyToString()} * and {@code stringToKey()} methods.</p> * * <p>The String is actually generated by using the KeyFactory {@code keyToString()} * method on a raw version of the datastore key. You can, if you wanted, use * these web safe strings interchangeably.</p> * * @param key is any Objectify key * @return a simple String which does not need urlencoding */ public String keyToString(Key<?> key) { return KeyFactory.keyToString(key.getRaw()); }
public static Key columnKey(ResourceId formId, String columnId) { Key formKey = FormEntity.key(formId).getRaw(); return KeyFactory.createKey(formKey, COLUMN_KIND, columnId); }
public static com.google.appengine.api.datastore.Key key(Key<FormEntity> formKey, String fieldId, int blockIndex) { com.google.appengine.api.datastore.Key fieldKey = KeyFactory.createKey(formKey.getRaw(),"FormField", fieldId); return KeyFactory.createKey(fieldKey, "Block", blockIndex); }
@Override protected void doSerialize( JsonWriter writer, Key<T> key, JsonSerializationContext ctx, JsonSerializerParameters params ) { writer.beginObject(); writer.name( KeyConstant.RAW ); RawKeyJsonSerializer.getInstance().serialize( writer, key.getRaw(), ctx, params ); writer.endObject(); } }