@Override public <E> LoadType<E> type(final Class<E> type) { return new LoadTypeImpl<>(this, Key.getKind(type), type); }
/** * @return the metadata for the specified class, or null if there was nothing appropriate registered */ @SuppressWarnings("unchecked") public <T> EntityMetadata<T> getMetadata(Class<T> clazz) { return getMetadata(Key.getKind(clazz)); }
/** * @return the metadata for a kind of entity based on its key * @throws IllegalArgumentException if the kind has not been registered */ public <T> EntityMetadata<T> getMetadata(final Key<T> key) throws IllegalArgumentException { return this.registrar.getMetadataSafe(key.getKind()); }
/** */ public KeyMetadata(final Class<P> clazz, final CreateContext ctx, final Path path) { this.factory = ctx.getFactory(); this.clazz = clazz; findKeyFields(clazz, ctx, path); // There must be some field marked with @Id if (this.idMeta == null) throw new IllegalStateException("There must be an @Id field (String, Long, or long) for " + clazz.getName()); this.kind = Key.getKind(clazz); }
/** * @return the metadata for a registered pojo, or null if there is none */ @SuppressWarnings("unchecked") public <T> KeyMetadata<T> getMetadata(final Key<T> key) { final EntityMetadata<T> em = registrar.getMetadata(key.getKind()); return em == null ? null : em.getKeyMetadata(); }
/** * @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); }
String kind = Key.getKind(clazz);
/** * <p>Preallocate multiple unique ids within the namespace of the * specified entity class. These ids can be used in concert with the normal * automatic allocation of ids when save()ing entities with null Long id fields.</p> * * <p>The {@code KeyRange<?>} class is deprecated; when using this method, * treat the return value as {@code List<Key<T>>}.</p> * * @param clazz must be a registered entity class with a Long or long id field. * @param num must be >= 1 and small enough we can fit a set of keys in RAM. */ public <T> KeyRange<T> allocateIds(final Class<T> clazz, final int num) { final String kind = Key.getKind(clazz); final IncompleteKey incompleteKey = datastore().newKeyFactory().setKind(kind).newKey(); return allocate(incompleteKey, num); }
/** Create a key with a parent and a long id */ private Key(final Key<?> parent, final Class<? extends T> kindClass, final long id) { final String kind = getKind(kindClass); if (parent == null) { this.raw = newKeyFactory().setKind(kind).newKey(id); } else { this.raw = com.google.cloud.datastore.Key.newBuilder(key(parent), kind, id).build(); } this.parent = parent; }
/** Create a key with a parent and a String name */ private Key(final Key<?> parent, final Class<? extends T> kindClass, final String name) { final String kind = getKind(kindClass); if (parent == null) { this.raw = newKeyFactory().setKind(kind).newKey(name); } else { this.raw = com.google.cloud.datastore.Key.newBuilder(key(parent), kind, name).build(); } this.parent = parent; }
/** * 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); }
entityType = keyOfEntityToMigrate.getKind();
/** * @return the metadata for a kind of entity based on its key * @throws IllegalArgumentException if the kind has not been registered */ public <T> EntityMetadata<T> getMetadata(Key<T> key) { return this.getMetadata(key.getKind()); }
/** Create a key with a parent and a String name */ public Key(Key<?> parent, Class<? extends T> kindClass, String name) { this.raw = KeyFactory.createKey(raw(parent), getKind(kindClass), name); this.parent = parent; }
/** Create a key with a parent and a long id */ public Key(Key<?> parent, Class<? extends T> kindClass, long id) { this.raw = KeyFactory.createKey(raw(parent), getKind(kindClass), id); this.parent = parent; }
/** */ public QueryImpl(ObjectifyFactory fact, Objectify objectify, Class<T> clazz) { this.factory = fact; this.ofy = objectify; this.actual = new com.google.appengine.api.datastore.Query(Key.getKind(clazz)); // If this is a polymorphic subclass, add an extra filter Subclass sub = clazz.getAnnotation(Subclass.class); if (sub != null) { String discriminator = sub.name().length() > 0 ? sub.name() : clazz.getSimpleName(); this.actual.addFilter(PolymorphicEntityMetadata.DISCRIMINATOR_INDEX_PROPERTY, FilterOperator.EQUAL, discriminator); } this.classRestriction = clazz; }
/** * Inspects and stores the metadata for a particular entity class. * @param clazz must be a properly-annotated Objectify entity class. */ public ConcreteEntityMetadata(Conversions conversions, Class<T> clazz) { this.entityClass = clazz; this.entityClassConstructor = TypeUtils.getNoArgConstructor(clazz); this.kind = Key.getKind(clazz); this.cached = clazz.getAnnotation(Cached.class); // Recursively walk up the inheritance chain looking for @Id and @Parent fields this.processKeyFields(clazz); // Walk up the inheritance chain looking for @PrePersist and @PostLoad this.processLifecycleCallbacks(clazz); // Now figure out how to handle normal properties this.transmog = new Transmog<T>(conversions, clazz); // There must be some field marked with @Id if ((this.idField == null) && (this.nameField == null)) throw new IllegalStateException("There must be an @Id field (String, Long, or long) for " + this.entityClass.getName()); }
/** * Preallocate a contiguous range of unique ids within the namespace of the * specified entity class. These ids can be used in concert with the normal * automatic allocation of ids when put()ing entities with null Long id fields. * * @param clazz must be a registered entity class with a Long or long id field. * @param num must be >= 1 and <= 1 billion */ public <T> KeyRange<T> allocateIds(Class<T> clazz, long num) { // Feels a little weird going directly to the DatastoreServiceFactory but the // allocateIds() method really is optionless. String kind = Key.getKind(clazz); return new KeyRange<T>(DatastoreServiceFactory.getDatastoreService().allocateIds(kind, num)); }
/** * 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(Object parentKeyOrEntity, Class<T> clazz, long num) { Key<?> parent = this.getKey(parentKeyOrEntity); String kind = Key.getKind(clazz); // Feels a little weird going directly to the DatastoreServiceFactory but the // allocateIds() method really is optionless. return new KeyRange<T>(DatastoreServiceFactory.getDatastoreService().allocateIds(parent.getRaw(), kind, num)); }