Community

JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData

reply from Scott Marlow in JBoss XML Binding Development - View the full discussion

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

Start a new discussion in JBoss XML Binding Development at Community