javagoogle-app-enginejdomptt

MPTT, how to implement in Google App Engine using JDO?


I am moving from PHP/MySQL to Google App Engine and using JDO as interface with the datastore. What's the recommended way of migrating a Modified Preorder Tree Traversal (MPTT) enabled table to a JDO model?


Solution

  • After spending some time searching on the different ways to implement hierarchical data storage on GAE datastore, I decided to try a direct MPTT implementation. The following code snippet presents the model:

    @PersistenceCapable(identityType = IdentityType.APPLICATION)
    public class MPTTObject {
    
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
        private String encodedKey;
    
        @Persistent
        private String parentEncodedKey;
    
        @Persistent
        private int left;
    
        @Persistent
        private int right;
    

    The solution works pretty well if the datastore operations are read intensive, but it's quite "heavy" when the operations are write intensive. This fact in combination with the time limitations within which an operation must be completed in GAE, makes this solution less appealing.

    Another approach that seems to be more efficient is to store the full list of parents and children for each node in the hierarchy.

    Some useful links on hierarchical data storage on GAE datastore are the following: