objectify

Create-or-Err with Objectify

自古美人都是妖i 提交于 2019-12-19 11:17:28
问题 I'm getting started with Google App Engine, and I'm using Objectify. How do I create a root entity in the data store, but err if it already exists? I didn't find anything built in for this (e.g. DatastoreService.put() and therefore ofy().save() will overwrite an existing entity instead of err). The simple technique I am used to is to do this in a transaction: Err if already exists Save However, that is not idempotent; it would err in step 1 if the transaction executes twice. Here is the best

Objectify and TimerTask: No API environment is registered for this thread

不羁的心 提交于 2019-12-19 08:06:09
问题 I'm trying to get a TimerTask set up to remove entries from Google App Engine's dataStore periodically. So I set up a ServletContextListener with a Timer . Inside the contextInitialized , I have registered my Objectify classes: ObjectifyService.register(Person.class); However, when the task actually runs, it complains that no API environment has been set up: Exception in thread "Timer-0" java.lang.NullPointerException: No API environment is registered for this thread. at com.google.appengine

Objectify and TimerTask: No API environment is registered for this thread

与世无争的帅哥 提交于 2019-12-19 08:05:09
问题 I'm trying to get a TimerTask set up to remove entries from Google App Engine's dataStore periodically. So I set up a ServletContextListener with a Timer . Inside the contextInitialized , I have registered my Objectify classes: ObjectifyService.register(Person.class); However, when the task actually runs, it complains that no API environment has been set up: Exception in thread "Timer-0" java.lang.NullPointerException: No API environment is registered for this thread. at com.google.appengine

Can a two Entities of the same Kind have the same ID if the parent is different?

天大地大妈咪最大 提交于 2019-12-14 04:09:04
问题 I know that datastore will auto generate a unique ID for root Entities. But what about Entities of the same Kind that have different Parents? Will datastore auto generate unique IDs for Entities for the same Kind with different parents (of same Kind)? e.g. User->Post . Could two different Users conceivably each have a Post with the same ID? 回答1: I wrote a JUnit test for you. It uses lombok, but you can write out the getters and setters as well. import com.google.appengine.tools.development

How to use ObjectifyService in Junit Testing

爷,独闯天下 提交于 2019-12-13 19:22:51
问题 If you want to use datastore service to perform a junit test, this is what you do LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalMemcacheServiceTestConfig(),new LocalDatastoreServiceTestConfig()); @Before public void setUp() { helper.setUp(); } @After public void tearDown() { helper.tearDown(); } @Test public void testInsert1() { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10)));

efficient searching using appengine datastore ancestor paths

爷,独闯天下 提交于 2019-12-13 15:00:42
问题 We have a mulch-tenancy and I need to search and fetch in a huge appengine datastore based on an indexed attribute range and client id. Does usage of Ancestor Paths make it efficient ? Alternatively Same can be done using an additional filter e.g. to get the top 100 salaries via objectify Key<Clients> clientIdKey = Key.create(Clients.class, 500) ofy().load().type(Salaries.class).ancestor(clientIdKey).order("-salary").limit(100).list() Alternatively just ofy().load().type(Salaries.class)

How to set default commit for transactions in google app engine?

半腔热情 提交于 2019-12-13 05:44:37
问题 ObjectifyBookShelfDAO transactionalDao = new ObjectifyBookShelfDAO(true); transactionDao.removeThis(item); // Its get removed only after i commit // Perform some operations transactionDao.ofy().getTxn().commit(); There is a scenario where in i want this object to be removed on instant... How do i do this .. 回答1: it looks like you're using objectify-appengine. as the objectify transaction docs describe, if you make your call to removeThis() outside of a transaction, it will happen immediately.

Entity hierarchies in Objectify 4.0

心已入冬 提交于 2019-12-13 05:37:03
问题 Is there a way how to define an entity hierarchy that enables to query just particular subclass? Consider situation below. Let's have abstract Base class that defines common properties and concrete subclasses A and B. class abstract Base { ... } class A extends Base { ... } class B extends Base { ... } I would like to run for example queries as follows. To retrieve all entities of type A and B Base base = this.objectify.load().type(Base.class).list(); To retrieve all entities of type A Base

“projectId must match the following pattern” exception when running Objectify on Google Cloud tools for Eclipse

女生的网名这么多〃 提交于 2019-12-13 05:27:33
问题 I am trying to run a very simple hello world application on Google Cloud with objectify but get an exception when trying to access the datastore for saving an entity. I am using the latest Google Cloud Tools (1.6.1) for eclipse (Oxygen 4.7.3a) and Java 8. Following the official Google quick star guide I was able to create a standard java project and run the hello word sample app on my local server from eclipse. Since the plugin let you add Objectify libraries to the project I decided to give

App Engine DataStore - Compound Indexes - datastore-indexes - not working

爷,独闯天下 提交于 2019-12-13 04:47:53
问题 I am unable to search entities using compound indexes. I am using Objectify 4. Entity configuration: @Entity @Unindex class MyEntity implements Serialiable { @Id String id; String one; String two; long three; } Index configuration: <datastore-indexes autoGenerate="true"> <datastore-index kind="MyEntity" ancestor="false"> <property name="one" direction="asc" /> <property name="two" direction="desc" /> </datastore-index> </datastore-indexes> I see the indexes built in DataStore Indexes .