Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [dali-dev] Manipulate java resources via resource model

Hi Brian,
 
I observed, that changes are propagated directly to the model, but file is not saved. I done that in this way:
 
  JavaPersistentAttribute attr = (JavaPersistentAttribute)ownerType.resolveAttribute("Attr_name");  
  attr.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);//
  IFile entityClass = (IFile)ownerType.getResource();  
  CompilationUnit cu = (CompilationUnit)JavaModelManager.create(entityClass, ownerType.getJpaProject().getJavaProject());
  try {
   cu.save(new NullProgressMonitor(), true);
  } catch (JavaModelException jme){
   //TODO 
  }
 
However, it works, when I invoke this at the input of our editor. Unfortunately it is not the case when I tried to invoke it in test environment. I tried to set command executor and updater on JpaProject without success. Actually that was only applying of the methods of attempts, because in the test environment I haven't UI at all. I debug the process and after the setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY) the annotation is provided in the model
Could you tell me where is my mistake? Obviously I have problem with saving of the changed file.
 
Best Regards,
Dimiter



From: dali-dev-bounces@xxxxxxxxxxx [mailto:dali-dev-bounces@xxxxxxxxxxx] On Behalf Of Brian Vosburgh
Sent: Tuesday, July 22, 2008 8:07 PM
To: General Dali EJB ORM developer discussion.
Subject: Re: [dali-dev] Manipulate java resources via resource model

Dimiter,

changes to the model are propagated directly to the source. If the modified file is also open in an editor in the UI, the modified file will be changed but not saved. The user will need to save the file.

If you are changing the model outside the UI thread you will need to configure the JPA project to make modifications on the UI thread as necessary. See JpaProject#setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor).

Also note the model is "updated" asynchronously with every change. If you want these updates to happen synchronously, you will need to set the JPA project's "updater". See JpaProject#setUpdater(
Updater). Note the comments in SynchronousJpaProjectUpdater.

All of this is mildly complicated; so I have to ask: What are you trying to do? If you are manipulating JPA annotations, you could use the "context" model. Is there a reason you want to use the "resource" model?

Brian

Dimitrov, Dimiter wrote:
Hi Brian,
 
I will take a look and I will ask you if something is not clear to me. Just another question at this stage. When I change the model, whether change will be propagated directly in the source, or I have to save the explicitly. If I have to do it explicitly, is there special API provided from DALI, or I have to use JDT API?
 
Best Regards,
Dimiter

From: dali-dev-bounces@xxxxxxxxxxx [mailto:dali-dev-bounces@xxxxxxxxxxx] On Behalf Of Brian Vosburgh
Sent: Thursday, July 17, 2008 9:11 PM
To: General Dali EJB ORM developer discussion.
Subject: Re: [dali-dev] Manipulate java resources via resource model

Yes, Member is the interface Dali uses to manipulate annotations in Java source code.
We use implementations of AnnotationAdapter and Declaration
AnnotationAdapter to
add, remove, and change annotations on a member (type, field, or method).
These adapters are public while the implementations are still internal; but you can look
at the implementations to see how we manipulate annotations ourselves.

Ask, if something is not clear, and I will try to remember how it works. :)

Brian

Dimitrov, Dimiter wrote:

Hello,

In our work with new JPA model, we have necessity to manipulate java entity class, adding new fields and annotations. We could do this via JDT API, but I’m wondering whether will be possible to do this via java resource model? I mean if we have reference to JavaResourcePersistentType (respectively to its fields and properties) could we manipulate them? For instance is it possible to add relation one to one on attribute with name attribute? I hope that the presented API provide such opportunities, because I noticed method getMember() (for type, field or property), which returns Member. From own side Member (in accordance with Java Doc) offers manipulating of annotations on members. Is this manipulation provides modifying (reflected in the code), or it is read-only?

Any help, information or hint will be appreciated.



_______________________________________________ dali-dev mailing list dali-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/dali-dev


Back to the top