You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/04/21 18:21:01 UTC

svn commit: r1470318 - in /isis/site/trunk/content: components/objectstores/jdo/about.md components/objectstores/jdo/workarounds.md documentation.md

Author: danhaywood
Date: Sun Apr 21 16:21:01 2013
New Revision: 1470318

URL: http://svn.apache.org/r1470318
Log:
isis site - adding page with workarounds for jdo

Added:
    isis/site/trunk/content/components/objectstores/jdo/workarounds.md
Modified:
    isis/site/trunk/content/components/objectstores/jdo/about.md
    isis/site/trunk/content/documentation.md

Modified: isis/site/trunk/content/components/objectstores/jdo/about.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/about.md?rev=1470318&r1=1470317&r2=1470318&view=diff
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/about.md (original)
+++ isis/site/trunk/content/components/objectstores/jdo/about.md Sun Apr 21 16:21:01 2013
@@ -1,12 +1,13 @@
-Title: JDO (DataNucleus) Object Store
+Title: DataNucleus (JDO) Object Store
 
-The JDO objectstore enables the persistence of domain objects using the JDO API. [DataNucleues](http://datanucleus.org) - the reference implementation for JDO - is used as the backing implementation.
+The DataNucleus objectstore enables the persistence of domain objects using the JDO API.  [DataNucleues](http://datanucleus.org) is the reference implementation for JDO.
 
 ### Hints and tips:
 
 - [Maven and Eclipse](maven-and-eclipse.html)
 - [Dates, Blobs and Lazy Loading](dates-blobs-lazy-loading.html)
 - [Using a JNDI Datasource](using-jndi-datasource.html) [1.1.0-SNAPSHOT]
+- [Workarounds (the `IsisJdoSupport` service)](workarounds.html) [1.1.0-SNAPSHOT]
 - [Enabling Logging](enabling-logging.html)
 - [Deploying on the Google App Engine](deploying-on-the-google-app-engine.html)
 

Added: isis/site/trunk/content/components/objectstores/jdo/workarounds.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/workarounds.md?rev=1470318&view=auto
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/workarounds.md (added)
+++ isis/site/trunk/content/components/objectstores/jdo/workarounds.md Sun Apr 21 16:21:01 2013
@@ -0,0 +1,127 @@
+Title: Workarounds (the `IsisJdoSupport` service) [1.1.0-SNAPSHOT]
+
+There are a number of limitations in DataNucleus' implementation of JDO, specifically with regard to 1:m bidirectional relationships.  
+
+* loading the children from the parent does not fire the `jdoPostLoad` callback (either on the entity via `javax.jdo.listener.LoadCallback` nor `javax.jdo.listener.LoadLifecycleListener`)
+
+* persisting a child entity does not cause the parent's collection to be updated.
+
+  Note that this is documented behaviour; see this [DataNucleus page](http://www.datanucleus.org/products/datanucleus/jdo/orm/relationships.html).
+
+The `IsisJdoSupport` service provides a number of methods to enable workarounds for these cases.
+
+*This page will be updated if we determine that such workarounds are not (or are no longer) required.*
+
+## `IsisJdoSupport`
+
+The `IsisJdoSupport` is defined in the JDO applib. It is defined as:
+
+    package org.apache.isis.objectstore.jdo.applib.service.support;
+public interface IsisJdoSupport {
+        <T> T injected(T domainObject);
+        <T> T refresh(T domainObject);
+    }
+
+The implementation is `IsisJdoSupportImpl`.  It is registered in `isis.properties` as per usual:
+
+    isis.services = ...\
+                org.apache.isis.objectstore.jdo.datanucleus.service.support.IsisJdoSupportImpl,\
+                    ...
+
+In the domain entity or service, add:
+
+    // {{
+    private IsisJdoSupport isisJdoSupport;
+    public void setIsisJdoSupport(IsisJdoSupport isisJdoSupport) {
+        this.isisJdoSupport = isisJdoSupport;
+    }
+    // }}
+
+The service will then be automatically injected as normal.
+                    
+## Workaround for Lazy Loading
+
+In a bidir 1:m, we have found that the post-load callback for the children is not fired.
+
+The consequence of this is that any domain services used by the child object (including `DomainObjectContainer`) are not injected into the child.
+
+The workaround is to have the parent inject the services when returning the children.
+
+For example, suppose we have a Customer <->* Order bidir relationship.  In Customer, we would have:
+
+    // {{ Orders (Collection)
+    private SortedSet<Order> orders = new TreeSet<Order>();
+
+    @Persistent(mappedBy = "customer")
+    public SortedSet<Order> getOrders() {
+        
+        if (this.orders == null) {
+            // this can happen, it would seem, by JDO/DN when it is 
+            // setting up the object with its own set impl for lazy loading.
+            return null;
+        } else {
+            // inject each element before returning it
+            return Sets.newTreeSet(
+                Iterables.transform(
+                    this.orders, 
+                    new Function<Order, Order>(){
+                        public Order apply(Order order) {
+                            return isisJdoSupport.injected(order);                        
+                        }
+                    }));
+        }
+    }
+
+    public void setOrders(final SortedSet<Order> orders) {
+        this.orders = orders;
+    }
+
+Alternatively, you can reload each child object.  Change:
+
+                    new Function<Order, Order>(){
+                        public Order apply(Order order) {
+                            return isisJdoSupport.injected(order);                        
+                        }
+                    }));
+
+to:
+
+                    new Function<Order, Order>(){
+                        public Order apply(Order order) {
+                            return isisJdoSupport.refresh(order);
+                        }
+                    }));
+
+Use [logging](enabling-logging.html) to determine if this makes more calls to the database than using the `injected()` method.
+
+## Handling Unmanaged Parent Relationship
+
+(Also in a bidir 1:m), we have found that the parent collection is not added to if a new child entity is persisted.
+
+There are two choices here.  The first is to ensure that there is code that manually updates each side of the relationship.  The second is to flush the changes and then to manually reload the parent entity from the database.
+
+For example, suppose we have a Customer <->* Order bidir relationship, with an action that persists an Order.  
+
+To update both sides of the relationship, use:
+
+    public Order newOrder(final Customer customer) {
+        Order order = newTransientInstance(Order.class);
+        order.setCustomer(customer);
+        customer.getOrders().add(order); // update parent's collection
+        persist(customer);
+        return order;
+    }
+
+
+Alternatively, to reload the parent, use the `IsisJdoSupport` service:
+
+    public Order newOrder(final Customer customer) {
+        Order order = newTransientInstance(Order.class);
+        order.setCustomer(customer);
+        persist(customer);
+        getContainer().flush(); // to database
+        isisJdoSupport.refresh(customer); // reload parent from database
+        return order;
+    }
+
+

