| author | Petya Sabeva | 2013-01-02 08:42:12 (EST) |
|---|---|---|
| committer | Petya Sabeva | 2013-01-02 08:57:57 (EST) |
| commit | 4c46116f315db000d7550b9fa26ad4ef61c68733 (patch) (side-by-side diff) | |
| tree | 47c10829c3ff604d82b6aa8797e5ed3d134454ec | |
| parent | 8ac751a8b8531fb642ccd9f85746afe7ed2da36c (diff) | |
| download | webtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.zip webtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.tar.gz webtools.dali-4c46116f315db000d7550b9fa26ad4ef61c68733.tar.bz2 | |
[364597] - JPA 2.0 - Support for derived ids
Change-Id: Icaab1c0a8989b040efcdf3fc8a4f95da0c775262
46 files changed, 2139 insertions, 377 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif Binary files differnew file mode 100644 index 0000000..e11633f --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-1-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif Binary files differnew file mode 100644 index 0000000..7fd38a2 --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-2-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif Binary files differnew file mode 100644 index 0000000..077e8ae --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/many-to-one-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif Binary files differnew file mode 100644 index 0000000..0a46cfb --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-1-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif Binary files differnew file mode 100644 index 0000000..8ea6842 --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-2-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif Binary files differnew file mode 100644 index 0000000..3e72534 --- a/dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/icons/ent/one-to-one-key.gif diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java index 1c260b2..af2edc2 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java @@ -321,6 +321,7 @@ public class JPADiagramEditor extends DiagramEditor implements JpaEditorManager{ jpaSelectionModel.setValue(jpaStructureNode); setFileModel(jpaStructureNode); selectionManager.setSelection(jpaStructureNode); +// jpaStructureNode.getJpaPlatform().buildJpaFile(jpaStructureNode.getJpaProject(), jpaFileModel.getValue().getFile()); return; } } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java index 8bad938..70a2205 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/AddAttributeCommand.java @@ -112,19 +112,22 @@ public class AddAttributeCommand implements Command { createAttribute(fp, jpt, attributeType, mapKeyType, attributeName,
actName, cu, type, isCollection, attrTypes, contents);
- JavaPersistentAttribute attr = jpt.getAttributeNamed(actName);
- int cnt = 0;
- while ((attr == null) && (cnt < 25)) {
- try {
- Thread.sleep(250);
- } catch (InterruptedException e) {
- JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
+ if(jpt != null) {
+ JavaPersistentAttribute attr = jpt.getAttributeNamed(actName);
+ int cnt = 0;
+ while ((attr == null) && (cnt < 25)) {
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
+ }
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit()
+ .synchronizeWithJavaSource();
+ jpt.update();
+ jpt.synchronizeWithResourceModel();
+ attr = jpt.getAttributeNamed(actName);
+ cnt++;
}
- jpt.getJavaResourceType().getJavaResourceCompilationUnit()
- .synchronizeWithJavaSource();
- jpt.update();
- attr = jpt.getAttributeNamed(actName);
- cnt++;
}
} catch (JavaModelException e) {
@@ -182,7 +185,7 @@ public class AddAttributeCommand implements Command { " " + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
String contents = ""; //$NON-NLS-1$
- if(!JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ if(jpt!= null && !JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
contents = annotationContents + attrFieldContent;
} else {
contents = attrFieldContent;
@@ -379,7 +382,7 @@ public class AddAttributeCommand implements Command { + actName.substring(1);
String contents = ""; //$NON-NLS-1$
- if(JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
+ if(jpt != null && JpaArtifactFactory.instance().isMethodAnnotated(jpt)){
contents += annotationContents;
}
contents += " public " + attrType + //$NON-NLS-1$
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java index 5252dbd..eb3159a 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java @@ -25,7 +25,6 @@ import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.utility.command.Command;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -39,109 +38,205 @@ public class DeleteAttributeCommand implements Command { private JavaPersistentType jpt;
private String attributeName;
private IJPAEditorFeatureProvider fp;
+ private ICompilationUnit unit;
- public DeleteAttributeCommand(JavaPersistentType jpt, String attributeName,
+ public DeleteAttributeCommand(ICompilationUnit unit, JavaPersistentType jpt, String attributeName,
IJPAEditorFeatureProvider fp) {
super();
this.jpt = jpt;
+ this.unit = unit;
this.attributeName = attributeName;
this.fp = fp;
}
public void execute() {
- synchronized (jpt) {
- String attrNameWithCapitalLetter = attributeName.substring(0, 1)
- .toUpperCase(Locale.ENGLISH)
- + attributeName.substring(1);
- ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
- IType javaType = compUnit.findPrimaryType();
- JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
+//<<<<<<< OURS +// synchronized (jpt) {
+// String attrNameWithCapitalLetter = attributeName.substring(0, 1)
+// .toUpperCase(Locale.ENGLISH)
+// + attributeName.substring(1);
+// ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
+// IType javaType = compUnit.findPrimaryType();
+// JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
+//
+// String typeSignature = null;
+// String getterPrefix = "get"; //$NON-NLS-1$
+// String methodName = getterPrefix + attrNameWithCapitalLetter;
+// IMethod getAttributeMethod = javaType.getMethod(methodName,
+// new String[0]);
+// if (!getAttributeMethod.exists()) {
+//
+// String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
+// if ("boolean".equals(typeName)) { //$NON-NLS-1$
+// getterPrefix = "is"; //$NON-NLS-1$
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// getAttributeMethod = javaType.getMethod(methodName,
+// new String[0]);
+// }
+// try {
+// if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
+// typeSignature = getAttributeMethod.getReturnType();
+// }
+// } catch (JavaModelException e1) {
+// JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+// if (typeSignature == null)
+// methodName = null;
+//======= + boolean isMethodAnnotated = false;
+//>>>>>>> THEIRS +//
+//<<<<<<< OURS +// boolean isMethodAnnotated = JpaArtifactFactory.instance()
+// .isMethodAnnotated(jpt);
+// if (isMethodAnnotated) {
+// try {
+// IField attributeField = javaType.getField(attributeName);
+//
+// if ((attributeField != null) && !attributeField.exists())
+// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+// if ((attributeField != null) && attributeField.exists())
+// attributeField.delete(true, new NullProgressMonitor());
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+// }
+// try {
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// if (getAttributeMethod != null) {
+// typeSignature = getAttributeMethod.getReturnType();
+// if (getAttributeMethod.exists())
+// getAttributeMethod.delete(true, new NullProgressMonitor());
+// }
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// } else {
+// try {
+// methodName = getterPrefix + attrNameWithCapitalLetter;
+// if (getAttributeMethod.exists()) {
+// typeSignature = getAttributeMethod.getReturnType();
+// getAttributeMethod.delete(true, new NullProgressMonitor());
+// }
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// try {
+// IField attributeField = javaType.getField(this.attributeName);
+// if (attributeField != null)
+// if (!attributeField.exists())
+// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+// if ((attributeField != null) && attributeField.exists())
+// attributeField.delete(true, new NullProgressMonitor());
+// } catch (JavaModelException e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+// }
+// }
+// try {
+// methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
+// IMethod setAttributeMethod = javaType.getMethod(methodName,
+// new String[] { typeSignature });
+// if ((setAttributeMethod != null) && setAttributeMethod.exists())
+// setAttributeMethod.delete(true, new NullProgressMonitor());
+// } catch (Exception e) {
+// JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+//
+// IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
+// JPAEditorUtil.organizeImports(compUnit, ws);
+//
+// this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+//
+//======= + if(jpt != null) {
+ unit = fp.getCompilationUnit(jpt);
+ isMethodAnnotated = JpaArtifactFactory.instance()
+ .isMethodAnnotated(jpt);
+//>>>>>>> THEIRS + }
+
+ IType javaType = unit.findPrimaryType();
- String typeSignature = null;
- String getterPrefix = "get"; //$NON-NLS-1$
- String methodName = getterPrefix + attrNameWithCapitalLetter;
- IMethod getAttributeMethod = javaType.getMethod(methodName,
- new String[0]);
- if (!getAttributeMethod.exists()) {
-
- String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
- if ("boolean".equals(typeName)) { //$NON-NLS-1$
- getterPrefix = "is"; //$NON-NLS-1$
- methodName = getterPrefix + attrNameWithCapitalLetter;
- getAttributeMethod = javaType.getMethod(methodName,
- new String[0]);
- }
- try {
- if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
- typeSignature = getAttributeMethod.getReturnType();
- }
- } catch (JavaModelException e1) {
- JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- if (typeSignature == null)
- methodName = null;
+ String attrNameWithCapitalLetter = attributeName.substring(0, 1)
+ .toUpperCase(Locale.ENGLISH) + attributeName.substring(1);
- boolean isMethodAnnotated = JpaArtifactFactory.instance()
- .isMethodAnnotated(jpt);
- if (isMethodAnnotated) {
- try {
- IField attributeField = javaType.getField(attributeName);
+ String typeSignature = null;
+ String getterPrefix = "get"; //$NON-NLS-1$
+ String methodName = getterPrefix + attrNameWithCapitalLetter;
+ IMethod getAttributeMethod = javaType.getMethod(methodName,
+ new String[0]);
+ if (!getAttributeMethod.exists()) {
+ getterPrefix = "is"; //$NON-NLS-1$
+ }
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ getAttributeMethod = javaType.getMethod(methodName, new String[0]);
+ try {
+ if ((getAttributeMethod != null) && getAttributeMethod.exists());
+ typeSignature = getAttributeMethod.getReturnType();
+ } catch (JavaModelException e1) {
+ JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (typeSignature == null)
+ methodName = null;
+
+ if (isMethodAnnotated) {
+ try {
+ IField attributeField = javaType.getField(attributeName);
- if ((attributeField != null) && !attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
- if ((attributeField != null) && attributeField.exists())
- attributeField.delete(true, new NullProgressMonitor());
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
- }
- try {
- methodName = getterPrefix + attrNameWithCapitalLetter;
- if (getAttributeMethod != null) {
- typeSignature = getAttributeMethod.getReturnType();
- if (getAttributeMethod.exists())
- getAttributeMethod.delete(true, new NullProgressMonitor());
- }
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- } else {
- try {
- methodName = getterPrefix + attrNameWithCapitalLetter;
- if (getAttributeMethod.exists()) {
- typeSignature = getAttributeMethod.getReturnType();
+ if ((attributeField != null) && !attributeField.exists())
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+ if ((attributeField != null) && attributeField.exists())
+ attributeField.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+ }
+ try {
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ if (getAttributeMethod != null) {
+ typeSignature = getAttributeMethod.getReturnType();
+ if (getAttributeMethod.exists())
getAttributeMethod.delete(true, new NullProgressMonitor());
- }
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- try {
- IField attributeField = javaType.getField(this.attributeName);
- if (attributeField != null)
- if (!attributeField.exists())
- attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
- if ((attributeField != null) && attributeField.exists())
- attributeField.delete(true, new NullProgressMonitor());
- } catch (JavaModelException e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
- }
- }
+ }
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ } else {
+ try {
+ methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
+ if (getAttributeMethod.exists()) {
+ typeSignature = getAttributeMethod.getReturnType();
+ getAttributeMethod.delete(true, new NullProgressMonitor());
+ }
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
try {
- methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
- IMethod setAttributeMethod = javaType.getMethod(methodName,
- new String[] { typeSignature });
- if ((setAttributeMethod != null) && setAttributeMethod.exists())
- setAttributeMethod.delete(true, new NullProgressMonitor());
- } catch (Exception e) {
- JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ IField attributeField = javaType.getField(this.attributeName);
+ if (attributeField != null)
+ if (!attributeField.exists())
+ attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
+ if ((attributeField != null) && attributeField.exists())
+ attributeField.delete(true, new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
+ }
+ }
+ try {
+ methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
+ IMethod setAttributeMethod = javaType.getMethod(methodName,
+ new String[] { typeSignature });
+ if ((setAttributeMethod != null) && setAttributeMethod.exists())
+ setAttributeMethod.delete(true, new NullProgressMonitor());
+ } catch (Exception e) {
+ JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
- IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
- JPAEditorUtil.organizeImports(compUnit, ws);
-
- this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
+ JPAEditorUtil.organizeImports(unit, ws);
- }
+ if(jpt != null)
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java index d9f7701..db274a4 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/RenameAttributeCommand.java @@ -18,6 +18,7 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.command; import java.lang.reflect.InvocationTargetException;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
@@ -37,16 +38,18 @@ import org.eclipse.ui.IWorkbenchWindow; public class RenameAttributeCommand implements Command {
private JavaPersistentType jpt;
+ private ICompilationUnit jptCompilationUnit;
private String oldName;
private String newName;
private IJPAEditorFeatureProvider fp;
- public RenameAttributeCommand(JavaPersistentType jpt, String oldName,
+ public RenameAttributeCommand(ICompilationUnit jptCompilationUnit, JavaPersistentType jpt, String oldName,
String newName, IJPAEditorFeatureProvider fp){
super();
this.jpt = jpt;
+ this.jptCompilationUnit = jptCompilationUnit;
this.oldName = oldName;
this.newName = newName;
this.fp = fp;
@@ -54,10 +57,20 @@ public class RenameAttributeCommand implements Command { }
public void execute() {
- ICompilationUnit cu = fp.getCompilationUnit(jpt);
+ if(jptCompilationUnit == null) {
+ jptCompilationUnit = fp.getCompilationUnit(jpt);
+ }
try {
- renameAttribute(cu, oldName, this.newName, fp, JpaArtifactFactory.instance().isMethodAnnotated(jpt));
- jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ boolean isMethodAnnotated = false;
+ if(jpt!= null){
+ isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpt);
+ }
+ renameAttribute(jptCompilationUnit, oldName, this.newName, fp, isMethodAnnotated);
+
+ if(jpt != null) {
+ jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ jpt.getJpaPlatform().buildJpaFile(jpt.getJpaProject(), (IFile) jptCompilationUnit.getResource());
+ }
} catch (InterruptedException e) {
JPADiagramEditorPlugin.logError("Cannot rename attribute", e); //$NON-NLS-1$
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java index ca9c478..8a269f9 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java @@ -221,15 +221,15 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature { } private void fillCompartments(JavaPersistentType jpt, ContainerShape entityShape) { - String[] primaryKeyAnnotations = new String[] {JPAEditorConstants.ANNOTATION_ID, JPAEditorConstants.ANNOTATION_EMBEDDED_ID}; + String[] primaryKeyAnnotations = new String[] {JPAEditorConstants.ANNOTATION_ID, JPAEditorConstants.ANNOTATION_EMBEDDED_ID, JPAEditorConstants.ANNOTATION_MAPS_ID}; for(String annotation : primaryKeyAnnotations){ - addCompartmentChildren(primaryShape, jpt, annotation); + addCompartmentChildren(primaryShape, jpt, annotation, null); } String[] relationAnnotations = new String[] {JPAEditorConstants.ANNOTATION_MANY_TO_MANY, JPAEditorConstants.ANNOTATION_MANY_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_MANY, JPAEditorConstants.ANNOTATION_ONE_TO_ONE}; for(String annotation : relationAnnotations){ - addCompartmentChildren(relationShape, jpt, annotation); + addCompartmentChildren(relationShape, jpt, annotation, primaryKeyAnnotations); } addBasicAttributes(basicShape, jpt); GraphicsUpdater.updateEntityShape(entityShape); @@ -284,18 +284,29 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature { private void addCompartmentChildren( ContainerShape containerShape, JavaPersistentType jpt, - String attributeAnnotations) { + String attributeAnnotations, String[] excludeAnnotations) { List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>(); for (JavaPersistentAttribute attribute : jpt.getAttributes()) { HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute); - if (annotations.contains(attributeAnnotations)) { + if (annotations.contains(attributeAnnotations) && canAddAttribute(annotations, excludeAnnotations)) { attributes.add(attribute); } } addAttributes(containerShape, attributes); } + private boolean canAddAttribute(HashSet<String> annotations, String[] excludeAnnotations){ + if(excludeAnnotations == null || excludeAnnotations.length == 0) + return true; + for(String annotation : excludeAnnotations){ + if(annotations.contains(annotation)) + return false; + } + + return true; + } + private void addBasicAttributes(ContainerShape containerShape, JavaPersistentType jpt){ List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>(); @@ -303,7 +314,7 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature { HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute); if(!(annotations.contains(JPAEditorConstants.ANNOTATION_ID))&& !(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY))&& - !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) || annotations.isEmpty()){ + !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)) || annotations.isEmpty()){ attributes.add(attribute); } } @@ -437,4 +448,4 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature { graphicalAdd.add(addContext); } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java index ad8216d..5f30051 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java @@ -21,6 +21,7 @@ import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.R import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_MANY; import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_ONE; +import java.util.HashSet; import java.util.List; import org.eclipse.emf.transaction.RecordingCommand; @@ -51,6 +52,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; import org.eclipse.swt.graphics.Point; @@ -210,18 +212,30 @@ public class AddRelationFeature extends AbstractAddFeature { } JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName()); owner.update(); - JavaAttributeMapping mapping = owner.getMapping(); - a = (OneToOneAnnotation)mapping.getMappingAnnotation(); - if (a == null) - return; - optional = a.getOptional(); - isOptional = (optional == null) ? true : optional.booleanValue(); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); + HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(owner); + if(isDerivedId(annotations)){ + isOptional = false; + } else { + JavaAttributeMapping mapping = owner.getMapping(); + a = (OneToOneAnnotation) mapping.getMappingAnnotation(); + if (a == null) + return; + optional = a.getOptional(); + isOptional = (optional == null) ? true : optional.booleanValue(); + } + imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0); + imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); if (!UNI.equals(direction)) { - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0); + imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0); } } + + private boolean isDerivedId(HashSet<String> annotations){ + if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){ + return true; + } + return false; + } private void addOneToManyTextDecorator(FreeFormConnection c, IRelation rel) { imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_ONE, 0.0); @@ -230,15 +244,23 @@ public class AddRelationFeature extends AbstractAddFeature { } private void addManyToOneTextDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { + boolean isOptional = false; imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 0.0); imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName()); - JavaAttributeMapping mapping = owner.getMapping(); - ManyToOneAnnotation a = (ManyToOneAnnotation)mapping.getMappingAnnotation(); - if (a == null) - return; - Boolean optional = a.getOptional(); - boolean isOptional = (optional == null) ? true : optional.booleanValue(); + + HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(owner); + if(isDerivedId(annotations)){ + isOptional = false; + } else { + JavaAttributeMapping mapping = owner.getMapping(); + ManyToOneAnnotation a = (ManyToOneAnnotation) mapping.getMappingAnnotation(); + if (a == null) + return; + Boolean optional = a.getOptional(); + isOptional = (optional == null) ? true : optional.booleanValue(); + } + imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0); diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java index 506e4a4..578b1b9 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java @@ -16,7 +16,11 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; import java.text.MessageFormat; +import java.util.HashSet; +import java.util.ListIterator; +import java.util.Set; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IContext; import org.eclipse.graphiti.features.context.IDeleteContext; @@ -24,9 +28,22 @@ import org.eclipse.graphiti.internal.features.context.impl.base.PictogramElement import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; +import org.eclipse.jdt.core.IType; +import org.eclipse.jpt.common.core.resource.java.Annotation; +import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor; +import org.eclipse.jpt.common.utility.command.Command; +import org.eclipse.jpt.jpa.core.JpaProjectManager; +import org.eclipse.jpt.jpa.core.context.PersistentType; +import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; +import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.command.DeleteAttributeCommand; import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; @@ -43,9 +60,7 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature { protected String getQuestionToUser() { return MessageFormat.format(JPAEditorMessages.ClickRemoveAttributeButtonFeature_deleteAttributeQuestion, new Object[] {attrName}); } - - - @Override + public boolean canUndo(IContext context) { return false; } @@ -58,9 +73,10 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature { } private void deleteAttribute(ContainerShape pe, String attrName) { - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe.getContainer().getContainer()); + JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe.getContainer().getContainer()); + deleteFieldFromCompositePKClass(attrName, jpt); JpaArtifactFactory.instance().deleteAttribute(jpt, attrName, getFeatureProvider()); - } + } @Override public void delete(IDeleteContext context) { @@ -83,12 +99,13 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature { if (!getUserDecision(context)) { return; } - } + } preDelete(context); if (textShape.getGraphicsAlgorithm() == null){ return; - } + } + deleteAttribute(textShape, attrName); } @@ -122,5 +139,155 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature { return (IJPAEditorFeatureProvider)super.getFeatureProvider(); } + /** + * Returns a collection of java persistent types, that have an embedded id attribute of type, the given + * fully qualified name, or an id class annotation with the given fully qualified name. + * @param jpt - the java persistent type from which the attribute is originally deleted + * @param fqn - te fully qualified name of the composite primary key class + * @return a collection of java persistent types that uses the same composite primary key class. + */ + private Set<JavaPersistentType> getAllJPTWithSameIDClassOrEmbeddedId(JavaPersistentType jpt, String fqn){ + HashSet<JavaPersistentType> persistentTypes = new HashSet<JavaPersistentType>(); + ListIterator<PersistenceUnit> lit = jpt.getJpaProject().getRootContextNode().getPersistenceXml().getRoot().getPersistenceUnits().iterator(); + PersistenceUnit pu = lit.next(); + for(PersistentType persistentType : pu.getPersistentTypes()){ + if(!persistentType.equals(jpt) && ((hasSameEmbeddedId((JavaPersistentType) persistentType, fqn)) || hasSameIdClass((JavaPersistentType) persistentType, fqn))){ + persistentTypes.add((JavaPersistentType) persistentType); + } + } + return persistentTypes; + } + + /** + * Checks whether the given java persistent type has an id class annotation with the + * given fully qualified name. + * @param jpt - the java persistent type to be checked + * @param fqn - the fully qualified name of the id class + * @return true if the java persistent type has an id class annotation with the given + * fully qualified name, false otherwise. + */ + private boolean hasSameIdClass(JavaPersistentType jpt, String fqn){ + JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance(); + if(jpaFactory.hasIDClassAnnotation(jpt) && jpaFactory.getIdType(jpt).equals(fqn)){ + return true; + } + + return false; + } + + /** + * Checks whether the given java persistent type has an embedded id attribute of type, + * the given fully qualified name. + * @param jpt - the java persistent type to be checked + * @param fqn - the fully qualified name of the embedded id attribute's type + * @return true, if the java persistent type has an embedded id attribute with the + * given fully qualified name. + */ + private boolean hasSameEmbeddedId(JavaPersistentType jpt, String fqn){ + JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance(); + for(JavaPersistentAttribute jpa : ((JavaPersistentType)jpt).getAttributes()){ + if(jpaFactory.isEmbeddedId(jpa) && JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa).equals(fqn)){ + return true; + } + } -}
\ No newline at end of file + return false; + } + + /** + * Checks whether the attribute which is going to be deleted is mapped as derived id. + * If yes, finds the helper attribute/field in the composite primary key class and if + * it is not used by another entity, deletes it too. + * @param attrName - the name of the attribute which is going to be deleted + * @param jpt - the java persistent type from which the attribute is originally deleted + */ + private void deleteFieldFromCompositePKClass(String attrName, + JavaPersistentType jpt) { + JavaPersistentAttribute jpa = jpt.getAttributeNamed(attrName); + HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa); + if(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) || annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)){ + if(annotations.contains(JPAEditorConstants.ANNOTATION_ID)){ + deleteFieldFromIdClassCompositePK(attrName, jpt); + } else if(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){ + deleteFieldFromEmbeddedIDCompositePK(jpt, jpa); + } + } + } + + /** + * By the maps id annotation value, find the attribute which has to be deleted from the + * embeddable class and deletes it. + * @param jpt - the java persistent type from which the attribute is originally deleted + * @param jpa - the attribute to be deleted + */ + private void deleteFieldFromEmbeddedIDCompositePK(JavaPersistentType jpt, + JavaPersistentAttribute jpa) { + Annotation ann = jpa.getResourceAttribute().getAnnotation(MapsId2_0Annotation.ANNOTATION_NAME); + if(ann != null) { + String attribName = ((MapsId2_0Annotation)ann).getValue(); + if(attribName == null) + return; + JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance(); + for(JavaPersistentAttribute jpa1 : jpt.getAttributes()){ + if(jpaFactory.isEmbeddedId(jpa1)){ + String fqn = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa1); + if(isDeleteAttributeAllowed(jpt, fqn)){ + JavaPersistentType embeddedJPT = jpaFactory.getContextPersistentType(jpt.getJpaProject(), fqn); + jpaFactory.deleteAttribute(embeddedJPT, attribName, getFeatureProvider()); + } + } + } + } + } + + /** + * Deletes the field with the given name from the id class. + * @param attrName - the name of the field to be deleted + * @param jpt - the java persistent type from which the attribute is originally deleted + */ + private void deleteFieldFromIdClassCompositePK(String attrName, + JavaPersistentType jpt) { + JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance(); + String idClassFQN = jpaFactory.getIdType(jpt); + if(idClassFQN != null && isDeleteAttributeAllowed(jpt, idClassFQN)){ + IType type = jpaFactory.getType(jpt.getJpaProject().getJavaProject(), idClassFQN); + Command deleteAttributeCommand = new DeleteAttributeCommand(type.getCompilationUnit(), null, attrName, getFeatureProvider()); + try { + getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance()); + } catch (InterruptedException e) { + JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attrName, e); //$NON-NLS-1$ + } + } + } + + /** + * Finds all java persistent types, which either has attribute, mapped as embedded id and + * type, the given fully qualified name, or has an id class with the given fully qualified name. + * Then for each one java persistent type, checks whether it has an derived id. If at least one + * java persistent type has an derived id, then the method returns false. The method return true, + * if there isn't any java persistent type that has an derived identifier. + * @param jpt - the java persistent type, from which the attribute is originally deleted + * @param fqn - the fully qualified name of the composite primary key class + * @return true, if there isn't any java persistent type, that has a composite primary key class + * with the given fully qualified name and an derived identifiers; false - if there is at least + * one java persistent type with composite primary class, that has an derived id. + */ + private boolean isDeleteAttributeAllowed(JavaPersistentType jpt, String fqn){ + Set<JavaPersistentType> jpts = getAllJPTWithSameIDClassOrEmbeddedId(jpt, fqn); + for(JavaPersistentType perType : jpts){ + for(JavaPersistentAttribute jpa : perType.getAttributes()){ + HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa); + if((annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) || annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) && + (annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID))){ + return false; + } + + } + } + return true; + } + + private JpaProjectManager getJpaProjectManager() { + return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class); + } +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java index 79d040f..817d7eb 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java @@ -22,7 +22,7 @@ abstract class CreateManyToManyRelationFeature extends CreateRelationFeature { public CreateManyToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); + super(fp, name, description, false); } } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java index dfcb764..54cb460 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java @@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelationFeature implements ICreateBiDirRelationFeature { - - public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) { + + public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { super(fp, JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, - JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureDescription); + JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureDescription, isDerivedIdFeature); } @Override @@ -56,13 +56,15 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName); String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2); - ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity); + ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity, isDerivedIdFeature); return rel; } - - @Override - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR; + + public String getCreateImageId() { + if(isDerivedIdFeature) { + return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_KEY_DIR; + } + return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR; } @Override @@ -84,4 +86,4 @@ public class CreateManyToOneBiDirRelationFeature extends CreateManyToOneRelation } return true; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java index 1f1c9ec..18c4e39 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java @@ -20,8 +20,8 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr abstract class CreateManyToOneRelationFeature extends CreateRelationFeature { - public CreateManyToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); + public CreateManyToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description, boolean isDerivedIdFeature) { + super(fp, name, description, isDerivedIdFeature); } } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java index b484045..102366c 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java @@ -33,9 +33,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelationFeature implements ICreateUniDirRelationFeature { - public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) { + + public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { super(fp, JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName, - JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureDescription); + JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureDescription, isDerivedIdFeature); } @Override @@ -48,12 +49,14 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName); String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true); + ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true, isDerivedIdFeature); return relation; } - @Override - public String getCreateImageId() { + public String getCreateImageId() { + if(isDerivedIdFeature) { + return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_KEY_DIR; + } return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_DIR; } @@ -77,4 +80,4 @@ public class CreateManyToOneUniDirRelationFeature extends CreateManyToOneRelatio return true; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java index a448461..58b58b4 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java @@ -27,7 +27,7 @@ abstract class CreateOneToManyRelationFeature extends CreateRelationFeature { public CreateOneToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); + super(fp, name, description, false); } /* (non-Javadoc) diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java index 98376cb..b082a47 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java @@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFeature implements ICreateBiDirRelationFeature { - - public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) { + + public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { super(fp, JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, - JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureDescription); + JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureDescription, isDerivedIdFeature); } @Override @@ -56,12 +56,14 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName); String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2); - OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity); + OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, embeddingEntity, isDerivedIdFeature); return rel; } - @Override - public String getCreateImageId() { + public String getCreateImageId() { + if(isDerivedIdFeature) { + return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_KEY_DIR; + } return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_DIR; } @@ -87,4 +89,4 @@ public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFe } return true; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java index f4b9fea..713aeef 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java @@ -20,7 +20,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr abstract class CreateOneToOneRelationFeature extends CreateRelationFeature { - public CreateOneToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); + public CreateOneToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description , boolean isDerivedIdFeature) { + super(fp, name, description, isDerivedIdFeature); } } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java index d38c03b..bcc7831 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java @@ -32,10 +32,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationFeature implements ICreateUniDirRelationFeature { - - public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) { + + public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { super(fp, JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, - JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription); + JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription, isDerivedIdFeature); } @Override @@ -50,12 +50,14 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name); String attribTxt = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true); + OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true, isDerivedIdFeature); return res; } - @Override - public String getCreateImageId() { + public String getCreateImageId() { + if(isDerivedIdFeature) { + return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_KEY_DIR; + } return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_DIR; } @@ -81,4 +83,4 @@ public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationF } return true; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java index 33c637b..d55b3ec 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java @@ -42,9 +42,12 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature { protected JavaPersistentType owner; + + protected boolean isDerivedIdFeature; - public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { + public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description, boolean isDerivedIdFeature) { super(fp, name, description); + this.isDerivedIdFeature = isDerivedIdFeature; } public boolean canCreate(ICreateConnectionContext context) { @@ -63,6 +66,10 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat if ((this instanceof ICreateBiDirRelationFeature) && (JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner))) return false; + if(isDerivedIdFeature && (!JpaArtifactFactory.instance().hasEntityAnnotation(owner) + || !JpaArtifactFactory.instance().hasEntityAnnotation(inverse))){ + return false; + } return true; } @@ -183,14 +190,14 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat disableAllJPTsThatAreNotEntities(unit); } else if(JpaArtifactFactory.instance().hasMappedSuperclassAnnotation(owner)){ - if (this instanceof ICreateBiDirRelationFeature){ + if (isDerivedIdFeature || (this instanceof ICreateBiDirRelationFeature)){ disableAllPersistentTypes(unit); } else { disableAllJPTsThatAreNotEntities(unit); } } else if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)) { - if(!isRelationshipPossible() || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) { + if(isDerivedIdFeature || !isRelationshipPossible() || JPAEditorUtil.checkJPAFacetVersion(owner.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) { disableAllPersistentTypes(unit); } else { disableAllJPTsThatAreNotEntities(unit); @@ -240,12 +247,12 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat PersistenceUnit unit = project.getRootContextNode().getPersistenceXml(). getRoot().getPersistenceUnits().iterator().next(); boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()), JPAEditorUtil.JPA_PROJECT_FACET_10); - if(!isJPA10Project) - return; + for (ClassRef classRef : unit.getClassRefs()) { if (classRef.getJavaPersistentType() != null) { final JavaPersistentType jpt = classRef.getJavaPersistentType(); - if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt)){ + if((isJPA10Project && JpaArtifactFactory.instance().hasEmbeddableAnnotation(jpt)) + || (isDerivedIdFeature && !JpaArtifactFactory.instance().hasEntityAnnotation(jpt))){ getFeatureProvider().setGrayColor(jpt); } @@ -267,4 +274,4 @@ abstract public class CreateRelationFeature extends AbstractCreateConnectionFeat } return false; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java index 0889fd5..ce12bb1 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java @@ -74,12 +74,14 @@ public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature { private ContainerShape addAttributeToProperlyShape(ContainerShape entityShape, String txt, HashSet<String> annots, ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) { ContainerShape textShape = null; - if (annots.contains(JPAEditorConstants.ANNOTATION_ID) || annots.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) { + if (annots.contains(JPAEditorConstants.ANNOTATION_ID) || annots.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID) + || annots.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)) { textShape = addAttributeToShape(entityShape, txt, annots, primaryShape); - } else if (annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY) + } else if (!annots.contains(JPAEditorConstants.ANNOTATION_ID) && !annots.contains(JPAEditorConstants.ANNOTATION_MAPS_ID) + && (annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY) || annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE) || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY) - || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { + || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE))) { textShape = addAttributeToShape(entityShape, txt, annots, relationShape); } else { textShape = addAttributeToShape(entityShape, txt, annots, basicShape); @@ -142,4 +144,4 @@ public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature { public boolean canAdd(IAddContext context) { return false; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java index 40a65fb..4d5e954 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.Set; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; + import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; @@ -72,7 +73,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature { protected Set<JavaPersistentAttribute> ats = null; protected boolean hasNameAnnotation = false; - + public RefactorEntityFeature(IFeatureProvider fp) { super(fp); } @@ -111,10 +112,10 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature { } public void execute(ICustomContext context, SelectionDispatchAction action) { - final Shape pict = (Shape)context.getInnerPictogramElement(); + PictogramElement pe = context.getInnerPictogramElement(); + final ContainerShape pict = ((Shape)pe).getContainer(); + JavaPersistentType jpt = (JavaPersistentType)getBusinessObjectForPictogramElement(pict); - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider(). - getBusinessObjectForPictogramElement(pict); ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); StructuredSelection sel = new StructuredSelection(cu); @@ -145,7 +146,7 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature { protected void doExecute() { remapEntity(oldName, pict, pu, rename, lsnr, dot, getFeatureProvider()); } - }); + }); } public void execute(ICustomContext context, String newName, ICompilationUnit cu, JavaPersistentType jpt) { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java index 769824a..1c90f37 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/JPAEditorMessages.java @@ -187,6 +187,8 @@ public class JPAEditorMessages extends NLS { public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel; public static String JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription; + + public static String JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle; public static String JPAEditorToolBehaviorProvider_expandAttrMenuItem; public static String JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr; diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties index 19919cc..c6d1c98 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/i18n/messages.properties @@ -154,6 +154,7 @@ JPAEditorToolBehaviorProvider_openMiniatureViewDesc=Open the Miniature view to d JPAEditorToolBehaviorProvider_CompositionPaletteName=Composition JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonLabel=Create Collection Attribute JPAEditorToolBehaviorProvider_CreateElementCollectionAttributeButtonDescription=Create a new attribute of a basic collection type in the persistent type. +JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle=Derived Identifiers JPAEditorToolBehaviorProvider_expandAttrMenuItem=Expand Attributes Group JPAEditorToolBehaviorProvider_expandAttrMenuItemDescr=Expand the attributes group. JPAEditorToolBehaviorProvider_expandCompartToolTip=Double click to expand "{0}" attributes group. diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java index ba097b2..011c46a 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorFeatureProvider.java @@ -414,11 +414,11 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements @Override public ICreateConnectionFeature[] getCreateConnectionFeatures() { return new ICreateConnectionFeature[] { - new CreateOneToOneUniDirRelationFeature(this), - new CreateOneToOneBiDirRelationFeature(this), + new CreateOneToOneUniDirRelationFeature(this, false), + new CreateOneToOneBiDirRelationFeature(this, false), new CreateOneToManyUniDirRelationFeature(this), - new CreateManyToOneUniDirRelationFeature(this), - new CreateManyToOneBiDirRelationFeature(this), + new CreateManyToOneUniDirRelationFeature(this, false), + new CreateManyToOneBiDirRelationFeature(this, false), new CreateManyToManyUniDirRelationFeature(this), new CreateManyToManyBiDirRelationFeature(this) }; @@ -635,7 +635,7 @@ public class JPAEditorFeatureProvider extends DefaultFeatureProvider implements } public boolean doesEmbeddedRelationExist(JavaPersistentType embeddable, JavaPersistentType embeddingEntity, String embeddedAttributeName, HasReferenceType relType){ - String id = HasReferanceRelation.generateId(embeddable, embeddingEntity, embeddedAttributeName, relType); + String id = HasReferanceRelation.generateId(embeddingEntity, embeddable, embeddedAttributeName, relType); return (getBusinessObjectForKey(id) != null); } diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java index e629105..19d89a5 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorImageProvider.java @@ -31,6 +31,8 @@ public class JPAEditorImageProvider extends AbstractImageProvider { public static final String ADD_EMBEDDABLE = PREFIX + "add_embeddable"; //$NON-NLS-1$ public static final String PRIMARY_KEY = PREFIX + "pk"; //$NON-NLS-1$ + public static final String ONE_TO_ONE_PRIMARY_KEY = PREFIX + "one_to_one_pk"; //$NON-NLS-1$ + public static final String MANY_TO_ONE_PRIMARY_KEY = PREFIX + "many_to_one_pk"; //$NON-NLS-1$ public static final String ICON_BASIC = PREFIX + "field"; //$NON-NLS-1$ public static final String ADD_ATTRIBUTE = PREFIX + "add_attribute"; //$NON-NLS-1$ public static final String ADD_ELEMENT_COLLECTION = PREFIX + "add_element-collection.gif"; //$NON-NLS-1$ @@ -47,6 +49,10 @@ public class JPAEditorImageProvider extends AbstractImageProvider { public static final String ICON_UNMAPPED = PREFIX + "unmapped"; //$NON-NLS-1$ public static final String ICON_DERIVE_JPT = PREFIX + "derive_jpt"; //$NON-NLS-1$ + public static final String ICON_ONE_TO_ONE_1_KEY_DIR = PREFIX + "one_to_one_1_key_relation"; //$NON-NLS-1$ + public static final String ICON_ONE_TO_ONE_2_KEY_DIR = PREFIX + "one_to_one_2_key_relation"; //$NON-NLS-1$ + public static final String ICON_MANY_TO_ONE_1_KEY_DIR = PREFIX + "many_to_one_1_key_relation"; //$NON-NLS-1$ + public static final String ICON_MANY_TO_ONE_2_KEY_DIR = PREFIX + "many_to_one_2_key_relation"; //$NON-NLS-1$ public static final String ICON_ONE_TO_ONE_1_DIR = PREFIX + "one_to_one_1_dir_relation"; //$NON-NLS-1$ public static final String ICON_ONE_TO_MANY_1_DIR = PREFIX + "one_to_many_1_dir_relation"; //$NON-NLS-1$ @@ -79,6 +85,9 @@ public class JPAEditorImageProvider extends AbstractImageProvider { addImageFilePath(ADD_MAPPED_SUPERCLASS, ROOT_FOLDER_FOR_IMG + "ent/add_mapped-superclass.gif"); //$NON-NLS-1$ addImageFilePath(ADD_EMBEDDABLE, ROOT_FOLDER_FOR_IMG + "ent/add_embeddable.gif"); //$NON-NLS-1$ addImageFilePath(PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/id.gif"); //$NON-NLS-1$ + addImageFilePath(ONE_TO_ONE_PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-key.gif"); //$NON-NLS-1$ + addImageFilePath(MANY_TO_ONE_PRIMARY_KEY, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-key.gif"); //$NON-NLS-1$ + addImageFilePath(ADD_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/add_attribute.gif"); //$NON-NLS-1$ addImageFilePath(ADD_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/add_element-collection.gif"); //$NON-NLS-1$ addImageFilePath(REMOVE_ATTRIBUTE, ROOT_FOLDER_FOR_IMG + "ent/remove_attribute.gif"); //$NON-NLS-1$ @@ -93,6 +102,11 @@ public class JPAEditorImageProvider extends AbstractImageProvider { addImageFilePath(ICON_ELEMENT_COLLECTION, ROOT_FOLDER_FOR_IMG + "ent/element-collection.gif"); //$NON-NLS-1$ addImageFilePath(ICON_UNMAPPED, ROOT_FOLDER_FOR_IMG + "ent/null-attribute-mapping.gif"); //$NON-NLS-1$ addImageFilePath(ICON_DERIVE_JPT, ROOT_FOLDER_FOR_IMG + "ent/derive_jpt.gif"); //$NON-NLS-1$ + + addImageFilePath(ICON_ONE_TO_ONE_1_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-key.gif"); //$NON-NLS-1$ + addImageFilePath(ICON_ONE_TO_ONE_2_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-2-key.gif"); //$NON-NLS-1$ + addImageFilePath(ICON_MANY_TO_ONE_1_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-1-key.gif"); //$NON-NLS-1$ + addImageFilePath(ICON_MANY_TO_ONE_2_KEY_DIR, ROOT_FOLDER_FOR_IMG + "ent/many-to-one-2-key.gif"); //$NON-NLS-1$ addImageFilePath(ICON_ONE_TO_ONE_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-one-1-dir.gif"); //$NON-NLS-1$ addImageFilePath(ICON_ONE_TO_MANY_1_DIR, ROOT_FOLDER_FOR_IMG + "ent/one-to-many-1-dir.gif"); //$NON-NLS-1$ diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java index 4511839..6423eb1 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/provider/JPAEditorToolBehaviorProvider.java @@ -73,6 +73,10 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseCompartmentS import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CollapseEntityFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateInheritedEntityFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateIsARelationFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneBiDirRelationFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneUniDirRelationFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneBiDirRelationFeature; +import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneUniDirRelationFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DiscardAndRemoveAllEntitiesFeature; import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.EmbedCollectionOfObjectsFeature; @@ -258,14 +262,58 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { createInheritancePaletteSection(ret, superCompartments); + if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) { + createDerivedIdentifiersPalleteSection(ret, superCompartments); + } + createCompositionPaletteSection(ret, superCompartments); return ret.toArray(new IPaletteCompartmentEntry[ret.size()]); } + + private void createDerivedIdentifiersPalleteSection(List<IPaletteCompartmentEntry> ret, + IPaletteCompartmentEntry[] superCompartments){ + PaletteCompartmentEntry compositionEnt = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_DerivedIdentifiersPalleteTitle, superCompartments[1].getIconId()); + + CreateOneToOneUniDirRelationFeature oneToOneUniDirPkFt = new CreateOneToOneUniDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true); + ConnectionCreationToolEntry oneToOneUniDirPkToolEntry = new ConnectionCreationToolEntry(oneToOneUniDirPkFt.getCreateName(), + oneToOneUniDirPkFt.getCreateDescription(), oneToOneUniDirPkFt.getCreateImageId(), oneToOneUniDirPkFt.getCreateLargeImageId()); + oneToOneUniDirPkToolEntry.addCreateConnectionFeature(oneToOneUniDirPkFt); + compositionEnt.addToolEntry(oneToOneUniDirPkToolEntry); + + CreateOneToOneBiDirRelationFeature oneToOneBiDirPkFt = new CreateOneToOneBiDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true); + ConnectionCreationToolEntry oneToOneBiDirPkToolEntry = new ConnectionCreationToolEntry(oneToOneBiDirPkFt.getCreateName(), + oneToOneBiDirPkFt.getCreateDescription(), oneToOneBiDirPkFt.getCreateImageId(), oneToOneBiDirPkFt.getCreateLargeImageId()); + oneToOneBiDirPkToolEntry.addCreateConnectionFeature(oneToOneBiDirPkFt); + compositionEnt.addToolEntry(oneToOneBiDirPkToolEntry); + + CreateManyToOneUniDirRelationFeature manyToOneUniDirPkFt = new CreateManyToOneUniDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true); + ConnectionCreationToolEntry manyToOneUniDirPkToolEntry = new ConnectionCreationToolEntry(manyToOneUniDirPkFt.getCreateName(), + manyToOneUniDirPkFt.getCreateDescription(), manyToOneUniDirPkFt.getCreateImageId(), manyToOneUniDirPkFt.getCreateLargeImageId()); + manyToOneUniDirPkToolEntry.addCreateConnectionFeature(manyToOneUniDirPkFt); + compositionEnt.addToolEntry(manyToOneUniDirPkToolEntry); + + CreateManyToOneBiDirRelationFeature manyToOneBiDirPkFt = new CreateManyToOneBiDirRelationFeature((IJPAEditorFeatureProvider) this.getFeatureProvider(), true); + ConnectionCreationToolEntry manyToOneBiDirPkToolEntry = new ConnectionCreationToolEntry(manyToOneBiDirPkFt.getCreateName(), + manyToOneBiDirPkFt.getCreateDescription(), manyToOneBiDirPkFt.getCreateImageId(), manyToOneBiDirPkFt.getCreateLargeImageId()); + manyToOneBiDirPkToolEntry.addCreateConnectionFeature(manyToOneBiDirPkFt); + compositionEnt.addToolEntry(manyToOneBiDirPkToolEntry); + + ret.add(2, compositionEnt); + } private void createCompositionPaletteSection( List<IPaletteCompartmentEntry> ret, IPaletteCompartmentEntry[] superCompartments) { + int index; + boolean isJPA10Project = JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10); + + if(isJPA10Project) { + index = 2; + } else { + index = 3; + } + PaletteCompartmentEntry compositionEnt = new PaletteCompartmentEntry(JPAEditorMessages.JPAEditorToolBehaviorProvider_CompositionPaletteName, superCompartments[1].getIconId()); EmbedSingleObjectFeature embedObjectFt = new EmbedSingleObjectFeature(this.getFeatureProvider()); @@ -274,7 +322,7 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { isEmbeddedObjectToolEntry.addCreateConnectionFeature(embedObjectFt); compositionEnt.addToolEntry(isEmbeddedObjectToolEntry); - if(!JPAEditorUtil.checkJPAFacetVersion(getTargetJPAProject(), JPAEditorUtil.JPA_PROJECT_FACET_10)) { + if(!isJPA10Project) { EmbedCollectionOfObjectsFeature embedCollectionFt = new EmbedCollectionOfObjectsFeature(this.getFeatureProvider()); ConnectionCreationToolEntry isEmbeddedCollectionToolEntry = new ConnectionCreationToolEntry(embedCollectionFt.getCreateName(), embedCollectionFt.getCreateDescription(), embedCollectionFt.getCreateImageId(), embedCollectionFt.getCreateLargeImageId()); @@ -282,7 +330,7 @@ public class JPAEditorToolBehaviorProvider extends DefaultToolBehaviorProvider { compositionEnt.addToolEntry(isEmbeddedCollectionToolEntry); } - ret.add(2, compositionEnt); + ret.add(index, compositionEnt); } private JpaProject getTargetJPAProject() { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java index 03cbc2c..90fe21d 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java @@ -29,12 +29,13 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir JavaPersistentType inverse, String ownerAttributeName, String inverseAttributeName, - boolean createAttribs, JavaPersistentType embeddingEntity) { + boolean createAttribs, JavaPersistentType embeddingEntity, + boolean isDerivedIdFeature) { super(owner, inverse); this.ownerAttributeName = ownerAttributeName; this.inverseAttributeName = inverseAttributeName; if (createAttribs) - createRelation(fp, embeddingEntity); + createRelation(fp, embeddingEntity, isDerivedIdFeature); } @@ -58,9 +59,12 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir this.inverseAnnotatedAttribute = inverseAnnotatedAttribute; } - private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) { + private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity, boolean isDerivedIdFeature) { ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null); - + if(isDerivedIdFeature){ + JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute); + } + boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()); String mapKeyType = getMapKeyType(isMap, owner, embeddingEntity); if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){ @@ -70,7 +74,7 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, true, mapKeyType); } JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap); - } + } @Override public RelDir getRelDir() { @@ -83,4 +87,5 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir } return isMap ? JpaArtifactFactory.instance().getIdType(jpt) : null; } -}
\ No newline at end of file + +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java index 778cbc0..1823add 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java @@ -27,11 +27,11 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi public ManyToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, JavaPersistentType inverse, String ownerAttributeName, - boolean createAttribs) { + boolean createAttribs, boolean isDerivedIdFeature) { super(owner, inverse); this.ownerAttributeName = ownerAttributeName; if (createAttribs) - createRelation(fp); + createRelation(fp, isDerivedIdFeature); } public JavaPersistentAttribute getAnnotatedAttribute() { @@ -42,8 +42,11 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi this.ownerAnnotatedAttribute = annotatedAttribute; } - private void createRelation(IJPAEditorFeatureProvider fp) { + private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null); + if(isDerivedIdFeature){ + JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute); + } JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute); } @@ -53,4 +56,4 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidi return RelDir.UNI; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java index 79ae9c0..264c8ad 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java @@ -27,12 +27,13 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect JavaPersistentType inverse, String ownerAttributeName, String inverseAttributeName, - boolean createAttribs, JavaPersistentType embeddingEntity) { + boolean createAttribs, JavaPersistentType embeddingEntity, + boolean isDerivedIdFeature) { super(owner, inverse); this.ownerAttributeName = ownerAttributeName; this.inverseAttributeName = inverseAttributeName; if (createAttribs) - createRelation(fp, embeddingEntity); + createRelation(fp, embeddingEntity, isDerivedIdFeature); } @Override @@ -57,8 +58,11 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect this.inverseAnnotatedAttribute = inverseAnnotatedAttribute; } - private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity) { + private void createRelation(IJPAEditorFeatureProvider fp, JavaPersistentType embeddingEntity, boolean isDerivedIdFeature) { ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null); + if(isDerivedIdFeature){ + JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute); + } if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(owner)){ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, embeddingEntity, false, null); @@ -72,4 +76,4 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect public RelDir getRelDir() { return RelDir.BI; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java index 6371bbf..02e45e5 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java @@ -27,11 +27,11 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire public OneToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner, JavaPersistentType inverse, String ownerAttributeName, - boolean createAttribs) { + boolean createAttribs, boolean isDerivedIdFeature) { super(owner, inverse); this.ownerAttributeName = ownerAttributeName; if (createAttribs) - createRelation(fp); + createRelation(fp, isDerivedIdFeature); } public JavaPersistentAttribute getAnnotatedAttribute() { @@ -42,8 +42,11 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire this.ownerAnnotatedAttribute = annotatedAttribute; } - private void createRelation(IJPAEditorFeatureProvider fp) { + private void createRelation(IJPAEditorFeatureProvider fp, boolean isDerivedIdFeature) { ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, false, null); + if(isDerivedIdFeature){ + JpaArtifactFactory.instance().calculateDerivedIdAnnotation(owner, inverse, ownerAnnotatedAttribute); + } JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute); } @@ -52,4 +55,4 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidire return RelDir.UNI; } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java index 7e76a45..80e9c85 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java @@ -148,6 +148,7 @@ public class JPAEditorConstants { public final static String ANNOTATION_ELEMENT_COLLECTION = "ElementCollection"; //$NON-NLS-1$ public final static String ANNOTATION_EMBEDDED_ID = "EmbeddedId"; //$NON-NLS-1$ public final static String ANNOTATION_TRANSIENT = "Transient"; //$NON-NLS-1$ + public final static String ANNOTATION_MAPS_ID = "MapsId"; //$NON-NLS-1$ public static final int RELATION_TYPE_UNIDIRECTIONAL = 1; public static final int RELATION_TYPE_BIDIRECTIONAL = 2; diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java index c7408ae..76a314f 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java @@ -405,14 +405,24 @@ public class JPAEditorUtil { Image icon = null; if ((annotations == null) || (annotations.size() == 0) || annotations.contains(JPAEditorConstants.ANNOTATION_BASIC)) { icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_BASIC); - } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ID)) { + } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ID) && + !annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) && + !annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) { icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.PRIMARY_KEY); - } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { - icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_ONE); + } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE) ) { + if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){ + icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ONE_TO_ONE_PRIMARY_KEY); + } else { + icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_ONE); + } } else if (annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)) { icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_ONE_TO_MANY); - } else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) { - icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_ONE); + } else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)){ + if(annotations.contains(JPAEditorConstants.ANNOTATION_ID) || annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID)){ + icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.MANY_TO_ONE_PRIMARY_KEY); + } else { + icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_ONE); + } } else if (annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) { icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_MANY_TO_MANY); } else if(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)){ diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java index bf280b3..be28b9b 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java @@ -435,7 +435,12 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver { private String findRelationshipKey(JavaPersistentAttribute jpa, IJPAEditorFeatureProvider fp){ JpaArtifactFactory jpaFactory = JpaArtifactFactory.instance(); if(jpaFactory.isEmbeddedAttribute(jpa)){ - JavaPersistentType embeddableClass = jpaFactory.findJPT(jpa, fp, JpaArtifactFactory.instance().getAnnotations(jpa)[0]); + Annotation embeddedAn = null; + Annotation[] anns = JpaArtifactFactory.instance().getAnnotations(jpa); + if(anns != null && anns.length > 0){ + embeddedAn = anns[0]; + } + JavaPersistentType embeddableClass = jpaFactory.findJPT(jpa, fp, embeddedAn); if(embeddableClass == null) return ""; //$NON-NLS-1$ for (JavaPersistentAttribute relEntAt : embeddableClass.getAttributes()) { diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java index 402391a..618e58b 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java @@ -44,9 +44,11 @@ import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.util.IColorConstant; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IPackageDeclaration; import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.JptResourceModel; @@ -76,8 +78,10 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping; import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation; import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation; import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation; import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation; @@ -254,7 +258,7 @@ public class JpaArtifactFactory { String mappedByAttr = getMappeByAttribute(fp, manySideJPT, manySideAttribute); setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, mappedByAttr); } else { - addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT, fp); + addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT); } if (isMap) singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); @@ -265,8 +269,8 @@ public class JpaArtifactFactory { String mappedByAttr = ownerSideAttribute.getName(); - if(JpaArtifactFactory.instance().hasEmbeddableAnnotation(ownerSideJPT)){ - HasReferanceRelation ref = JpaArtifactFactory.instance().findFisrtHasReferenceRelationByEmbeddable(ownerSideJPT, (IJPAEditorFeatureProvider)fp); + if(hasEmbeddableAnnotation(ownerSideJPT)){ + HasReferanceRelation ref = JpaArtifactFactory.INSTANCE.findFisrtHasReferenceRelationByEmbeddable(ownerSideJPT, (IJPAEditorFeatureProvider)fp); if(ref != null){ JavaPersistentAttribute embeddingAttribute = ref.getEmbeddedAnnotatedAttribute(); mappedByAttr = embeddingAttribute.getName() + "." + ownerSideAttribute.getName(); //$NON-NLS-1$ @@ -298,7 +302,7 @@ public class JpaArtifactFactory { } private void addJoinColumnIfNecessary(JavaPersistentAttribute jpa, - JavaPersistentType jpt, IFeatureProvider fp) { + JavaPersistentType jpt) { if (JPAEditorUtil.checkJPAFacetVersion(jpa.getJpaProject(), JPAEditorUtil.JPA_PROJECT_FACET_10) || JPADiagramPropertyPage.shouldOneToManyUnidirBeOldStyle(jpa @@ -345,6 +349,7 @@ public class JpaArtifactFactory { private Hashtable<String, String> getOverriddenColNames( JavaPersistentAttribute embIdAt) { Hashtable<String, String> res = new Hashtable<String, String>(); + if(embIdAt.getResourceAttribute().getAnnotationsSize(AttributeOverrideAnnotation.ANNOTATION_NAME) > 0){ AttributeOverrideAnnotation aon = (AttributeOverrideAnnotation) embIdAt .getResourceAttribute().getAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME); @@ -358,6 +363,7 @@ public class JpaArtifactFactory { res.put(aon.getName(), colName); return res; } + } Iterable<AttributeOverrideAnnotation> it = new SubListIterableWrapper<NestableAnnotation, AttributeOverrideAnnotation>( embIdAt.getResourceAttribute().getAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME)); for (AttributeOverrideAnnotation an : it) { @@ -591,6 +597,32 @@ public class JpaArtifactFactory { } /** + * Finds all java persistent types, which has an attribute, mapped as + * embedded id and type, the fully qualified name of the given embeddable. + * @param embeddable + * @param fp + * @return a collection of all java persistent types, that have an embedded id attribute of + * the given embeddable type. + */ + public HashSet<JavaPersistentType> findAllJPTWithTheGivenEmbeddedId(JavaPersistentType embeddable, IJPAEditorFeatureProvider fp){ + HashSet<JavaPersistentType> embeddingEntities = new HashSet<JavaPersistentType>(); + if(!hasEmbeddableAnnotation(embeddable)) + return embeddingEntities; + ListIterator<PersistenceUnit> lit = embeddable.getJpaProject().getRootContextNode().getPersistenceXml().getRoot().getPersistenceUnits().iterator(); + PersistenceUnit pu = lit.next(); + for(PersistentType jpt : pu.getPersistentTypes()){ + if(!jpt.equals(embeddable)){ + for(JavaPersistentAttribute jpa : ((JavaPersistentType)jpt).getAttributes()){ + if(isEmbeddedId(jpa) && JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa).equals(embeddable.getName())){ + embeddingEntities.add((JavaPersistentType) jpt); + } + } + } + } + return embeddingEntities; + } + + /** * Find the first {@link HasReferenceRelation} for the given embeddable class from all existing * {@link HasReferanceRelation} in the diagram. * @param embeddable - the given embeddable class @@ -759,12 +791,13 @@ public class JpaArtifactFactory { */ public void deleteAttribute(JavaPersistentType jpt, String attributeName, IJPAEditorFeatureProvider fp) { - - Command deleteAttributeCommand = new DeleteAttributeCommand(jpt, attributeName, fp); - try { - getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance()); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attributeName, e); //$NON-NLS-1$ + synchronized (jpt) { + Command deleteAttributeCommand = new DeleteAttributeCommand(null, jpt, attributeName, fp); + try { + getJpaProjectManager().execute(deleteAttributeCommand, SynchronousUiCommandExecutor.instance()); + } catch (InterruptedException e) { + JPADiagramEditorPlugin.logError("Cannot delete attribute with name " + attributeName, e); //$NON-NLS-1$ + } } } @@ -1148,7 +1181,7 @@ public class JpaArtifactFactory { String oldName, String newName, String inverseEntityName, IJPAEditorFeatureProvider fp) throws InterruptedException { newName = JPAEditorUtil.decapitalizeFirstLetter(newName); - if (JpaArtifactFactory.instance().isMethodAnnotated(jpt)) { + if (isMethodAnnotated(jpt)) { newName = JPAEditorUtil.produceValidAttributeName(newName); } newName = JPAEditorUtil.produceUniqueAttributeName(jpt, newName); @@ -1159,7 +1192,7 @@ public class JpaArtifactFactory { .getResourceAttribute(); fp.addRemoveIgnore((JavaPersistentType)oldAt.getParent(), jra.getName()); - Command renameAttributeCommand = new RenameAttributeCommand(jpt, oldName, newName, fp); + Command renameAttributeCommand = new RenameAttributeCommand(null, jpt, oldName, newName, fp); getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandExecutor.instance()); JavaPersistentAttribute newAt = jpt.getAttributeNamed(newName); @@ -1199,8 +1232,41 @@ public class JpaArtifactFactory { Command changeMappedByValueCommand = new SetMappedByNewValueCommand(fp, pu, inverseEntityName, inverseAttributeName, newAt, oldAt, rel); getJpaProjectManager().execute(changeMappedByValueCommand, SynchronousUiCommandExecutor.instance()); } - if (rel != null) + if (rel != null) { updateRelation(jpt, fp, rel); + if(hasIDClassAnnotation(jpt)) { + String idClassFQN = getIdType(jpt); + IJavaProject javaProject = JavaCore.create(jpt.getJpaProject().getProject()); + IType type = getType(javaProject, idClassFQN); + if(type != null && type.getField(oldAt.getName()).exists()){ + Command renameAttributeCommand = new RenameAttributeCommand(type.getCompilationUnit(), null, oldAt.getName(), newAt.getName(), fp); + getJpaProjectManager().execute(renameAttributeCommand, SynchronousUiCommandExecutor.instance()); + } + } + } + + HashSet<JavaPersistentType> embeddingEntities = findAllJPTWithTheGivenEmbeddedId(jpt, fp); + if(embeddingEntities != null && !embeddingEntities.isEmpty()){ + renameMapsIdAnnotationValue(oldAt, newAt, embeddingEntities); + } + + } + + private void renameMapsIdAnnotationValue(JavaPersistentAttribute oldAt, + JavaPersistentAttribute newAt, HashSet<JavaPersistentType> embeddingEntities) { + + for(JavaPersistentType embeddingEntity : embeddingEntities){ + for(JavaPersistentAttribute attr : embeddingEntity.getAttributes()){ + Annotation ann = attr.getResourceAttribute().getAnnotation(MapsId2_0Annotation.ANNOTATION_NAME); + if(ann != null){ + MapsId2_0Annotation mapsIdAnn = (MapsId2_0Annotation) ann; + if(mapsIdAnn.getValue() != null && mapsIdAnn.getValue().equals(oldAt.getName())){ + ((MapsId2_0Annotation)ann).setValue(newAt.getName()); + embeddingEntity.synchronizeWithResourceModel(); + } + } + } + } } @@ -1389,7 +1455,7 @@ public class JpaArtifactFactory { if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_ONE, RelDir.UNI)) - res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false); + res = new OneToOneUniDirRelation(fp, jpt, relJPT, attrName, false, false); } else if (annotationName .equals(JPAEditorConstants.ANNOTATION_ONE_TO_MANY)) { if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.ONE_TO_MANY, @@ -1399,7 +1465,7 @@ public class JpaArtifactFactory { .equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) { if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_ONE, RelDir.UNI)) - res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false); + res = new ManyToOneUniDirRelation(fp, jpt, relJPT, attrName, false, false); } else if (annotationName .equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) { if (!fp.doesRelationExist(jpt, relJPT, attrName, null, RelType.MANY_TO_MANY, @@ -1481,13 +1547,13 @@ public class JpaArtifactFactory { if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.ONE_TO_ONE, RelDir.BI)) res = new OneToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName, - inverseAttrName, false, relJPT); + inverseAttrName, false, relJPT, false); } else if (annotationName .equals(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) { if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_ONE, RelDir.BI)) res = new ManyToOneBiDirRelation(fp, jpt, relJPT, ownerAttrName, - inverseAttrName, false, relJPT); + inverseAttrName, false, relJPT, false); } else if (annotationName .equals(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) { if (!fp.doesRelationExist(jpt, relJPT, ownerAttrName, inverseAttrName, RelType.MANY_TO_MANY, @@ -1710,6 +1776,14 @@ public class JpaArtifactFactory { return (JpaProject) project.getAdapter(JpaProject.class); } + public boolean hasIDClassAnnotation(JavaPersistentType jpt){ + Annotation an = jpt.getJavaResourceType().getAnnotation(IdClassAnnotation.ANNOTATION_NAME); + if(an != null){ + return true; + } + return false; + } + public String getIdType(JavaPersistentType jpt) { IdClassAnnotation an = (IdClassAnnotation)jpt.getJavaResourceType().getAnnotation(IdClassAnnotation.ANNOTATION_NAME); if (an != null) @@ -1725,8 +1799,9 @@ public class JpaArtifactFactory { public JavaPersistentAttribute[] getIds(JavaPersistentType jpt) { ArrayList<JavaPersistentAttribute> res = new ArrayList<JavaPersistentAttribute>(); for (JavaPersistentAttribute at : jpt.getAttributes()) { - if (isId(at)) + if (isId(at)) { res.add(at); + } } JavaPersistentAttribute[] ret = new JavaPersistentAttribute[res.size()]; return res.toArray(ret); @@ -1750,6 +1825,23 @@ public class JpaArtifactFactory { return false; } + private boolean hasSimplePk(JavaPersistentType jpt) { + for(JavaPersistentAttribute at : jpt.getAttributes()){ + if(isSimpleId(at) && !hasIDClassAnnotation(jpt)){ + return true; + } + } + return false; + } + + private JavaPersistentAttribute getSimplePkAttribute(JavaPersistentType jpt){ + for(JavaPersistentAttribute jpa : jpt.getAttributes()){ + if(isSimpleId(jpa)){ + return jpa; + } + } + return null; + } public boolean isId(ReadOnlyPersistentAttribute jpa) { return isSimpleId(jpa) || isEmbeddedId(jpa); @@ -1759,6 +1851,24 @@ public class JpaArtifactFactory { return (jpa.getMappingKey() == MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); } + private boolean hasEmbeddedPk(JavaPersistentType jpt){ + for(JavaPersistentAttribute at : jpt.getAttributes()){ + if(isEmbeddedId(at)){ + return true; + } + } + return false; + } + + private JavaPersistentAttribute getEmbeddedIdAttribute(JavaPersistentType jpt){ + for(JavaPersistentAttribute jpa : jpt.getAttributes()){ + if(isEmbeddedId(jpa)){ + return jpa; + } + } + return null; + } + public boolean isEmbeddedId(ReadOnlyPersistentAttribute jpa) { return (jpa.getMappingKey() == MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); } @@ -1869,4 +1979,113 @@ public class JpaArtifactFactory { JPADiagramEditorPlugin.logError("Cannot create hierarchy of entity type " + subclass.getName(), e); //$NON-NLS-1$ } } + + /** + * Adds derived identifier + * @param ownerJPT - the dependent entity (the relationship's owner entity) + * @param inverseJPT - the parent entity (the relationship's inverse/target entity) + * @param ownerAttr - the relationship's owner attribute + */ + public void calculateDerivedIdAnnotation(JavaPersistentType ownerJPT, JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr) { + String attributeType = null; + if(hasSimplePk(inverseJPT)){ + JavaPersistentAttribute jpa = getSimplePkAttribute(inverseJPT); + attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa); + } else { + if(hasIDClassAnnotation(inverseJPT)){ + attributeType = getIdType(inverseJPT); + } else if (hasEmbeddedPk(inverseJPT)){ + attributeType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(inverseJPT)); + } + } + addAppropriateDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, attributeType); + + } + + /** + * Adds the derived identifier annotation depending on the dependent entity's primary key type. + * @param ownerJPT - the dependent entity (the relationship's owner entity) + * @param inverseJPT - the parent entity (the relationship's inverse/target entity) + * @param ownerAttr - the relationship's owner attribute + * @param inverseIdClassFQN - he type of the primary key of the parent entity + */ + private void addAppropriateDerivedIdAnnotation(JavaPersistentType ownerJPT, + JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr, + String inverseIdClassFQN) { + if(hasIDClassAnnotation(ownerJPT)){ + String ownerIdClassFQN = getIdType(ownerJPT); + addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN, + inverseIdClassFQN, IdAnnotation.ANNOTATION_NAME); + } else if(hasEmbeddedPk(ownerJPT)){ + String ownerIdClassFQN = JPAEditorUtil.getAttributeTypeNameWithGenerics(getEmbeddedIdAttribute(ownerJPT)); + addDerivedIdAnnotation(ownerJPT, inverseJPT, ownerAttr, ownerIdClassFQN, + inverseIdClassFQN, MapsId2_0Annotation.ANNOTATION_NAME); + } else if(hasSimplePk(ownerJPT)){ + ownerAttr.getResourceAttribute().addAnnotation(MapsId2_0Annotation.ANNOTATION_NAME); + } else { + ownerAttr.getResourceAttribute().addAnnotation(IdAnnotation.ANNOTATION_NAME); + } + addJoinColumnIfNecessary(ownerAttr, inverseJPT); + } + + /** + * Adds the appropriate derived identifier's annotation to the relationship's owner attribute. + * @param ownerJPT - the dependent entity (the relationship's owner entity) + * @param inverseJPT - the parent entity ( the relationship's inverse/target entity) + * @param ownerAttr - the relationship's owner attribute + * @param ownerIdClassFQN - the fully qualified name of the composite primary key's class + * @param inverseIdClassFQN - the type of the primary key of the parent entity + * @param annotationName - the derived identifier's annotation (either @Id or @MapsId) + */ + private void addDerivedIdAnnotation(JavaPersistentType ownerJPT, + JavaPersistentType inverseJPT, JavaPersistentAttribute ownerAttr, + String ownerIdClassFQN, String inverseIdClassFQN, String annotationName) { + if(!inverseIdClassFQN.equals(ownerIdClassFQN)){ + String attributeType = JPAEditorUtil.returnSimpleName(inverseIdClassFQN); + addFieldInCompositeKeyClass(inverseJPT, ownerAttr, ownerIdClassFQN, attributeType); + Annotation ann = ownerAttr.getResourceAttribute().addAnnotation(annotationName); + if(ann instanceof MapsId2_0Annotation){ + ((MapsId2_0Annotation)ann).setValue(ownerAttr.getName()); + } + } else { + ownerAttr.getResourceAttribute().addAnnotation(annotationName); + } + } + + /** + * This method is called during the calculation of the derived identifier. If the dependent entity has a + * composite primary key, this method is used to be created a new field in the composite primary key's class. + * The field will be of the same type as type the primary key of the parent entity and the name will be the + * same as the name of the owner relationship's attribute. + * @param inverseJPT - the parent entity (the relationship's inverse/target entity) + * @param ownerAttr - the dependent entity (the relationship's owner entity) + * @param fqnClass - the fully qualified name of the composite primary key's class + * @param attributeTypeName - the attribute's type + */ + private void addFieldInCompositeKeyClass(JavaPersistentType inverseJPT, + JavaPersistentAttribute ownerAttr, String fqnClass, String attributeTypeName) { + IJavaProject javaProject = JavaCore.create(ownerAttr.getJpaProject().getProject()); + IType type = getType(javaProject, fqnClass); + if(type != null && !type.getField(ownerAttr.getName()).exists()){ + ICompilationUnit unit = type.getCompilationUnit(); + JavaPersistentType jpt = JPAEditorUtil.getJPType(unit); + Command createNewAttributeCommand = new AddAttributeCommand(null, jpt, attributeTypeName, null, ownerAttr.getName(), + ownerAttr.getName(), null, null, false, unit); + try { + getJpaProjectManager().execute(createNewAttributeCommand, SynchronousUiCommandExecutor.instance()); + } catch (InterruptedException e) { + JPADiagramEditorPlugin.logError("Cannot create a new attribute with name " + ownerAttr.getName(), e); //$NON-NLS-1$ + } + } + } + + public IType getType(IJavaProject javaProject, String fqnClass) { + try { + IType type = javaProject.findType(fqnClass); + return type; + } catch (JavaModelException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java index cec84fa..4670028 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java @@ -422,25 +422,16 @@ public class JPACreateFactory { if (!folder.exists()) { createDirectories(folder, true, true, new NullProgressMonitor()); } - IFile file = folder.getFile(entityShortName + "Id.java"); + IFile file = folder.getFile(entityShortName + ".java"); if (!file.exists()) { String content = "package " + packageName + ";\n\n" - + "import javax.persistence.*;\n\n" - +"import java.io.Serializable;" - + "public class " + entityShortName + "Id {\n" - + " private String firstName;\n" - + " private String lastName;\n" - + " public String getFirstName() {\n" - + " return firstName;\n" - + " }\n" - + " public void setFirstName(String firstName) {\n" - + " this.firstName = firstName;\n" - + " }\n" - + " public String getLastName() {\n" - + " return lastName;\n" + + "public class " + entityShortName + " {\n" + + " private long id;\n" + + " public long getId() {\n" + + " return id;\n" + " }\n" - + " public void setLastName(String lastName) {\n" - + " this.lastName = lastName;\n" + + " public void setId(long id) {\n" + + " this.id = id;\n" + " }\n" + "}"; //$NON-NLS-1$ ByteArrayOutputStream stream = new ByteArrayOutputStream(); diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java index 8acdbae..467f7ab 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java @@ -6,6 +6,13 @@ import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; public class ConnectionIsShown extends DefaultCondition{
private SWTBotGefEditPart entity;
+ private int sourceConnectionSize;
+
+ public ConnectionIsShown(SWTBotGefEditPart entity, int sourceConnectionSize){
+ super();
+ this.entity = entity;
+ this.sourceConnectionSize = sourceConnectionSize;
+ }
public ConnectionIsShown(SWTBotGefEditPart entity){
super();
@@ -13,6 +20,9 @@ public class ConnectionIsShown extends DefaultCondition{ }
public boolean test() throws Exception {
+ if(sourceConnectionSize != 0) {
+ return ((!entity.sourceConnections().isEmpty() && (entity.sourceConnections().size() == sourceConnectionSize + 1)) || !entity.targetConnections().isEmpty());
+ }
return (!entity.sourceConnections().isEmpty() || !entity.targetConnections().isEmpty());
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java index 5542fea..086de2a 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java @@ -12,7 +12,9 @@ import static org.junit.Assert.fail; import java.awt.AWTException;
import java.awt.Robot;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -36,8 +38,12 @@ import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButton; import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButtonPad;
import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -45,7 +51,11 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0;
+import org.eclipse.jpt.jpa.core.jpa2.resource.java.MapsId2_0Annotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation;
import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
@@ -246,6 +256,7 @@ public class EditorProxy { jptType));
JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+ assertNotNull(jpa);
assertEquals(
"The newly added attribute must be mapped as basic attribute.",
MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY,
@@ -930,7 +941,7 @@ public class EditorProxy { */
public void assertBiDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
SWTBotGefEditPart entity2, SWTBotGefConnectionEditPart connection,
- String ownerAttributeName, String inverseAttributeName) {
+ String ownerAttributeName, String inverseAttributeName, boolean isDerivedIdFeature) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
denyDelete();
@@ -940,11 +951,19 @@ public class EditorProxy { assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
- assertTrue(
+ if(isDerivedIdFeature){
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(
+ entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ } else {
+ assertTrue(
"\"Relation Attributes\" section of the owner entity must be visible!",
isSectionVisible(
entity1,
JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
assertTrue(
"\"Relation Attributes\" section of the inverse entity must be visible!",
isSectionVisible(
@@ -996,7 +1015,7 @@ public class EditorProxy { */
public void assertUniDirRelationIsNotDeleted(SWTBotGefEditPart entity1,
SWTBotGefEditPart entity2, SWTBotGefConnectionEditPart connection,
- String attributeName) {
+ String attributeName, boolean isDerivedIdFeature) {
connection.select();
jpaDiagramEditor.clickContextMenu("Delete");
denyDelete();
@@ -1005,11 +1024,20 @@ public class EditorProxy { connection = getConnection(entity1, entity2);
assertNotNull("Attribute must not be deleted!", connection);
assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
+
+ if(isDerivedIdFeature){
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(
+ entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ } else {
assertTrue(
"\"Relation Attributes\" section of the owner entity must be visible!",
isSectionVisible(
entity1,
JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
assertFalse(
"\"Relation Attributes\" section of the inverse entity must not be visible!",
isSectionVisible(
@@ -1065,8 +1093,8 @@ public class EditorProxy { confirmDelete();
bot.waitUntil(new ElementDisappears(jpaDiagramEditor,
ownerAttributeName), 10000);
- assertTrue(entity1.sourceConnections().isEmpty());
- assertTrue(entity2.targetConnections().isEmpty());
+// assertTrue(entity1.sourceConnections().isEmpty());
+// assertTrue(entity2.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
@@ -1132,8 +1160,8 @@ public class EditorProxy { confirmDelete();
bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName),
10000);
- assertTrue(entity1.sourceConnections().isEmpty());
- assertTrue(entity2.targetConnections().isEmpty());
+// assertTrue(entity1.sourceConnections().isEmpty());
+// assertTrue(entity2.targetConnections().isEmpty());
assertNull(jpaDiagramEditor.getEditPart(attributeName));
assertFalse(
"\"Relation Attributes\" section of the owner entity must not be visible!",
@@ -1188,14 +1216,13 @@ public class EditorProxy { // entity1
// and that there is no relationship which starts from entity2
assertFalse(entity1.sourceConnections().isEmpty());
- assertEquals(1, entity1.sourceConnections().size());
assertTrue(entity2.sourceConnections().isEmpty());
// assert that there is exactly one relationship which ends in entity2
// and that there is no relationship which end in entity1.
assertFalse(entity2.targetConnections().isEmpty());
assertEquals(1, entity2.targetConnections().size());
- // assertTrue(entity1.targetConnections().isEmpty());
+// assertTrue(entity1.targetConnections().isEmpty());
assertTrue(
"\"Relation Attributes\" section of the owner entity must be visible!",
@@ -1217,6 +1244,36 @@ public class EditorProxy { }
}
+ /**
+ * Assert that there is exactly one GEF element representing the
+ * relationship
+ *
+ * @param entity1
+ * @param entity2
+ */
+ public void assertDerivedIdConnectionIsCreated(SWTBotGefEditPart entity1,
+ SWTBotGefEditPart entity2, boolean isBiDIr) {
+
+ assertFalse(
+ "\"Relation Attributes\" section of the owner entity must not be visible!",
+ isSectionVisible(
+ entity1,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ if (isBiDIr) {
+ assertTrue(
+ "\"Relation Attributes\" section of the inverse entity must be visible!",
+ isSectionVisible(
+ entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ } else {
+ assertFalse(
+ "\"Relation Attributes\" section of the inverse entity must not be visible!",
+ isSectionVisible(
+ entity2,
+ JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+ }
public void assertIsARelationExists(SWTBotGefEditPart entity1,
SWTBotGefEditPart entity2) {
// assert that there is exactly one relationship, which start from
@@ -1797,13 +1854,19 @@ public class EditorProxy { public void testUniDirRelation(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String linkLabel) {
+ RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ int sourceConSize = owner.sourceConnections().size();
+
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 2);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ }
jpaDiagramEditor.click(owner);
jpaDiagramEditor.click(inverse);
- bot.waitUntil(new ConnectionIsShown(owner), 10000);
+ bot.waitUntil(new ConnectionIsShown(owner, sourceConSize), 10000);
waitASecond();
jpaDiagramEditor.activateDefaultTool();
@@ -1823,15 +1886,354 @@ public class EditorProxy { assertAttributeIsCorretlyMapped(attributeName, linkLabel);
assertUniDirRelationIsNotDeleted(owner, inverse, connection,
- attributeName);
+ attributeName, false);
assertUniDirRelationIsDeleted(owner, inverse, connection, attributeName);
}
+
+
+ public void testUniDirDerivedIdWithIdAnnotation(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String relationAnnotation, String derivedIdAnnotation, String linkLabel){
+ jpaDiagramEditor
+ .activateTool(relationFeatureName, 0);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertDerivedIdConnectionIsCreated(owner, inverse, false);
+
+ SWTBotGefConnectionEditPart connection = getConnection(owner, inverse);
+ assertNotNull("Connection must be shown in the diagram.", connection);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, linkLabel);
+
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ jpaDetailsView.setFocus();
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
+
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ attribute.select();
+ attribute.click();
+
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ assertTrue(annotations.contains(relationAnnotation));
+ assertTrue(annotations.contains(derivedIdAnnotation));
+
+ assertUniDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, true);
+
+ assertUniDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName);
+
+ }
+
+ public void testUniDirDerivedIdWithEmbeddedPk(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse, SWTBotGefEditPart embeddable,
+ RelType reltype, String relationAnnotation, String derivedIdAnnotation, String linkLabel,
+ boolean isBiDir, boolean isSamePK, String idClassFQN){
+ int sourceConnSize = owner.sourceConnections().size();
+
+ if(isBiDir){
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ }
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ bot.waitUntil(new ConnectionIsShown(owner, sourceConnSize), 10000);
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertDerivedIdConnectionIsCreated(owner, inverse, isBiDir);
+
+ SWTBotGefConnectionEditPart connection = getConnection(owner, inverse);
+ assertNotNull("Connection must be shown in the diagram.", connection);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ if(isBiDir){
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ } else {
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ }
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+ String inverseAttributeName = null;
+ if(isBiDir){
+ inverseAttributeName = testInverseRelationAttributeProperties(rel);
+ }
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, linkLabel);
+
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ attribute.select();
+ attribute.click();
+
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ assertTrue(annotations.contains(relationAnnotation));
+ assertTrue(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID));
+
+ String helperAttributeName = null;
+ if(!isSamePK) {
+ helperAttributeName = assertContainsHelperAttrInEmbeddable(inverse, embeddable, jpa, idClassFQN);
+ }
+
+ if(isBiDir){
+ assertBiDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName, true);
+ assertBiDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName);
+ } else {
+ assertUniDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, true);
+ assertUniDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName);
+ }
+
+ if(!isSamePK)
+ assertNull(getAttributeInPE(embeddable, helperAttributeName));
+ }
+
+ public void testUniDirDerivedIdWithIdClassPk(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse, IFile idClass,
+ RelType reltype, String relationAnnotation, String derivedIdAnnotation, String linkLabel,
+ boolean isBiDir, boolean isSamePK, String idClassFQN) throws JavaModelException{
+ if(isBiDir){
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ }
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ bot.waitUntil(new ConnectionIsShown(owner), 10000);
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertDerivedIdConnectionIsCreated(owner, inverse, isBiDir);
+
+ SWTBotGefConnectionEditPart connection = getConnection(owner, inverse);
+ assertNotNull("Connection must be shown in the diagram.", connection);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ if(isBiDir){
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ } else {
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ }
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+ String inverseAttributeName = null;
+ if(isBiDir){
+ inverseAttributeName = testInverseRelationAttributeProperties(rel);
+ }
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, linkLabel);
+
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ attribute.select();
+ attribute.click();
+
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ assertTrue(annotations.contains(relationAnnotation));
+ assertTrue(annotations.contains(JPAEditorConstants.ANNOTATION_ID));
+
+ String helperAttributeName = null;
+ if(!isSamePK) {
+ helperAttributeName = assertContainsHelperAttrInIdClass(inverse, idClass, jpa, idClassFQN);
+ }
+
+ if(isBiDir){
+ assertBiDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName, true);
+ assertBiDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName);
+ } else {
+ assertUniDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, true);
+ assertUniDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName);
+ }
+
+ if(!isSamePK) {
+ IType idClassType = JavaCore.createCompilationUnitFrom(idClass).findPrimaryType();
+ assertFalse(idClassType.getField(helperAttributeName).exists());
+ }
+ }
+
+ private String assertContainsHelperAttrInEmbeddable(
+ SWTBotGefEditPart inverse, SWTBotGefEditPart embeddable,
+ JavaPersistentAttribute jpa, String IdClassFQN) {
+ String helperAttributeName = JPAEditorUtil.decapitalizeFirstLetter(getJPTObjectForGefElement(inverse).getSimpleName());
+ SWTBotGefEditPart helperAttr = getAttributeInPE(embeddable, helperAttributeName);
+ assertNotNull(helperAttr);
+
+ Annotation an = jpa.getResourceAttribute().getAnnotation(MapsId2_0Annotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertTrue(an instanceof MapsId2_0Annotation);
+ String mapsIdValue = ((MapsId2_0Annotation)an).getValue();
+ assertEquals(mapsIdValue, helperAttributeName);
+
+ String helperAttrType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getJPAObjectForGefElement(helperAttr));
+
+ if(IdClassFQN != null){
+ assertEquals(helperAttrType, IdClassFQN);
+ } else {
+ String primaryKeyType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getJPAObjectForGefElement(getAttributeInPE(inverse, "id")));
+ assertEquals(helperAttrType, primaryKeyType);
+ }
+ return helperAttributeName;
+ }
+
+
+ private String assertContainsHelperAttrInIdClass(
+ SWTBotGefEditPart inverse, IFile idClass,
+ JavaPersistentAttribute jpa, String IdClassFQN) throws JavaModelException {
+
+ IType idClassType = JavaCore.createCompilationUnitFrom(idClass).findPrimaryType();
+ assertNotNull(idClassType);
+
+ Annotation an = jpa.getResourceAttribute().getAnnotation(IdAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+
+ IField helperAttr = idClassType.getField(jpa.getName());
+ assertNotNull(helperAttr);
+
+
+ String helperAttrType = helperAttr.getSource().split(" ")[1];
+
+ if(IdClassFQN != null){
+ assertEquals(helperAttrType, IdClassFQN);
+ } else {
+ String primaryKeyType = JPAEditorUtil.getAttributeTypeNameWithGenerics(getJPAObjectForGefElement(getAttributeInPE(inverse, "id")));
+ assertEquals(helperAttrType, primaryKeyType);
+ }
+ return helperAttr.getElementName();
+ }
+
+ public SWTBotGefEditPart getAttributeInPE(
+ SWTBotGefEditPart dependentEntity, String embeddedAttributeName) {
+ List<SWTBotGefEditPart> editParts = new ArrayList<SWTBotGefEditPart>();
+ editParts.add(dependentEntity);
+ SWTBotGefEditPart embeddedAttribute = jpaDiagramEditor.getEditpart(
+ embeddedAttributeName, editParts);
+ return embeddedAttribute;
+ }
+
+ public void testBiDirDerivedIdWithIdAnnotation(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String relationAnnotation, String derivedIdAnnotation, String linkLabel){
+ jpaDiagramEditor
+ .activateTool(relationFeatureName, 1);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertDerivedIdConnectionIsCreated(owner, inverse, true);
+
+ SWTBotGefConnectionEditPart connection = getConnection(owner, inverse);
+ assertNotNull("Connection must be shown in the diagram.", connection);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+ String inverseAttributeName = testInverseRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, linkLabel);
+
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ jpaDetailsView.setFocus();
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
+
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ attribute.select();
+ attribute.click();
+
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ assertTrue(annotations.contains(relationAnnotation));
+ assertTrue(annotations.contains(derivedIdAnnotation));
+
+ assertBiDirRelationIsNotDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName, true);
+
+ assertBiDirRelationIsDeleted(owner, inverse, connection, ownerAttributeName, inverseAttributeName);
+ }
+
+ public void testUniDirDerivedIdWithMapsIdAnnotation(String relationFeatureName,
+ SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
+ RelType reltype, String linkLabel){
+ jpaDiagramEditor
+ .activateTool(relationFeatureName, 0);
+ jpaDiagramEditor.click(owner);
+ jpaDiagramEditor.click(inverse);
+
+ bot.waitUntil(new ConnectionIsShown(owner));
+
+ waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ assertDerivedIdConnectionIsCreated(owner, inverse, false);
+
+ SWTBotGefConnectionEditPart connection = getConnection(owner, inverse);
+ assertNotNull("Connection must be shown in the diagram.", connection);
+ IRelation rel = getConnection(connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(reltype, rel.getRelType());
+
+ String ownerAttributeName = testOwnerRelationAttributeProperties(rel);
+
+ assertAttributeIsCorretlyMapped(ownerAttributeName, linkLabel);
+
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ jpaDetailsView.setFocus();
+ assertTrue("JPA Details view must be opened!",
+ jpaDetailsView.isActive());
+
+ SWTBotGefEditPart attribute = jpaDiagramEditor
+ .getEditPart(ownerAttributeName);
+ attribute.select();
+ attribute.click();
+
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(attribute);
+
+ HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(jpa);
+ assertTrue(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE));
+ assertTrue(annotations.contains(JPAEditorConstants.ANNOTATION_MAPS_ID));
+ }
public void testSelfUniDirRelation(String relationFeatureName,
- SWTBotGefEditPart entity, RelType reltype, String linkLabel) {
+ SWTBotGefEditPart entity, RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 2);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ }
jpaDiagramEditor.click(entity);
jpaDiagramEditor.click(entity);
bot.waitUntil(new ConnectionIsShown(entity));
@@ -1860,9 +2262,13 @@ public class EditorProxy { public void testUniDirRelRemoveOwnerAttribute(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String linkLabel) {
+ RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 2);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 0);
+ }
jpaDiagramEditor.click(owner);
jpaDiagramEditor.click(inverse);
bot.waitUntil(new ConnectionIsShown(owner));
@@ -1902,22 +2308,26 @@ public class EditorProxy { public void testBiDirRel(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String linkLabel) {
+ RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
testBiDirRelWithTwoMappingTypes(relationFeatureName, owner, inverse,
- reltype, linkLabel, linkLabel);
+ reltype, linkLabel, linkLabel, canBeDerivedIdFeature);
}
public void testSelfBiDirRel(String relationFeatureName,
- SWTBotGefEditPart owner, RelType reltype, String linkLabel) {
+ SWTBotGefEditPart owner, RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
testSelfBiDirRelWithTwoMappings(relationFeatureName, owner, reltype,
- linkLabel, linkLabel);
+ linkLabel, linkLabel, canBeDerivedIdFeature);
}
public void testBiDirRelWithTwoMappingTypes(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String ownerLinkLabel, String inverseLinkLabel) {
+ RelType reltype, String ownerLinkLabel, String inverseLinkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 3);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ }
jpaDiagramEditor.click(owner);
jpaDiagramEditor.click(inverse);
bot.waitUntil(new ConnectionIsShown(owner));
@@ -1942,7 +2352,7 @@ public class EditorProxy { assertAttributeIsCorretlyMapped(inverseAttributeName, inverseLinkLabel);
assertBiDirRelationIsNotDeleted(owner, inverse, connection,
- ownerAttributeName, inverseAttributeName);
+ ownerAttributeName, inverseAttributeName, false);
assertBiDirRelationIsDeleted(owner, inverse, connection,
ownerAttributeName, inverseAttributeName);
@@ -1950,9 +2360,13 @@ public class EditorProxy { public void testSelfBiDirRelWithTwoMappings(String relationFeatureName,
SWTBotGefEditPart entity, RelType reltype, String ownerLinkLabel,
- String inverseLinkLabel) {
+ String inverseLinkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 3);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ }
jpaDiagramEditor.click(entity);
jpaDiagramEditor.click(entity);
bot.waitUntil(new ConnectionIsShown(entity));
@@ -1985,18 +2399,22 @@ public class EditorProxy { public void testBiDirRelRemoveInverseAttribute(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String linkLabel) {
+ RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
testBiDirRelWithTwoMappingsWithoutInverseAttr(relationFeatureName,
- owner, inverse, reltype, linkLabel, linkLabel);
+ owner, inverse, reltype, linkLabel, linkLabel, canBeDerivedIdFeature);
}
public void testBiDirRelWithTwoMappingsWithoutInverseAttr(
String relationFeatureName, SWTBotGefEditPart owner,
SWTBotGefEditPart inverse, RelType reltype, String ownerLinkLabel,
- String inverseLinkLabel) {
+ String inverseLinkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 3);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ }
jpaDiagramEditor.click(owner);
jpaDiagramEditor.click(inverse);
bot.waitUntil(new ConnectionIsShown(owner));
@@ -2062,17 +2480,21 @@ public class EditorProxy { public void testBiDirRelRemoveOwnerAttr(String relationFeatureName,
SWTBotGefEditPart owner, SWTBotGefEditPart inverse,
- RelType reltype, String linkLabel) {
+ RelType reltype, String linkLabel, boolean canBeDerivedIdFeature) {
testBiDirRelWithTwoMappingsWithoutOwnerAttr(relationFeatureName, owner,
- inverse, reltype, linkLabel, linkLabel);
+ inverse, reltype, linkLabel, linkLabel, canBeDerivedIdFeature);
}
public void testBiDirRelWithTwoMappingsWithoutOwnerAttr(
String relationFeatureName, SWTBotGefEditPart owner,
SWTBotGefEditPart inverse, RelType reltype, String ownerLinkLabel,
- String inverseLinkLabel) {
+ String inverseLinkLabel, boolean canBeDerivedIdFeature) {
- jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ if(canBeDerivedIdFeature) {
+ jpaDiagramEditor.activateTool(relationFeatureName, 3);
+ } else {
+ jpaDiagramEditor.activateTool(relationFeatureName, 1);
+ }
jpaDiagramEditor.click(owner);
jpaDiagramEditor.click(inverse);
bot.waitUntil(new ConnectionIsShown(owner));
@@ -2327,10 +2749,13 @@ public class EditorProxy { SWTBotGefEditPart embeddingEntity, SWTBotGefEditPart embeddable,
HasReferenceType refType, String embeddedMappingKey,
String linkLabel, int elementsInDiagramCount) {
-
+
jpaDiagramEditor.activateTool(toolEntry);
-
+
jpaDiagramEditor.click(embeddingEntity);
+
+ waitASecond();
+
jpaDiagramEditor.click(embeddable);
String attributeName = checkEmbeddedConnectionProperties(
@@ -2484,4 +2909,71 @@ public class EditorProxy { type.getResource().delete(true, new NullProgressMonitor());
}
}
+
+ /**
+ * Embed the given embeddedable into the given embedding entity and change the mapping of the
+ * embedded attribute to EmbeddedId.
+ * @param embeddingEntity
+ * @param embeddable
+ */
+ public void addEmbeddedIdToEntity(SWTBotGefEditPart embeddingEntity,
+ SWTBotGefEditPart embeddable) {
+
+ jpaDiagramEditor.activateDefaultTool();
+ embeddingEntity.select();
+ embeddingEntity.click();
+
+ String embeddedAttributeName = embedConnection(JPAEditorMessages.EmbedSingleObjectFeature_EmbeddedFeatureName, embeddingEntity,
+ embeddable, HasReferenceType.SINGLE,
+ MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY,
+ JptUiDetailsMessages.EmbeddedMappingUiProvider_linkLabel,
+ 3);
+
+ SWTBotGefEditPart embeddedAttribute = getAttributeInPE(embeddingEntity,
+ embeddedAttributeName);
+
+ assertNotNull(embeddedAttribute);
+ JavaPersistentAttribute jpa = getJPAObjectForGefElement(embeddedAttribute);
+ jpa.setMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ }
+
+ /**
+ * Delete the default primary key from the selected entity in the diagram
+ * @param entity - the entity from which the primary key to be deleted
+ */
+ public void deleteEntityDefaultPK(
+ SWTBotGefEditPart entity) {
+ List<SWTBotGefEditPart> editParts = new ArrayList<SWTBotGefEditPart>();
+ editParts.add(entity);
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditpart(
+ "id", editParts);
+
+ pressAttributeDeleteContextButton(attribute);
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, entity, "id"),
+ 20000);
+ attribute = jpaDiagramEditor.getEditpart(
+ "id", editParts);
+ assertNull("Attribute must be deleted!", attribute);
+ }
+
+ /**
+ * Creates a new simple java class and set this class as IDClass for the given entity.
+ * @param entity - entity to which the idClass annotation will be added.
+ * @param idClassName - the name of the java class
+ * @param jpaProject - the given jpa project
+ * @return the simple java class file.
+ * @throws IOException
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ public IFile setIdClass(SWTBotGefEditPart entity, String idClassName, JpaProject jpaProject)
+ throws IOException, CoreException, JavaModelException {
+ IFile idClass = JPACreateFactory.instance().createIdClassInProject(jpaProject.getProject(), new String[] {"org", "persistence"}, idClassName);
+
+ JavaPersistentType jptType= getJPTObjectForGefElement(entity);
+ Annotation an = jptType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue(idClassName);
+ return idClass;
+ }
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java index 7514885..678e001 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EmbeddableInDiagramSWTBotTest.java @@ -936,7 +936,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
- 0, entity, embeddable);
+ 2, entity, embeddable);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -962,7 +962,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 1, entity, embeddable);
+ 3, entity, embeddable);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1014,7 +1014,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
- 0, entity, embeddable);
+ 2, entity, embeddable);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1040,7 +1040,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, entity, embeddable);
+ 3, entity, embeddable);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1123,7 +1123,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 1, embeddable, entity);
+ 3, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1139,7 +1139,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelRemoveInverseAttribute(
@@ -1147,7 +1147,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelRemoveOwnerAttr(
@@ -1155,7 +1155,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1186,7 +1186,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, embeddable, entity);
+ 3, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1203,7 +1203,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelWithTwoMappingsWithoutInverseAttr(
@@ -1212,7 +1212,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelWithTwoMappingsWithoutOwnerAttr(
@@ -1221,7 +1221,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1269,7 +1269,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy
.testBiDirRelRemoveInverseAttribute(
@@ -1277,7 +1277,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy
.testBiDirRelRemoveOwnerAttr(
@@ -1285,7 +1285,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1315,7 +1315,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
- 0, embeddable, entity);
+ 2, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1331,7 +1331,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1339,7 +1339,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1369,7 +1369,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
- 0, embeddable, entity);
+ 2, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1385,7 +1385,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1393,7 +1393,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1439,7 +1439,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1447,7 +1447,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1477,7 +1477,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 1, embeddable, entity);
+ 3, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1494,7 +1494,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelRemoveInverseAttribute(
@@ -1502,7 +1502,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelRemoveOwnerAttr(
@@ -1510,7 +1510,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1541,7 +1541,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, embeddable, entity);
+ 3, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1559,7 +1559,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelWithTwoMappingsWithoutInverseAttr(
@@ -1568,7 +1568,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy
.testBiDirRelWithTwoMappingsWithoutOwnerAttr(
@@ -1577,7 +1577,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { entity,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1627,7 +1627,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1635,7 +1635,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1685,7 +1685,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1693,7 +1693,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1743,7 +1743,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1751,7 +1751,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1781,7 +1781,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 0, embeddable, entity);
+ 2, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1798,7 +1798,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1806,7 +1806,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1836,7 +1836,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, embeddable, entity);
+ 2, embeddable, entity);
SWTBotGefEditPart embeddingEntity = editorProxy.addEntityToDiagram(200,
50, jpaProject);
@@ -1853,7 +1853,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy
.testUniDirRelRemoveOwnerAttribute(
@@ -1861,7 +1861,7 @@ public class EmbeddableInDiagramSWTBotTest extends SWTBotGefTestCase { embeddable,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java index 4bbd4d4..04f65bc 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EntitiesInDiagramSWTBotTest.java @@ -2,11 +2,15 @@ package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor; import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.common.core.resource.java.Annotation;
import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.IdClassAnnotation;
import org.eclipse.jpt.jpa.ui.internal.details.JptUiDetailsMessages;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
@@ -176,6 +180,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { Utils.sayTestFinished("testAddAttribute");
}
+ @Ignore
@Test
public void testAddElementCollectionAttribute() {
Utils.sayTestStarted("testAddElementCollectionAttribute");
@@ -1104,7 +1109,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
// create One-to-One unidirectional relation from entity1 to entity2
editorProxy
@@ -1113,7 +1118,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1144,7 +1149,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
entity1,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1180,7 +1185,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
// create One-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1189,7 +1194,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
// create One-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1198,7 +1203,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1228,7 +1233,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
entity1,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1263,7 +1268,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_MANY,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, false);
// create One-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1272,7 +1277,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.ONE_TO_MANY,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1304,7 +1309,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName,
entity1,
IRelation.RelType.ONE_TO_MANY,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1339,7 +1344,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
// create Many-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1348,7 +1353,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1379,7 +1384,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
entity1,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1416,7 +1421,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity2,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
// create Many-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1426,7 +1431,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity2,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
// create Many-to-One bidirectional relation from entity1 to entity2
editorProxy
@@ -1436,7 +1441,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity2,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -1468,7 +1473,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
IRelation.RelType.MANY_TO_ONE,
JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1502,7 +1507,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
// create Many-to-Many bidirectional relation from entity1 to entity2
editorProxy
@@ -1511,7 +1516,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1542,7 +1547,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName,
entity1,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1578,7 +1583,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
// create Many-to-Many bidirectional relation from entity1 to entity2
editorProxy
@@ -1587,7 +1592,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
// create Many-to-Many bidirectional relation from entity1 to entity2
editorProxy
@@ -1596,7 +1601,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { entity1,
entity2,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1627,7 +1632,7 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName,
entity1,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -1699,6 +1704,624 @@ public class EntitiesInDiagramSWTBotTest extends SWTBotGefTestCase { Utils.sayTestFinished("testIsARelationBetweenExistingEntities");
}
+
+ /**
+ * Create two entities in the diagram. From the second entity, remove the default
+ * primary key attribute. From the "Derived Identifiers" select "One-to-One" unidirectional
+ * relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testSimpleDerivedIdWithoutDefaultPK(){
+ Utils.sayTestStarted("testSimpleDerivedIdWithoutDefaultPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+
+ editorProxy.testUniDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testBiDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testUniDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testBiDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ Utils.sayTestFinished("testSimpleDerivedIdWithoutDefaultPK");
+ }
+
+ /**
+ * Create two entities in the diagram. From the "Derived Identifiers" select "One-to-One"
+ * unidirectional relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * with the MapsId annotation in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testSimpleDerivedIdWithDefaultPK(){
+ Utils.sayTestStarted("testSimpleDerivedIdWithDefaultPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.testUniDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testBiDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testUniDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ editorProxy.testBiDirDerivedIdWithIdAnnotation(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+
+ Utils.sayTestFinished("testSimpleDerivedIdWithDefaultPK");
+ }
+
+
+ /**
+ * Create two entities and one embeddable in the diagram. From the second entity, remove the default
+ * primary key attribute. From the "Composition" section, select "Embed Single object" and embed the
+ * embeddable into the entity2. From the "JPA Details" view, change the mapping of the embedded attribute
+ * in the entity2 to EmbeddedId. From the "Derived Identifiers" select "One-to-One"
+ * unidirectional relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * with the MapsId annotation in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithEmbeddedPK(){
+ Utils.sayTestStarted("testDerivedIdWithEmbeddedPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(dependentEntity, embeddable);
+
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, null);
+
+ Utils.sayTestFinished("testDerivedIdWithEmbeddedPK");
+ }
+
+ /**
+ * Create two entities in the diagram. Create a simple java class. From the second entity, remove the default
+ * primary key attribute. Use the created java class as IDClass in entity2. From the "Derived Identifiers" select "One-to-One"
+ * unidirectional relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithIdClassPK() throws Exception{
+ Utils.sayTestStarted("testDerivedIdWithIdClassPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ IFile idClass = editorProxy.setIdClass(dependentEntity, "TestIdClass", jpaProject);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, null);
+
+ Utils.sayTestFinished("testDerivedIdWithIdClassPK");
+ }
+
+ /**
+ * Create two entities in the diagram. Create a simple java class. Remove the default
+ * primary key attribute from both entities. Use the created java class as IDClass in both entities.
+ * From the "Derived Identifiers" select "One-to-One" unidirectional relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithSameIdClassPK() throws Exception{
+ Utils.sayTestStarted("testDerivedIdWithSameIdClassPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ IFile idClass = editorProxy.setIdClass(parentEntity, "TestParentIdClass", jpaProject);
+ String idClassFQN = "TestParentIdClass";
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ JavaPersistentType parentJPTType= editorProxy.getJPTObjectForGefElement(dependentEntity);
+ Annotation an = parentJPTType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue(idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, true, null);
+
+ Utils.sayTestFinished("testDerivedIdWithSameIdClassPK");
+ }
+
+ /**
+ * Create two entities in the diagram. Create two simple java class. Remove the default
+ * primary key attribute from both entities. Use the first java class as IDClass in the first entity and the second
+ * java class as IdClass for the second entity. From the "Derived Identifiers" select "One-to-One"
+ * unidirectional relation feature and click first on the second entity and then on the first one.
+ * Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Assert that a new helper attribute is automatically added in the second java class and its type is the type
+ * of the first java class, used as IDClass.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithDifferentIdClassPK() throws Exception{
+ Utils.sayTestStarted("testDerivedIdWithDifferentIdClassPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ editorProxy.setIdClass(parentEntity, "TestParentIdClass", jpaProject);
+ String idClassFQN = "TestParentIdClass";
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ IFile idClass = editorProxy.setIdClass(dependentEntity, "TestIdClass", jpaProject);
+
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ Utils.sayTestFinished("testDerivedIdWithDifferentIdClassPK");
+ }
+
+ /**
+ * Create two entities and one embeddable in the diagram. Remove the default primary key attribute from both entities.
+ * Embed the embeddable in both entities and change the mappig of the embedded attributes to EmbeddedIds.
+ * From the "Derived Identifiers" select "One-to-One" unidirectional relation feature and click first on the second
+ * entity and then on the first one. Assert that the connection appears. Assert that the owner attribute of the relation is mapped
+ * with MapsId in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithSameEmbeddedPK(){
+ Utils.sayTestStarted("testDerivedIdWithSameEmbeddedPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+ editorProxy.deleteEntityDefaultPK(parentEntity);
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(dependentEntity, embeddable);
+
+ editorProxy.addEmbeddedIdToEntity(parentEntity, embeddable);
+
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, true, null);
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, true, null);
+
+ Utils.sayTestFinished("testDerivedIdWithSameEmbeddedPK");
+ }
+
+ /**
+ * Create two entities and two embeddable in the diagram. Remove the default primary key attribute from both entities.
+ * Embed the first embeddable in the first enetity and the second one in the second entity. Change the mapping of the
+ * embedded attributes to EmbeddedIds. From the "Derived Identifiers" select "One-to-One" unidirectional relation feature
+ * and click first on the second entity and then on the first one. Assert that the connection appears. Assert that the owner
+ * attribute of the relation is mapped with MapsId in the second entity and there is no "Relation Attributes" section.
+ * Assert that e new helper attribute is added in the second embeddable and its type is of the first embeddable.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithDifferentEmbeddedPK(){
+ Utils.sayTestStarted("testDerivedIdWithDifferentEmbeddedPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(parentEntity);
+
+ SWTBotGefEditPart parentEmbeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(parentEntity, parentEmbeddable);
+
+ editorProxy.waitASecond();
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+
+ SWTBotGefEditPart dependentEmbeddable = editorProxy.addEmbeddableToDiagram(300, 300, jpaProject);
+ editorProxy.addEmbeddedIdToEntity(dependentEntity, dependentEmbeddable);
+
+ String idClassFQN = editorProxy.getJPTObjectForGefElement(parentEmbeddable).getName();
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, dependentEmbeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, dependentEmbeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, dependentEmbeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, dependentEmbeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ Utils.sayTestFinished("testDerivedIdWithDifferentEmbeddedPK");
+ }
+
+ /**
+ * Create two entities and one embeddable in the diagram. Create a simple java class. Remove the default primary key attribute
+ * from both entities. Set the java class as IDClass to the first entity and embed the embeddable in the second entity.
+ * Change the mapping of the embedded attributes to EmbeddedIds. From the "Derived Identifiers" select "One-to-One" unidirectional relation feature
+ * and click first on the second entity and then on the first one. Assert that the connection appears. Assert that the owner
+ * attribute of the relation is mapped with MapsId in the second entity and there is no "Relation Attributes" section.
+ * Assert that e new helper attribute is added in the embeddable and its type is of the java class used as IdClass.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithIdClassAndEmbeddedPK() throws Exception {
+ Utils.sayTestStarted("testDerivedIdWithIdClassAndEmbeddedPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+
+ JPACreateFactory.instance().createIdClassInProject(jpaProject.getProject(), new String[] {"org", "persistence"}, "TestIdClass");
+ String idClassFQN = "org.persistence.TestIdClass";
+
+ JavaPersistentType parentJPTType= editorProxy.getJPTObjectForGefElement(parentEntity);
+ Annotation an = parentJPTType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue("TestIdClass");
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(dependentEntity, embeddable);
+
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ Utils.sayTestFinished("testDerivedIdWithIdClassAndEmbeddedPK");
+ }
+
+
+ /**
+ * Create two entities and one embeddable in the diagram.Remove the default primary key attribute
+ * from both entities. Set the embeddable as IDClass to the first entity and embed the embeddable in the second entity.
+ * Change the mapping of the embedded attributes to EmbeddedIds. From the "Derived Identifiers" select "One-to-One" unidirectional relation feature
+ * and click first on the second entity and then on the first one. Assert that the connection appears. Assert that the owner
+ * attribute of the relation is mapped with MapsId in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithIdClassAndSameEmbeddedPK() throws Exception {
+ Utils.sayTestStarted("testDerivedIdWithIdClassAndSameEmbeddedPK");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(parentEntity);
+ String attrnamString = editorProxy.getUniqueAttrName(parentEntity);
+ editorProxy.addAttributeToJPT(parentEntity, attrnamString);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(dependentEntity, embeddable);
+
+ String attrname = editorProxy.getUniqueAttrName(embeddable);
+ jpaDiagramEditor.activateDefaultTool();
+ editorProxy.waitASecond();
+ editorProxy.addAttributeToJPT(embeddable, attrname);
+
+ JavaPersistentType parentJPTType= editorProxy.getJPTObjectForGefElement(parentEntity);
+ Annotation an = parentJPTType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue(editorProxy.getJPTObjectForGefElement(embeddable).getSimpleName());
+
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, true, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithEmbeddedPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, embeddable, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, true, null);
+
+ Utils.sayTestFinished("testDerivedIdWithIdClassAndSameEmbeddedPK");
+ }
+
+ /**
+ * Create two entities and one embeddable in the diagram. Create a simple java class. Remove the default primary key attribute
+ * from both entities. Embed the embeddable in the first entity and set the java class as IDClass to the second entity.
+ * Change the mapping of the embedded attributes to EmbeddedIds. From the "Derived Identifiers" select "One-to-One" unidirectional relation feature
+ * and click first on the second entity and then on the first one. Assert that the connection appears. Assert that the owner
+ * attribute of the relation is mapped as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Assert that e new helper attribute is added in the java class and its type is of the embeddable.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithEmbeddedPkAndIdClass() throws Exception {
+ Utils.sayTestStarted("testDerivedIdWithEmbeddedPkAndIdClass");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(parentEntity);
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(parentEntity, embeddable);
+
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+
+ IFile idClass = JPACreateFactory.instance().createIdClassInProject(jpaProject.getProject(), new String[] {"org", "persistence"}, "TestIdClass");
+ String idClassFQN = editorProxy.getJPTObjectForGefElement(embeddable).getSimpleName();
+
+ JavaPersistentType parentJPTType= editorProxy.getJPTObjectForGefElement(dependentEntity);
+ Annotation an = parentJPTType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue("TestIdClass");
+
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, false, idClassFQN);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, idClass, IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, false, idClassFQN);
+
+ Utils.sayTestFinished("testDerivedIdWithEmbeddedPkAndIdClass");
+ }
+
+ /**
+ * Create two entities and one embeddable in the diagram. Remove the default primary key attribute
+ * from both entities. Embed the embeddable in the first entity and set the embeddable as IDClass to the second entity.
+ * Change the mapping of the embedded attributes to EmbeddedIds. From the "Derived Identifiers" select "One-to-One" unidirectional relation feature
+ * and click first on the second entity and then on the first one. Assert that the connection appears. Assert that the owner
+ * attribute of the relation is mapped as primary key attribute in the second entity and there is no "Relation Attributes" section.
+ * Test that the created relation is successfully deleted. Repeats all steps for the other three
+ * types of relation also.
+ */
+ @Test
+ public void testDerivedIdWithEmbeddedPkAndSameIdClass() throws Exception {
+ Utils.sayTestStarted("testDerivedIdWithEmbeddedPkAndSameIdClass");
+
+ assertTrue("The diagram must be empty.", jpaDiagramEditor
+ .mainEditPart().children().isEmpty());
+
+ SWTBotGefEditPart parentEntity = editorProxy.addEntityToDiagram(50, 50,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(parentEntity);
+
+ SWTBotGefEditPart embeddable = editorProxy.addEmbeddableToDiagram(300, 50, jpaProject);
+
+ editorProxy.addEmbeddedIdToEntity(parentEntity, embeddable);
+
+ String attrname = editorProxy.getUniqueAttrName(embeddable);
+ jpaDiagramEditor.activateDefaultTool();
+ editorProxy.waitASecond();
+ editorProxy.addAttributeToJPT(embeddable, attrname);
+
+ SWTBotGefEditPart dependentEntity = editorProxy.addEntityToDiagram(50, 300,
+ jpaProject);
+
+ editorProxy.deleteEntityDefaultPK(dependentEntity);
+ String attrnamString = editorProxy.getUniqueAttrName(parentEntity);
+ editorProxy.addAttributeToJPT(parentEntity, attrnamString);
+
+ JavaPersistentType parentJPTType= editorProxy.getJPTObjectForGefElement(dependentEntity);
+ Annotation an = parentJPTType.getJavaResourceType().addAnnotation(IdClassAnnotation.ANNOTATION_NAME);
+ ((IdClassAnnotation)an).setValue(editorProxy.getJPTObjectForGefElement(embeddable).getSimpleName());
+
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
+ dependentEntity, parentEntity, (IFile)parentJPTType.getResource(), IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
+ dependentEntity, parentEntity, (IFile)parentJPTType.getResource(), IRelation.RelType.ONE_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
+ dependentEntity, parentEntity, (IFile)parentJPTType.getResource(), IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, false, true, null);
+
+ editorProxy.testUniDirDerivedIdWithIdClassPk(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
+ dependentEntity, parentEntity, (IFile)parentJPTType.getResource(), IRelation.RelType.MANY_TO_ONE, JPAEditorConstants.ANNOTATION_MANY_TO_ONE,
+ JPAEditorConstants.ANNOTATION_MAPS_ID, JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true, true, null);
+
+ Utils.sayTestFinished("testDerivedIdWithEmbeddedPkAndSameIdClass");
+ }
/**
* Test that the JPA Diagram editor is opened when the context menu
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/MappedSuperclassesInDiagramSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/MappedSuperclassesInDiagramSWTBotTest.java index dec2422..1dcf927 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/MappedSuperclassesInDiagramSWTBotTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/MappedSuperclassesInDiagramSWTBotTest.java @@ -816,7 +816,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { mappedSuperclass,
entity,
IRelation.RelType.ONE_TO_ONE,
- JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -851,7 +851,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { mappedSuperclass,
entity,
IRelation.RelType.ONE_TO_MANY,
- JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.OneToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -886,7 +886,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { mappedSuperclass,
entity,
IRelation.RelType.MANY_TO_ONE,
- JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToOneMappingUiProvider_linkLabel, true);
editorProxy.deleteDiagramElements();
@@ -922,7 +922,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { mappedSuperclass,
entity,
IRelation.RelType.MANY_TO_MANY,
- JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel);
+ JptUiDetailsMessages.ManyToManyMappingUiProvider_linkLabel, false);
editorProxy.deleteDiagramElements();
@@ -951,12 +951,12 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName,
- 0, entity, mappedSuperclass);
+ 2, entity, mappedSuperclass);
editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 1, entity, mappedSuperclass);
+ 3, entity, mappedSuperclass);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -984,7 +984,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName,
- 1, mappedSuperclass, entity);
+ 3, mappedSuperclass, entity);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1040,12 +1040,12 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName,
- 0, entity, mappedSuperclass);
+ 2, entity, mappedSuperclass);
editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, entity, mappedSuperclass);
+ 3, entity, mappedSuperclass);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
@@ -1073,7 +1073,7 @@ public class MappedSuperclassesInDiagramSWTBotTest extends SWTBotGefTestCase { editorProxy
.testNoConnectionIsCreated(
JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName,
- 1, mappedSuperclass, entity);
+ 3, mappedSuperclass, entity);
editorProxy.deleteDiagramElements();
jpaDiagramEditor.save();
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java index 27b7d8e..afb3807 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java @@ -104,7 +104,7 @@ public class CreateRelationFeaturesTest { } - CreateOneToOneUniDirRelationFeature ft = new CreateOneToOneUniDirRelationFeature(featureProvider); + CreateOneToOneUniDirRelationFeature ft = new CreateOneToOneUniDirRelationFeature(featureProvider, false); ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class); ContainerShape cs1 = EasyMock.createMock(ContainerShape.class); @@ -178,7 +178,7 @@ public class CreateRelationFeaturesTest { } - CreateOneToOneBiDirRelationFeature ft = new CreateOneToOneBiDirRelationFeature(featureProvider); + CreateOneToOneBiDirRelationFeature ft = new CreateOneToOneBiDirRelationFeature(featureProvider, false); ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class); ContainerShape cs1 = EasyMock.createMock(ContainerShape.class); @@ -245,7 +245,7 @@ public class CreateRelationFeaturesTest { } - CreateManyToOneUniDirRelationFeature ft = new CreateManyToOneUniDirRelationFeature(featureProvider); + CreateManyToOneUniDirRelationFeature ft = new CreateManyToOneUniDirRelationFeature(featureProvider, false); ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class); ContainerShape cs1 = EasyMock.createMock(ContainerShape.class); @@ -311,7 +311,7 @@ public class CreateRelationFeaturesTest { } - CreateManyToOneBiDirRelationFeature ft = new CreateManyToOneBiDirRelationFeature(featureProvider); + CreateManyToOneBiDirRelationFeature ft = new CreateManyToOneBiDirRelationFeature(featureProvider, false); ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class); ContainerShape cs1 = EasyMock.createMock(ContainerShape.class); diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java index 4294696..aae52a8 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java @@ -104,7 +104,7 @@ public class CreateRelationsInFieldAnnotatedEntitiesTest { t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getTypeBinding().getQualifiedName()); } ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address", true); + AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address", true, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -154,7 +154,7 @@ public class CreateRelationsInFieldAnnotatedEntitiesTest { } ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); ICompilationUnit cu2 = createCompilationUnitFrom((IFile)t2.getResource()); - AbstractRelation rel = new OneToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null); + AbstractRelation rel = new OneToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -264,7 +264,7 @@ public class CreateRelationsInFieldAnnotatedEntitiesTest { t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getTypeBinding().getQualifiedName()); } ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address", true); + AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address", true, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -315,7 +315,7 @@ public class CreateRelationsInFieldAnnotatedEntitiesTest { } ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); ICompilationUnit cu2 = createCompilationUnitFrom((IFile)t2.getResource()); - AbstractRelation rel = new ManyToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null); + AbstractRelation rel = new ManyToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java index 66d11c3..c8f306d 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java @@ -139,7 +139,7 @@ public class CreateRelationsTest { @Test public void testCreateOneToOneUnidirRelation() throws Exception { - AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address", true); + AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address", true, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -155,7 +155,7 @@ public class CreateRelationsTest { @Test public void testCreateOneToOneBidirRelation() throws Exception { - AbstractRelation rel = new OneToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null); + AbstractRelation rel = new OneToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -193,7 +193,7 @@ public class CreateRelationsTest { @Test public void testCreateManyToOneUnidirRelation() throws Exception { - AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address", true); + AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address", true, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); @@ -206,7 +206,7 @@ public class CreateRelationsTest { @Test public void testCreateManyToOneBidirRelation() throws Exception { - AbstractRelation rel = new ManyToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null); + AbstractRelation rel = new ManyToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", true, null, false); assertNotNull(rel); assertSame(t1, rel.getOwner()); assertSame(t2, rel.getInverse()); |

