[jboss-dev-forums] [JBoss XML Binding Development] - JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData

Scott Marlow do-not-reply at jboss.com
Fri Apr 30 11:39:21 EDT 2010


Scott Marlow [http://community.jboss.org/people/smarlow%40redhat.com] replied to the discussion

"JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData"

To view the discussion, visit: http://community.jboss.org/message/540480#540480

--------------------------------------------------------------
When the collection is set, I need to do some special initialization on each item in the collection.  It might look something like this:


public List<PersistenceUnitMetaData> getPersistenceUnits()
   {
      if(NOT INITIALIZED YET)
      {
         for( Iterator<PersistenceUnitMetaData> iter = persistenceUnits.iterator(); iter.hasNext(); )
         {
            PersistenceUnitMetaData pumd = iter.next();
            pumd.setPersistenceMetaData(this);
         }
      }
      return persistenceUnits;
   }
 


I started out with this logic in the setter but found that null is passed in.  When the getter is called from CollectionPropertyHandler (I'm not on XB trunk yet), the collection hasn't been set yet (as by design in CollectionPropertyHandler.

Others have said that I should place my initialization logic in the getter (by convention).  I'm not sure if that is a XB convention or a more general convention that other XML parsing/processing libraries also use. 

1.  I need a strong contract/convention that I can depend on with regard to custom initialization after the collection has been set.  Whether that is a setter or getter contract (I assume getter is better since it shouldn't mutate the collection).  I am mutating the objects referenced by the collection which can be a delicate operation (will need to avoid mutating the hashkey).

2.  I don't know the existing conventions that we might already depend on.  I am not making a case to make changes to current conventions that could break other XB dependent code. 

I hope that helps illustrate what I am trying to do.

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/540480#540480]

Start a new discussion in JBoss XML Binding Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2065]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20100430/7e2a8610/attachment.html 


More information about the jboss-dev-forums mailing list