objectify

How to resolve “You have not started an Objectify context” in JUnit?

六月ゝ 毕业季﹏ 提交于 2019-12-01 15:09:26
问题 I've got some Objectify test code running in JUnit and I'm getting this error: java.lang.IllegalStateException: You have not started an Objectify context. You are probably missing the ObjectifyFilter. If you are not running in the context of an http request, see the ObjectifyService.run() method. at com.googlecode.objectify.ObjectifyService.ofy(ObjectifyService.java:44) at com.googlecode.objectify.impl.ref.LiveRef.<init>(LiveRef.java:31) at com.googlecode.objectify.Ref.create(Ref.java:26) at

Objectify with Endpoints for android

二次信任 提交于 2019-12-01 12:53:48
I read that Objectify is a supported framework for use with Endpoints. How do I convert the sample from the GPE App Engine Connected Android Project wizard to deal with Objectify 4 data? I'm getting this: org.datanucleus.exceptions.ClassNotPersistableException: The class "com.example.MyObjectifyTestInfo" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. I have searched a lot, but found nothing in stackoverflow or

Create-or-Err with Objectify

ⅰ亾dé卋堺 提交于 2019-12-01 12:48:15
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 I've come up with so far, not in a transaction: Err if already exists Save Fetch Err if it's not the

Objectify with Endpoints for android

心不动则不痛 提交于 2019-12-01 11:39:00
问题 I read that Objectify is a supported framework for use with Endpoints. How do I convert the sample from the GPE App Engine Connected Android Project wizard to deal with Objectify 4 data? I'm getting this: org.datanucleus.exceptions.ClassNotPersistableException: The class "com.example.MyObjectifyTestInfo" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data

Objectify error “You cannot create a Key for an object with a null @Id” in JUnit

坚强是说给别人听的谎言 提交于 2019-12-01 10:35:19
问题 I got the following error while testing a simple piece of code in JUnit that creates a User object (an Objectify Entity) and then tries to attach it as a Parent to another Objectify Entity called DownloadTask : java.lang.IllegalArgumentException: You cannot create a Key for an object with a null @Id. Object was com.netbase.followerdownloader.model.User@57fcbecc at com.googlecode.objectify.impl.KeyMetadata.getRawKey(KeyMetadata.java:185) at com.googlecode.objectify.impl.Keys.rawKeyOf(Keys.java

GAE datastore query with filter and sort using objectify

走远了吗. 提交于 2019-12-01 09:29:11
问题 I am trying to query the datastore for the top 100 users in terms of points scored, who have logged on in the past week (the date field). List<User> users = ofy().load().type(User.class) .filter("date >", date).order("date") .order("-points").limit(100).list(); It seems to ignore the final ordering by points and returns the list sorted by date instead. If I remove the date filter and sort then I get list nicely sorted by points, but including users who have logged on more than a week ago. I

Objectify queries: filter by date

流过昼夜 提交于 2019-12-01 08:45:08
I am using GAE and I need to write an Objectify query that asks for the elements created after September 1st. The dateCreated field is Java.util.Date and it is stored in this format 2012-11-29 16:03:59.494000. This request is NOT working: public List<MyElement> listAllFromUser(String userId) { Objectify ofy = ObjectifyService.begin(); Query<MyElement> q=ofy.query(MyElement.class).filter("dateCreated >", "2013-09-01 00:00:00"); List<MyElement> results = q.list(); return results; } Your column needs to be indexed @Indexed protected Date dateCreated; You can sort only by one column in a request (

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

て烟熏妆下的殇ゞ 提交于 2019-12-01 05:44:19
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.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:80) at com.google.appengine

Get an Objectify Entity's Key

 ̄綄美尐妖づ 提交于 2019-12-01 04:07:54
Dummy question. I create my POJO Objectify entity (for example, "Category") and persist it. Then I retrieve it via a query. I want to use it in a one-to-may relationship e.g. want to set my category to one or more "Products". I will have this in my "Product"'s code: Key<Categoria> categoria; So the question is: how can I find my retrieved entity's key for setting it in my product? I'm usually adding an extra method: @Transient Key<Categoria> getKey() { return Key.create(Categoria.class, id); } and use it where it needed: anCategoria.getKey() For objectify 4 use: public Key<Foo> getKey() {

Is it possible to have a computed property on Google App Engine using Java?

谁都会走 提交于 2019-12-01 01:49:53
I have an app engine application and I want to run a query that sorts the result based on a expression involving two properties. Best way I thought of doing it so far is to create a computed/calculated property that stores the result of that expression. Although I saw that GAE in Python offers a ComputedProperty, which seems to be exactly what I'm looking for, I couldn't find an equivalent in Java. I'm currently using Objectify too, if that helps. Any ideas? Compute your value in an @OnSave method: @Entity public class YourEntity { @Id Long id; String foo; String bar; @Index String computed;