/** * A shortcut for {@code factory().register()} * * @see ObjectifyFactory#register(Class) */ public static void register(Class<?> clazz) { factory().register(clazz); }
/** This is a shortcut for {@code ObjectifyService.init(new ObjectifyFactory())}*/ public static void init() { init(new ObjectifyFactory()); }
/** * Named differently so you don't accidentally use the Object form * @return the metadata for a kind of typed object. * @throws IllegalArgumentException if the kind has not been registered */ @SuppressWarnings("unchecked") public <T> EntityMetadata<T> getMetadataForEntity(final T obj) throws IllegalArgumentException { // Type erasure sucks return (EntityMetadata<T>)this.getMetadata(obj.getClass()); }
closeable = ObjectifyService.begin(); final ObjectifyFactory factory = ObjectifyService.factory(); factory.getTranslators().add(new RefSupplierTranslatorFactory()); factory.register(CarWithSupplier.class); factory.register(SteeringWheel.class); factory.register(Tire.class);
public void afterPropertiesSet() throws Exception { if (this.logger.isInfoEnabled()) { this.logger.info("Initialization started"); } long startTime = System.currentTimeMillis(); if (classes == null) { classes = new ArrayList<Class<?>>(); } if (basePackage != null && basePackage.length() > 0) { classes.addAll(doScan()); } this.objectifyFactory = new ObjectifyFactory(); for (Class<?> clazz : classes) { this.objectifyFactory.register(clazz); if (this.logger.isInfoEnabled()) { this.logger.info("Registered entity class [" + clazz.getName() + "]"); } } if (this.logger.isInfoEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; this.logger.info("Initialization completed in " + elapsedTime + " ms"); } }
public void testBoolQuery() { ObjectifyFactory objectifyFactory = ObjectifyService.factory(); objectifyFactory.register(FakeEntity.class); Objectify objectify = objectifyFactory.begin(); FakeEntity entityFalse = new FakeEntity(); FakeEntity entityTrue = new FakeEntity(); entityTrue.boolProp = true; objectifyFactory.begin().put(entityFalse); objectifyFactory.begin().put(entityTrue);
/** * Get the relevant translator, creating it if necessary. */ public <P, D> Translator<P, D> getTranslator(final TypeKey<P> tk, final CreateContext ctx, final Path path) { return factory.getTranslators().get(tk, ctx, path); }
final Translator<Object, ?> componentTranslator = fact.getTranslators().get(new TypeKey(componentType, tk), ctx, path); final Mapper<Object, Object> mapper = (Mapper<Object, Object>)fact.construct(mapify.value());
return KeyValue.of(factory().keys().rawKeyOf(value)); } else { final Translator<Object, Value<?>> translator = factory().getTranslators().get(new TypeKey<>(value.getClass()), new CreateContext(factory()), Path.root());
entityList.add((FullEntity<?>)obj); } else { final EntityMetadata<E> metadata = factory().getMetadataForEntity(obj); final FullEntity<?> translated = metadata.save(obj, ctx); entityList.add(translated);
/** * Create a lightweight Objectify instance with the default options. * Equivalent to begin(new ObjectifyOpts()). */ public Objectify begin() { return this.begin(this.createDefaultOpts()); }
EntityMetadata<?> meta = this.factory.getMetadata(this.classRestriction); if (meta.isIdField(prop) || meta.isNameField(prop)) value = this.factory.makeFilterable(value);
/** * Allocates a single id from the allocator for the specified kind. Safe to use in concert * with the automatic generator. This is just a convenience method for allocateIds(). * * @param clazz must be a registered entity class with a Long or long id field. * @return a key with an id that is unique to the kind */ public <T> Key<T> allocateId(final Class<T> clazz) { return allocateIds(clazz, 1).iterator().next(); }
/** * Easy access to the objectify object (which is lazily created). */ public Objectify ofy() { if (this.lazyOfy == null) this.lazyOfy = ObjectifyService.factory().begin(this.opts); return this.lazyOfy; } }
/** * 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(); }
/** * @param clazz must have @Entity in its hierarchy */ public EntityMetadata(final ObjectifyFactory fact, final Class<P> clazz) { assert clazz.isAnnotationPresent(com.googlecode.objectify.annotation.Entity.class); this.entityClass = clazz; this.cached = clazz.getAnnotation(Cache.class); this.translator = (ClassTranslator<P>)fact.getTranslators().getRoot(clazz); this.keyMetadata = translator.getKeyMetadata(); }
final Stringifier<Object> stringifier = (Stringifier<Object>)fact.construct(stringifierClass); if (stringifier instanceof InitializeStringifier) ((InitializeStringifier)stringifier).init(fact, keyType); final Translator<Object, ?> componentTranslator = fact.getTranslators().get(new TypeKey<>(componentType, tk), ctx, path);
loadEngine.ofy.factory().getMetadataForEntity(thing).save(thing, saveCtx);
/** * @return an Objectify which uses a transaction. The transaction supports cross-group access, but * this has no extra overhead for a single-entity-group transaction. */ public Objectify beginTransaction() { return this.begin(this.createDefaultOpts().setBeginTransaction(true)); }
/** * Allocates a single id from the allocator for the specified kind. Safe to use in concert * with the automatic generator. This is just a convenience method for allocateIds(). * * Note that the id is only unique within the parent, not across the entire kind. * * @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. * @return a key with a new id unique to the kind and parent */ public <T> Key<T> allocateId(final Object parentKeyOrEntity, final Class<T> clazz) { return allocateIds(parentKeyOrEntity, clazz, 1).iterator().next(); }