| Summary: | Updating model does not commit changes to CompilationUnit - provide "headless" API | ||
|---|---|---|---|
| Product: | [WebTools] Dali JPA Tools | Reporter: | Tom Mutdosch <mutdosch> |
| Component: | General | Assignee: | Karen Butzke <karenfbutzke> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | karenfbutzke, neil.hauge |
| Version: | 1.0 | ||
| Target Milestone: | 2.0.5 | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
| Bug Depends on: | 271847 | ||
| Bug Blocks: | |||
Our general design is to work in tandem with the Java and XML editors, making edits to the source for the user, but never assuming that a user wants to commit. We always want to leave this decision up to the user, since we don't want to assume that the code is in a "committable" state. Looking at the comments of this method, there are some limitations that we are dealing with that seem to be very touchy. I'm copying Karen to see if she has any comments on your suggestion. Makes sense. In our case when our wizard operation runs, the target entity is likely not even open in the Java/XML editor. We are sort of using the model as a headless API. In this scenario, it's a bit cumbersome as any change we make to the model we have to add a block of code to handle committing ourselves -- such as in the below example where we add a new NamedQuery to the Entity. I was just thinking that it might be cleaner/nicer if there was an API mechanism on the model, such as IEntity.save() or JPAModel.saveModel() or something like that.
// add named query
List<INamedQuery> namedQueryList = ((IEntity)mapping).getNamedQueries();
INamedQuery q = ((IEntity)mapping).createNamedQuery(namedQueryList.size());
q.setName( "getMovies");
q.setQuery("select m FROM Movie m");
namedQueryList.add(q);
// save model change
ICompilationUnit compUnit = entityType.findJdtType().getCompilationUnit();
if (compUnit.isWorkingCopy()) {
compUnit.commitWorkingCopy(true, null);
} else {
compUnit.save(null, true);
}
Updating Severity to reflect enhancement request nature of this issue. We need to evaluate this request for 2.0. Ran out of time for this one. This problem is solved with the solution to bug 271847, setting it to depend on that bug. 271847 was fixed |
We have a wizard with an operation that sets the primary key on a selected Entity. We are setting the primary key by setting the mapping key on the IPersistentAttribute: IPersistentAttribute attribute = myAttribute; attribute.setMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY), false); This does not seem to actually commit the working copy. If I then open up the modified entity in the Java editor, it will appear dirty. It looks like in the jdtUtility.Member edit_ method, it does: if ( ! textEditorPresent) { compilationUnit.getBuffer().setContents(doc.get()); compilationUnit.commitWorkingCopy(true, null); compilationUnit.discardWorkingCopy(); } This does not commit the change to the compilation unit. Perhaps if this code could instead do something along the lines of: compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null); if ( compilationUnit.isWorkingCopy()) { compilationUnit.commitWorkingCopy(true, null); } else { compilationUnit.save(null,true); } Or an alternative would be an API mechanism that could be called to commit the JPA model changes.