Re: [jboss-dev-forums] [JBoss XML Binding Development] - JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData
by Scott Marlow
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&cont...]
14 years, 5 months
Re: [jboss-dev-forums] [JBoss XML Binding Development] - JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData
by jaikiran pai
jaikiran pai [http://community.jboss.org/people/jaikiran] replied to the discussion
"JBJPA-27 and setting PersistenceUnitMetaData reference to PersistenceMetaData"
To view the discussion, visit: http://community.jboss.org/message/540467#540467
--------------------------------------------------------------
> Scott Marlow wrote:
>
> Is there any reason why CollectionPropertyHandler.handle(PropertyInfopropertyInfo, TypeInfo propertyType, Object parent, Object child, QName
> qName) couldn't call the the getter after setting the field? It appears that we call the getter before the set, but not after.
>
> ...
>
> If the convention is to put initialization logic in the getter, perhaps XB should call the getter after setting the field.
Scott,
I haven't looked into the details of this thread (yet), but looking at this part of getter/setter, I guess it's related to this? http://community.jboss.org/thread/149235 http://community.jboss.org/thread/149235
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/540467#540467]
Start a new discussion in JBoss XML Binding Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 5 months