Java Reference
In-Depth Information
Type
Java Class
Notes
a user-
provided
rating, an
integer
between 0
to 100
com.google.appengine.api.datastore.Rating
A user-provided
integer rating for a
piece of content.
Normalized to a 0-
100 scale.
CRUDing Entities
With most datastores, obtaining a connection is an expensive process. The App
Engine's datastore is no different. Applications utilizing JDO interact with the
datastore by using an instance of the PersistenceManager class. By instantiating an
instance of the PersistenceManagerFactory class, the factory creates an instance of
the PersistenceManager using the JDO configuration. Due to the high overhead of
creating the instance, you should wrap this class in a singleton so that it can be
reused and prevented from creating additional instances.
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;
public final class PMF {
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("transactions-optional");
private PMF() {}
public static PersistenceManagerFactory get() {
return pmfInstance;
}
}
Creating Entities
Once you have a connection to the datastore, it's relatively simple to persist entities.
Just create a new instance, and then pass it to the makePersistent synchronous
method.
PersistenceManager pm = PMF.get().getPersistenceManager();
Order o = new Order("Jeff Douglas", "111-222-3333");
 
Search WWH ::




Custom Search