Pages

GAE/J and DataNucleus v3 - Part 1

Monday, August 15, 2011
Some time ago I wrote a post about GAE/J and how it provides JDO/JPA. It had many limitations and shortcomings. Recently we have had the chance to update their DataNucleus plugin to work with version 3.0. Here are the major changes that users of that plugin will see if they build and use GAE/J DataNucleus plugin from SVN trunk.

JDOQL/JPQL : Support for methods/operators
If a user sets the query extension/hint "datanucleus.query.evaluateInMemory" then the query will be evaluated in-memory. This has an obvious drawback in terms of memory utilisation (if the number of results is large), but the big plus is that it will evaluate almost all JDOQL/JPQL syntax.

JDOQL : Support for input candidate collection
You can now specify the instances that you want to query over using query.setCandidateCollection(...). Means that you have a list of instances and can query which of them match a particular filter criteria.

Primary Key Types
Previously you could only have Long, String or Key. You can now also have long.

Plugin package naming
Now uses com.google.appengine.datanucleus as its package root, hence not using the DataNucleus-owned domain.

JDOQL/JPQL setResultClass
This is now supported for the standard types of result classes, so you no longer need to convert manually the result into your required type.

Value Generation
GAE/J users can now make use of other DataNucleus value generators, such as "uuid", "uuid-hex"

PersistenceManagerFactory
The PersistenceManagerFactory used is now the standard DataNucleus PMF, not any custom GAE variant. To be specific the PersistenceManagerFactoryClass is now org.datanucleus.api.jdo.JDOPersistenceManagerFactory. If you want to have a singleton PMF, simply set the persistence property datanucleus.singletonPMFForName to true. This will then return any existing PMF if present for the requested persistence-unit, or create it if not present.

EntityManagerFactory
The EntityManagerFactory used is now the standard DataNucleus EMF, not any custom GAE variant. To be specific the PersistenceProvider is org.datanucleus.api.jpa.PersistenceProviderImpl. If you want to have a singleton EMF, simply set the persistence property datanucleus.singletonEMFForName to true. This will then return any existing EMF if present for the requested persistence-unit, or create it if not present.

JPA2
By using DataNucleus v3 you now have available all of the changes made in JPA2, so things like Criteria queries, metamodel, etc.

JDO3
By using DataNucleus v3 you now have available all of the changes made in JDO3.0/JDO3.1. This means query timeouts, metadata API, enhancer API, as well as the DataNucleus proposal for Typesafe JDO queries.

Level2 Caching
Level2 Caching is enabled by default, using an internal map-based cache. You can improve this further by setting the persistence property datanucleus.cache.level2.type to "javax.cache" and include datanucleus-cache.jar in your CLASSPATH. This will then cache using GAE Memcache

Non-transactional Persistence
DataNucleus non-transactional behaviour is different now, with any call to pm.makePersistent, pm.deletePersistent, em.persist, em.merge, em.remove being atomic, sent to the datastore immediately. Any updates to fields via setters are still queued.

JPA RetainValues
JPA usage, by default, has datanucleus.RetainValues set to true now. This means that when you commit a transaction the object will retain the values of its fields (previously it migrated to hollow state).

Persistence of other java types
In GAE/J v1 you can only persist fields of the following types : primitive, primitive wrapper, String, Date, Enum, BigDecimal, some com.google.appengine types, as well as Collection types. With v2 you can now persist fields of types Currency, Locale, Timezone, BigInteger, Color, Point, StringBuffer, Jodatime, javax.time, and many more.


Be aware though ... there is more to come

3 comments:

  1. "Part1" hey we are waiting for the Part2!!!

    ReplyDelete
  2. DataNucleus App Engine Plugin v2.0.0-RC1 is available
    https://plus.google.com/102837845875216819095/posts/9U9VFWqhPx7

    ReplyDelete
  3. RC2!
    http://code.google.com/p/datanucleus-appengine/downloads/list

    ReplyDelete