Low-level filters --------------------------Finder methods can now take a FindOptions parameter which specifies the FetchOptions and new filters: PropertyPredicate and EntityPredicate. They are used to filter out data you are not interested in _before_ it is "re-hydrated" as model instances. This can save huge amounts of processing time because in GAE it is common to need to return more results than you need due to the single- inequality-property and sort-only-by-inequality rules.
in Twig a search for a hotel under a certain price might look like this:Query query = typesafe.query(Hotel.class).addFilter("price", LESS_THAN, 30);
Iterator<Hotel> hotels = typesafe.find(query);If you want to also sort the results by "popularity" you cannot do this in a simple query because the Datastore does not let you sort by a different property than your inequality. You have to do your search sorted by popularity and then in your application filter out the results that are too expensive.
Previously you would have needed to iterate through the Hotel objects and ignore the expensive ones. I believe that with JDO-GAE you would need to do this. Please correct me if I am wrong. That wastes CPU time instantiating objects and setting properties that are not even needed.
In Twig you can now filter out both entire Entities from the results at the lowest level by passing a Predicate<Entity> like:
Predicate<Entity> filter = new Predicate<Entity()
{
public boolean apply(Entity hotel)
{
return hotel.getProperty("price") < 30;
}
}
FindOptions options = new FindOptions();
options.setEntityPredicate(filter);
Iterator<Hotel> hotels = typesafe.find(query, options);
You can also set a similar property filter Predicate<String> to filter
out properties that you don't want translated when you know you will
not read them.
Smaller Kind names ---------------------------------You can save space that your Keys require in the datastore by giving them shorter kind names. In JDO you can do this by naming your classes with short names. In Twig it is simple to specify short names while keeping your classes named nicely:
@Override
public String typeToKind(Type type)
{
if (Hotel.class == type)
{
return "H";
}
else
{
return super.typeToKind(type);
}
}
@Override
protected Type kindToType(String kind)
{
if (kind.equals("H"))
{
return Hotel.class;
}
else
{
return super.kindToType(kind);
}
}
There have been many other API changes bug fixes and improvements
including new bulk store methods :
List<Key> storeAll(Iterator<?> instances);
List<Key> storeAll(Iterator<?> instances, Object parent);
and convenience methods to avoid checking if an instance is already
known to the Twig session.
void storeOrUpdate(Object instance);
void storeOrUpdate(Object instance, Object parent);
There are a lot more performance improvements and new features in the
works for futures versions. The API is still quite fluid however so
it is definitely no where near stable yet. But if you are interested
in helping guide the evolution of the API at this early stage please
take it for a spin! There is a maven pom which will take care of all
the dependencies for you to build from source and get hacking on the
code.
http://code.google.com/p/twig-persist/ John--
You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
