[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.dali] Re: question on ResourceModelListener

For completeness's sake, still another re-post from dali-dev:

Sorry about the class names. They have very recently changed,
to make them more consistent and to fit better with work we are
doing to support binary entities in the next release. The class names
I referred to are in the latest development stream. From now on,
I will assume you are using Dali 2.0, which was part of the
Ganymede Java EE release. Let me know if you are using some other release.

ResourceModelListener is very different from the other listeners you
mention. The method resourceModelChanged() is called any time
*anything* within the ResourceModel or any of the objects contained
by the ResourceModel changes. This is used by Dali to trigger an
update of *all* the inter-dependent settings in the "context" model.
E.g. if a Java field name changes (which is part of the "resource" model),
the default column name in the field's mapping changes (which is part
of the "context" model). Instead of tracking all the inter-dependencies
directly, Dali simply uses a brute-force "update" of the entire "context"
model whenever *anything* in the "resource" model changes.

If you are interested in more granular changes, you will need to use
the other listeners (PropertyChangeListener, ListChangeListener, etc.).
You need to add these listeners to the specific object whose state you
are interested in. If you add a PropertyChangeListener to a
JpaCompilationUnit, you will receive notification of changes to the
compilation unit's various properties. I think the only property that can
change is the 'persistentType', which is a JavaResourcePersistentType.
If you interested in changes to the persistent type, you will need to
add the appropriate listener to that object directly.

I would like to repeat: The "context" model is probably more helpful
than the "resource" model. It has much more information and "context"(!).
To get the particular "context" persistent type you are interested in,
you would use code somewhat akin to this:
    JpaProject.getRootContext()
    JpaRootContextNode.getPersistenceXml()
    PersistenceXml.getPersistence()
    Persistence.persistenceUnits()
    PersistenceUnit.classRefs()
    ClassRef.getClassName().equals("com.test.Sess1")
    ClassRef.getJavaPersistentType()
    JavaPersistentType.getMapping()
    etc.

If you are interested in knowing when a type's mapping has changed
(e.g. the @Entity annotation has been added to the class declaration),
you would add a PropertyChangeListener to the JavaPersistentType
returned by the ClassRef above. The "context" model for the @Entity
annotation would be the TypeMapping returned by JavaPersistentType.

If you are using a mapping file (i.e. orm.xml) you will need to use a
slightly different approach to getting the PersistentType you are
interested in.

Also, you log in to the newsgroups using your Bugzilla userid/password.
If you have forgotten your password, you can submit a request to change
it here:
    https://bugs.eclipse.org/bugs/index.cgi?GoAheadAndLogIn=1

Brian


Ivy Ho wrote:
> Brian:
>
> Just one more question: (sorry I forget my password and cannot post it to org.eclipse)..
>
> I could not find JpaResourceCompilationUnit. I find JpaCompilationUnit instead.
>
>
> 1. Assuming that "JpaResourceCompilationUnit" is JpaCompilationUnit, I got this object from my jpa project and
> add listener to listen different changes, but somehow all the changes I made from JPA details view, I didn't
> get any notification, so to simplify the question, is there a way I can get notification whenever the change
> is made from JPA details view? If I need to go with the some kind of model change listener, the code below is
> the correct?
>
> JavaResourcePersistentType type = jpaProject.getJavaPersistentTypeResource("com.test.Sess1");
> if(type != null) {
> JpaCompilationUnit jcu = type.getJpaCompilationUnit();
> jcu.addPropertyChangeListener(new PropertyChangeListener() {
> ......
> });
> jcu.addCollectionChangeListener(new CollectionChangeListener() {
> ......
> });
> jcu.addListChangeListener(new ListChangeAdapter() {
> ......
> });
> jcu.addStateChangeListener(new StateChangeListener() {
> ......
> });
> jcu.addTreeChangeListener(new TreeChangeListener() {
> ......
> });
> jcu.getResourceModel().addResourceModelChangeListener(new ResourceModelListener() {
> ......
> });
> }
>
> 2. Also can I get the model of an annotation say @Entity in the JPACompilationUnit?
>
>
> ================Thanks for your help!=============================
>
>
> On 1/30/09, Ivy Ho <corporategirl@xxxxxxxxx> wrote:
>
> Thanks so much for such detail reply. It is very informative.
> :-)
>
>
> On 1/30/09, Brian Vosburgh <brian.vosburgh@xxxxxxxxxx> wrote:
>
> Forwarded to the appropriate forum, the Dali newsgroup:
> http://www.eclipse.org/newsportal/thread.php?group=eclipse.technology.dali
>
> Ivy Ho wrote:
>> Hi there:
>>
>> I have implements in from our widget ,ResourceModelListener and ,PropertyChangeListener..
>>
>> It is funny that if I click on the JPA view,on any fields The PropertyChangeListener is never invoked but it always go to ResourceModelListener.
>> However in the method resourceModelChanged() , there is no indication as what changes trigger the events,.
>> Is there any other listeners I can use or there is something we can do in the resourceModelChanged to find out what the change is ?
>>
>> Thanks so much!
>>
>> public void resourceModelChanged() {
>> // TODO Auto-generated method stub
>>
>> System.out.println("resourceModelChanged...");
>>
>> }
>>
>>
>>
>> === some how the following was never invoked.== don''t know why.====
>>
>> public void propertyChanged(
>> org.eclipse.jpt.utility.model.event.PropertyChangeEvent arg0) {
>> // TODO Auto-generated method stub
>>
>> System.out.println("org.eclipse.jpt.utility.model.event.PropertyChangeEvent");
>> if (arg0!=null)
>> {
>> System.out.println("property name="+arg0.getPropertyName());
>> System.out.println("source="+arg0.getSource());
>> System.out.println("new value="+arg0.getNewValue()+": old="+arg0.getOldValue());
>>
>> }
>> System.out.println("end org.eclipse.jpt.utility.model.event.PropertyChangeEvent");
>> }
>> l
>>
>>
>>
>> _______________________________________________
>> dali-dev mailing list
>> dali-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/dali-dev
>>
>
>
>
> _______________________________________________
> dali-dev mailing list
> dali-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/dali-dev
>
>
>