Modified: isis/site/trunk/content/documentation.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/documentation.md?rev=1470318&r1=1470317&r2=1470318&view=diff
==============================================================================
--- isis/site/trunk/content/documentation.md (original)
+++ isis/site/trunk/content/documentation.md Sun Apr 21 16:21:01 2013
@@ -205,12 +205,13 @@ Note: this viewer is open source but is 
 
 {span-one-third
 
-###  JDO [1.0.0](components/objectstores/jdo/release-notes/about.html)
+###  DataNucleus (JDO) [1.0.0](components/objectstores/jdo/release-notes/about.html)
 
 - [About](components/objectstores/jdo/about.html)
 - [Maven and Eclipse](components/objectstores/jdo/maven-and-eclipse.html)
 - [Dates, Blobs and Lazy Loading](components/objectstores/jdo/dates-blobs-lazy-loading.html)
-- [Using a JNDI Datasource](components/objectstores/jdo/using-jndi-datasource.html) [1.1.0-SNAPSHOT]
+- [Using a JNDI Datasource](components/objectstores/jdo/using-jndi-datasource.html) [1.1.0-SNAPSHOT]
+- [Workarounds](components/objectstores/jdo/workarounds.html) [1.1.0-SNAPSHOT]
 - [Enabling Logging](components/objectstores/jdo/enabling-logging.html)
 - [Deploying on the Google App Engine](components/objectstores/jdo/deploying-on-the-google-app-engine.html)