/** * A shortcut for {@code factory().register()} * * @see ObjectifyFactory#register(Class) */ public static void register(Class<?> clazz) { factory().register(clazz); }
/** * <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(); } }
/** * 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(); }
/** * The method to call at any time to get the current Objectify, which may change depending on txn context */ public static Objectify ofy() { return factory().ofy(); }
/** Create a key from a registered POJO entity. */ public static <T> Key<T> create(final T pojo) { return ObjectifyService.factory().keys().keyOf(pojo); }
/** Obtain it from the global ObjectifyFactory */ private KeyFactory newKeyFactory() { return ObjectifyService.factory().datastore().newKeyFactory(); }
public static ObjectifyFactory factory() { return ObjectifyService.factory(); } }
/** * Easy access to the factory object. This is convenient shorthand for * {@code ObjectifyService.factory()}. */ public ObjectifyFactory fact() { return ObjectifyService.factory(); }
public static ObjectifyFactory factory() { return ObjectifyService.factory(); } }
/** * 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; } }
/** * If you aren't using ObjectifyService, you can extend the servlet and override this method. */ protected EntityMemcacheStats getMemcacheStats() { return ObjectifyService.factory().getMemcacheStats(); }
/** @see ObjectifyFactory#begin(ObjectifyOpts) */ public static Objectify begin(ObjectifyOpts opts) { return factory().begin(opts); }
/** @see ObjectifyFactory#register(Class) */ public static void register(Class<?> clazz) { factory().register(clazz); } }
/** @see ObjectifyFactory#begin() */ public static Objectify begin() { return factory().begin(); }
/** @see ObjectifyFactory#beginTransaction() */ public static Objectify beginTransaction() { return factory().beginTransaction(); }
protected Field idField(Class<E> entityType) { try { String idFieldName = ObjectifyService.factory().getMetadata(entityType).getKeyMetadata().getIdFieldName(); return FieldUtils.getField(entityType, idFieldName, true); } catch (IllegalArgumentException | SecurityException e) { throw new RepositoryException(e, "Unable to determine id field for type %s: %s", entityType.getClass().getName(), e.getMessage()); } }
@Override public void initialise(UpdatableInjectionContext injectionContext) { ObjectifyFactory objectifyFactory = ObjectifyService.factory(); runBasicConfiguration(objectifyFactory); injectionContext.inject(objectifyFactory).as(ObjectifyFactory.class); }
public static void runBasicConfiguration(ObjectifyFactory objectifyFactory) { // register Objectify converter to convert between java.uil.Date and org.joda.time.DateTime JodaTimeTranslators.add(objectifyFactory); ObjectifyService.factory().getTranslators().add(new UUIDTranslatorFactory()); }
@Before public void setUp() throws Exception { // Don't call super.setUp because we initialize slightly differently // here... countdownLatch = new LocalTaskQueueTestConfig.TaskCountDownLatch(1); // See // http://www.ensor.cc/2010/11/unit-testing-named-queues-spring.html // NOTE: THE QUEUE XML PATH RELATIVE TO WEB APP ROOT, More info // below // http://stackoverflow.com/questions/11197058/testing-non-default-app-engine-task-queues final LocalTaskQueueTestConfig localTaskQueueConfig = new LocalTaskQueueTestConfig() .setDisableAutoTaskExecution(false).setQueueXmlPath("src/test/resources/queue.xml") .setTaskExecutionLatch(countdownLatch).setCallbackClass(DeleteShardedCounterDeferredCallback.class); // Use a different queue.xml for testing purposes helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig().setApplyAllHighRepJobPolicy(), new LocalMemcacheServiceTestConfig(), new LocalCapabilitiesServiceTestConfig(), localTaskQueueConfig); helper.setUp(); memcache = MemcacheServiceFactory.getMemcacheService(); capabilitiesService = CapabilitiesServiceFactory.getCapabilitiesService(); // New Objectify 5.1 Way. See https://groups.google.com/forum/#!topic/objectify-appengine/O4FHC_i7EGk this.session = ObjectifyService.begin(); // Enable Joda Translators JodaTimeTranslators.add(ObjectifyService.factory()); ObjectifyService.factory().register(CounterData.class); ObjectifyService.factory().register(CounterShardData.class); ObjectifyService.factory().register(CounterShardOperationData.class); shardedCounterServiceImpl = new ShardedCounterServiceImpl(); this.shardedCounterService = shardedCounterServiceImpl; }