Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpsabeva2012-07-09 14:45:21 +0000
committerpsabeva2012-07-09 14:45:21 +0000
commitd74f2b9f3f137512101655c1f9dae542c120101b (patch)
tree566ef1612fcc5d13095f6362b03753ec71147803
parentcb68f30f2a2978624a4067951db01a136fd7c0d6 (diff)
downloadwebtools.dali-d74f2b9f3f137512101655c1f9dae542c120101b.tar.gz
webtools.dali-d74f2b9f3f137512101655c1f9dae542c120101b.tar.xz
webtools.dali-d74f2b9f3f137512101655c1f9dae542c120101b.zip
[383655] - Relationships between entities are not always shown in the diagram
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java7
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/preferences/JPAEditorPreferencesPage.java13
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java18
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IUnidirectionalRelation.java (renamed from jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/UnidirectionalRelation.java)2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java48
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java32
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java41
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneUniDirRelation.java24
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java32
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java36
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneUniDirRelation.java22
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorConstants.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java32
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java366
16 files changed, 236 insertions, 455 deletions
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 3f8e0e5791..02f33da5a9 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
@@ -44,6 +44,7 @@ import org.eclipse.graphiti.ui.services.GraphitiUi;
import org.eclipse.graphiti.util.IColorConstant;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.core.SourceType;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
@@ -137,6 +138,12 @@ public class AddJPAEntityFeature extends AbstractAddShapeFeature {
ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit();
jpt = JPAEditorUtil.getJPType(cu);
}
+
+ CompilationUnit unit = jpt.getJavaResourceType().getJavaResourceCompilationUnit().buildASTRoot();
+ jpt.getJavaResourceType().synchronizeWith(unit);
+ jpt.update();
+ jpt.synchronizeWithResourceModel();
+
final Diagram targetDiagram = (Diagram) context.getTargetContainer();
final Wrp wrp = new Wrp();
createEntity(context, fp, targetDiagram, wrp, jpt);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
index 9dc301b69c..c6c7813ec1 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java
@@ -28,7 +28,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeaturePr
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.UnidirectionalRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IUnidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchSite;
@@ -72,8 +72,8 @@ public class DeleteRelationFeature extends DefaultDeleteFeature{
preDelete(context);
AbstractRelation rel = (AbstractRelation)businessObjectForPictogramElement;
- if (rel instanceof UnidirectionalRelation) {
- UnidirectionalRelation relation = (UnidirectionalRelation)rel;
+ if (rel instanceof IUnidirectionalRelation) {
+ IUnidirectionalRelation relation = (IUnidirectionalRelation)rel;
ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider());
JavaPersistentAttribute attribute = relation.getAnnotatedAttribute();
PictogramElement textShape = getFeatureProvider().getPictogramElementForBusinessObject(attribute);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/preferences/JPAEditorPreferencesPage.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/preferences/JPAEditorPreferencesPage.java
index 2753c5e9d6..8e9377aa61 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/preferences/JPAEditorPreferencesPage.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/preferences/JPAEditorPreferencesPage.java
@@ -33,6 +33,7 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Button;
@@ -45,10 +46,6 @@ public class JPAEditorPreferencesPage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {
private static final String FICTIVE_PROJECT_NAME = "PROJECT NAME"; //$NON-NLS-1$
- private static final String COLLECTIION_TYPE = "java.util.Collection"; //$NON-NLS-1$
- private static final String LIST_TYPE = "java.util.List"; //$NON-NLS-1$
- private static final String SET_TYPE = "java.util.Set"; //$NON-NLS-1$
- private static final String MAP_TYPE = "java.util.Map"; //$NON-NLS-1$
private StringFieldEditor fDefaultDiagramFolderField;
private StringFieldEditor fDefaultEntityPackageField;
@@ -100,10 +97,10 @@ public class JPAEditorPreferencesPage extends FieldEditorPreferencePage
JPAEditorMessages.JPAEditorPreferencesPage_DefaultCollectionTypeSectionTittle,
1,
new String[][] {
- {COLLECTIION_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE},
- {LIST_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE},
- {SET_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE},
- {MAP_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE}},
+ {JPAEditorConstants.COLLECTION_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE},
+ {JPAEditorConstants.LIST_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE},
+ {JPAEditorConstants.SET_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE},
+ {JPAEditorConstants.MAP_TYPE, JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE}},
parent, true);
defaultCollectionTypeChooser.setPreferenceStore(getPreferenceStore());
defaultCollectionTypeChooser.getRadioBoxControl(parent).setToolTipText(JPAEditorMessages.JPAEditorPreferencesPage_DefaultCollectionTypeSectionDescription);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
index 0ab27283c9..3cdedeeaa0 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/propertypage/JPADiagramPropertyPage.java
@@ -36,6 +36,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferencesPage;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -84,14 +85,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
static public final QualifiedName PROP_DIRECT_EDIT_AFFECTS_CLASS = new QualifiedName(QUALIFIER, "directEditAffectsClass"); //$NON-NLS-1$;
static public final QualifiedName PROP_ACCESS_TYPE = new QualifiedName(QUALIFIER, "accessType"); //$NON-NLS-1$;
static public final QualifiedName PROP_COLLECTION_TYPE = new QualifiedName(QUALIFIER, "collectionType"); //$NON-NLS-1$;
- static public final QualifiedName PROP_ONE_TO_MANY_OLD_STYLE = new QualifiedName(QUALIFIER, "oneToManyOldStyle"); //$NON-NLS-1$;
-
-
- public static final String COLLECTION_TYPE = "java.util.Collection"; //$NON-NLS-1$
- public static final String LIST_TYPE = "java.util.List"; //$NON-NLS-1$
- public static final String SET_TYPE = "java.util.Set"; //$NON-NLS-1$
- public static final String MAP_TYPE = "java.util.Map"; //$NON-NLS-1$
-
+ static public final QualifiedName PROP_ONE_TO_MANY_OLD_STYLE = new QualifiedName(QUALIFIER, "oneToManyOldStyle"); //$NON-NLS-1$;
private IPreferenceStore store = JPADiagramEditorPlugin.getDefault().getPreferenceStore();
@@ -270,7 +264,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
private void createCollectionTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
btnCollectionType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
- btnCollectionType.setText(COLLECTION_TYPE);
+ btnCollectionType.setText(JPAEditorConstants.COLLECTION_TYPE);
gd = new GridData();
btnCollectionType.setLayoutData(gd);
btnCollectionType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_COLLECTION_TYPE));
@@ -284,7 +278,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
private void createListTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
btnListType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
- btnListType.setText(LIST_TYPE);
+ btnListType.setText(JPAEditorConstants.LIST_TYPE);
gd = new GridData();
btnListType.setLayoutData(gd);
btnListType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_LIST_TYPE));
@@ -298,7 +292,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
private void createSetTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
btnSetType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
- btnSetType.setText(SET_TYPE);
+ btnSetType.setText(JPAEditorConstants.SET_TYPE);
gd = new GridData();
btnSetType.setLayoutData(gd);
btnSetType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_SET_TYPE));
@@ -312,7 +306,7 @@ public class JPADiagramPropertyPage extends PropertyPage {
private void createMapTypeButton(Composite composite, GridData gd, String defaultCollectionType) {
btnMapType = new Button(groupCollectionType, SWT.RADIO | SWT.FLAT);
- btnMapType.setText(MAP_TYPE);
+ btnMapType.setText(JPAEditorConstants.MAP_TYPE);
gd = new GridData();
btnMapType.setLayoutData(gd);
btnMapType.setSelection(defaultCollectionType.equals(JPAEditorPreferenceInitializer.PROPERTY_VAL_MAP_TYPE));
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/UnidirectionalRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IUnidirectionalRelation.java
index 7ffb85a51e..e15f046e2e 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/UnidirectionalRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/IUnidirectionalRelation.java
@@ -17,7 +17,7 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal.relations;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
-public interface UnidirectionalRelation extends IRelation {
+public interface IUnidirectionalRelation extends IRelation {
public abstract JavaPersistentAttribute getAnnotatedAttribute();
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
index d57cd9ca74..ba1e06c148 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyBiDirRelation.java
@@ -66,46 +66,13 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
}
private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- String inverseAttributeName = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actInverseAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(inverseAttributeName);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actInverseAttributeName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(inverseAttributeName);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actInverseAttributeName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
-
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject()) ? JpaArtifactFactory.instance().getIdType(inverse) : null,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter,
- true,
- ownerCU,
- inverseCU);
-
- String ownerAttributeName = JPAEditorUtil.returnSimpleName(owner.getName());
- String actOwnerAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner));
- nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(ownerAttributeName);
- actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actOwnerAttributeName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(ownerAttributeName);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actOwnerAttributeName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, actNameWithNonCapitalLetter);
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- inverseAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, inverse, owner,
- isMap ? JpaArtifactFactory.instance().getIdType(owner) : null,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter,
- true,
- inverseCU,
- ownerCU);
+ String mapKeyType = getMapKeyType(isMap, inverse);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
+
+ mapKeyType = getMapKeyType(isMap, owner);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, true, mapKeyType);
JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
}
@@ -113,5 +80,8 @@ public class ManyToManyBiDirRelation extends ManyToManyRelation implements IBidi
public RelDir getRelDir() {
return RelDir.BI;
}
-
+
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ 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/ManyToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
index 790c23c61f..f00027d23c 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToManyUniDirRelation.java
@@ -24,7 +24,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-public class ManyToManyUniDirRelation extends ManyToManyRelation implements UnidirectionalRelation {
+public class ManyToManyUniDirRelation extends ManyToManyRelation implements IUnidirectionalRelation {
public ManyToManyUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
@@ -46,34 +46,20 @@ public class ManyToManyUniDirRelation extends ManyToManyRelation implements Unid
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
-
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
+ private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- isMap ? JpaArtifactFactory.instance().getIdType(inverse) : null,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter,
- true,
- ownerCU,
- inverseCU);
+ String mapKeyType = getMapKeyType(isMap, inverse);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
+
JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
}
public RelDir getRelDir() {
return RelDir.UNI;
- }
+ }
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ 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/ManyToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/ManyToOneBiDirRelation.java
index dd8ad0f211..191a84c2c3 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
@@ -58,42 +58,11 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
}
private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, false,
- ownerCU,
- inverseCU);
-
- name = JPAEditorUtil.returnSimpleName(owner.getName());
- actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner));
- nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, actNameWithNonCapitalLetter);
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- inverseAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, inverse, owner,
- isMap ? JpaArtifactFactory.instance().getIdType(owner) : null,
- nameWithNonCapitalLetter, actNameWithNonCapitalLetter,
- true,
- inverseCU,
- ownerCU);
+ String mapKeyType = getMapKeyType(isMap, owner);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, true, mapKeyType);
JpaArtifactFactory.instance().addManyToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute, isMap);
}
@@ -102,5 +71,7 @@ public class ManyToOneBiDirRelation extends ManyToOneRelation implements IBidir
return RelDir.BI;
}
-
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ 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 099eb292bd..98aca305ca 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
@@ -23,7 +23,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-public class ManyToOneUniDirRelation extends ManyToOneRelation implements UnidirectionalRelation {
+public class ManyToOneUniDirRelation extends ManyToOneRelation implements IUnidirectionalRelation {
public ManyToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
@@ -45,26 +45,8 @@ public class ManyToOneUniDirRelation extends ManyToOneRelation implements Unidir
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
-
- //fp.addAddIgnore(owner, actNameWithNonCapitalLetter);
-
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, false,
- ownerCU,
- inverseCU);
+ private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
index 7af06377c6..a153b4d890 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToManyUniDirRelation.java
@@ -24,7 +24,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-public class OneToManyUniDirRelation extends OneToManyRelation implements UnidirectionalRelation {
+public class OneToManyUniDirRelation extends OneToManyRelation implements IUnidirectionalRelation {
public OneToManyUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
@@ -46,32 +46,20 @@ public class OneToManyUniDirRelation extends OneToManyRelation implements Unidir
this.ownerAnnotatedAttribute = annotatedAttribute;
}
- private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU,
- ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
-
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
+ private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
boolean isMap = JPADiagramPropertyPage.isMapType(owner.getJpaProject().getProject());
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- isMap ? JpaArtifactFactory.instance().getIdType(inverse) : null,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, true,
- ownerCU,
- inverseCU);
+ String mapKeyType = getMapKeyType(isMap, inverse);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, true, mapKeyType);
+
JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute, isMap);
}
public RelDir getRelDir() {
return RelDir.UNI;
- }
+ }
+
+ private String getMapKeyType(boolean isMap, JavaPersistentType jpt){
+ 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/OneToOneBiDirRelation.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/relations/OneToOneBiDirRelation.java
index 0cab59e7fb..3466b89c9a 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
@@ -57,40 +57,8 @@ public class OneToOneBiDirRelation extends OneToOneRelation implements IBidirect
}
private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
-
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, false,
- ownerCU,
- inverseCU);
-
- name = JPAEditorUtil.returnSimpleName(owner.getName());
- actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner));
- nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(inverse, actNameWithNonCapitalLetter);
- inverseAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, inverse, owner,
- nameWithNonCapitalLetter, actNameWithNonCapitalLetter,
- false,
- inverseCU,
- ownerCU);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
+ inverseAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, inverse, owner, inverseCU, ownerCU, false, null);
JpaArtifactFactory.instance().addOneToOneBidirectionalRelation(fp, owner, ownerAnnotatedAttribute, inverse, inverseAnnotatedAttribute);
}
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 b429068394..e262d9d361 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
@@ -23,7 +23,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
-public class OneToOneUniDirRelation extends OneToOneRelation implements UnidirectionalRelation {
+public class OneToOneUniDirRelation extends OneToOneRelation implements IUnidirectionalRelation {
public OneToOneUniDirRelation(IJPAEditorFeatureProvider fp, JavaPersistentType owner,
JavaPersistentType inverse,
@@ -46,26 +46,8 @@ public class OneToOneUniDirRelation extends OneToOneRelation implements Unidirec
}
private void createRelation(IJPAEditorFeatureProvider fp, ICompilationUnit ownerCU, ICompilationUnit inverseCU) {
- String name = JPAEditorUtil.returnSimpleName(inverse.getName());
- String actName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse));
-
- String nameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(name);
- String actNameWithNonCapitalLetter = JPAEditorUtil.decapitalizeFirstLetter(actName);
-
- if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) {
- nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(actName);
- }
- nameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter);
- actNameWithNonCapitalLetter = JPAEditorUtil.produceUniqueAttributeName(owner, actNameWithNonCapitalLetter);
-
- ownerAnnotatedAttribute = JpaArtifactFactory.instance().addAttribute(fp, owner, inverse,
- nameWithNonCapitalLetter,
- actNameWithNonCapitalLetter, false,
- ownerCU,
- inverseCU);
+ ownerAnnotatedAttribute = JPAEditorUtil.addAnnotatedAttribute(fp, owner, inverse, ownerCU, inverseCU, false, null);
JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(fp, owner, ownerAnnotatedAttribute);
-
}
public RelDir getRelDir() {
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 73d627010a..6264d09255 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
@@ -36,6 +36,14 @@ public class JPAEditorConstants {
public static final String HEADER_PREFIX_DIRTY = "* "; //$NON-NLS-1$
+ public static final String COLLECTION_TYPE = "java.util.Collection"; //$NON-NLS-1$
+
+ public static final String LIST_TYPE = "java.util.List"; //$NON-NLS-1$
+
+ public static final String SET_TYPE = "java.util.Set"; //$NON-NLS-1$
+
+ public static final String MAP_TYPE = "java.util.Map"; //$NON-NLS-1$
+
public static Hashtable<String, String> PRIMITIVE_TO_WRAPPER = new Hashtable<String,String>();
public static HashSet<String> WRAPPER_SIMPLE_NAMES = new HashSet<String>();
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 78bd525ad9..9d51a5f531 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
@@ -1391,7 +1391,7 @@ public class JPAEditorUtil {
getPersistence().getPersistenceUnits().iterator();
PersistenceUnit pu = lit.next();
for (ClassRef cf : pu.getClassRefs()) {
- names.add(JPAEditorUtil.returnSimpleName(cf.getClassName()).toLowerCase(Locale.ENGLISH));
+ names.add(returnSimpleName(cf.getClassName()).toLowerCase(Locale.ENGLISH));
}
return names;
}
@@ -1506,4 +1506,34 @@ public class JPAEditorUtil {
return h1.equals(h2);
}
+ public static JavaPersistentAttribute addAnnotatedAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType referencingJPT,
+ JavaPersistentType referencedJPT, ICompilationUnit referencingCU, ICompilationUnit referencedCU, boolean isCollection,
+ String mapKeyType){
+
+ String name = returnSimpleName(referencedJPT.getName());
+ String actName = returnSimpleName(JpaArtifactFactory.instance().getEntityName(referencedJPT));
+
+ String nameWithNonCapitalLetter = decapitalizeFirstLetter(name);
+ String actNameWithNonCapitalLetter = decapitalizeFirstLetter(actName);
+
+ if (JpaArtifactFactory.instance().isMethodAnnotated(referencingJPT)) {
+ nameWithNonCapitalLetter = produceValidAttributeName(name);
+ actNameWithNonCapitalLetter = produceValidAttributeName(actName);
+ }
+ nameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, nameWithNonCapitalLetter);
+ actNameWithNonCapitalLetter = produceUniqueAttributeName(referencingJPT, actNameWithNonCapitalLetter);
+
+ if(mapKeyType == null){
+ return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT,
+ nameWithNonCapitalLetter, actNameWithNonCapitalLetter, isCollection,
+ referencingCU, referencedCU);
+ }
+
+ return JpaArtifactFactory.instance().addAttribute(fp, referencingJPT, referencedJPT, mapKeyType,
+ nameWithNonCapitalLetter,
+ actNameWithNonCapitalLetter, isCollection,
+ referencingCU,
+ referencedCU);
+ }
+
} \ 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/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
index 1f4a0cbce7..190ba6cb14 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
@@ -1359,6 +1359,10 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
ArrayIterator<JavaPersistentAttribute> it = (ArrayIterator<JavaPersistentAttribute>) event.getItems().iterator();
while (it.hasNext()) {
JavaPersistentAttribute at = it.next();
+ if(at.getMapping() == null || at.getMapping().getMappingAnnotation() == null){
+ at.getResourceAttribute().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ }
+
//Shape atShape = (Shape) featureProvider.getPictogramElementForBusinessObject(at);
//if (atShape != null)
// continue;
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 411eb252b5..0dcea3288f 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
@@ -60,7 +60,6 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
-import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
@@ -70,12 +69,10 @@ import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.RelationshipMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
-import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass;
-import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping;
-import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping;
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.java.JavaTypeMapping;
@@ -85,10 +82,7 @@ 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.IdClassAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
-import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.MapKeyAnnotation;
-import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation;
-import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.RelationshipMappingAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.TableAnnotation;
@@ -104,6 +98,7 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IBidirectionalRela
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IUnidirectionalRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation;
@@ -112,7 +107,6 @@ import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneUniDirRel
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToManyUniDirRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneBiDirRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneUniDirRelation;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.UnidirectionalRelation;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
@@ -125,11 +119,6 @@ public class JpaArtifactFactory {
private static final int MAX_NUM_OF_ITERATIONS = 25;
private static final int PAUSE_DURATION = 200;
-
- private static final String COLLECTION_TYPE = "java.util.Collection"; //$NON-NLS-1$
- private static final String LIST_TYPE = "java.util.List"; //$NON-NLS-1$
- private static final String SET_TYPE = "java.util.Set"; //$NON-NLS-1$
- private static final String MAP_TYPE = "java.util.Map"; //$NON-NLS-1$
synchronized public static JpaArtifactFactory instance() {
return INSTANCE;
@@ -187,34 +176,6 @@ public class JpaArtifactFactory {
JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL);
}
- public void addOneToOneRelation(IFeatureProvider fp, JavaPersistentType ownerJPT,
- JavaPersistentAttribute ownerAttibute,
- JavaPersistentType referencedJPT,
- JavaPersistentAttribute referencedAttribute, int direction) {
-
- if(ownerJPT.getAttributeNamed(ownerAttibute.getName()) == null){
- refreshEntityModel(fp, ownerJPT);
- }
-
- JavaPersistentAttribute attr = (JavaPersistentAttribute) ownerJPT
- .resolveAttribute(ownerAttibute.getName());
- attr.getResourceAttribute().setPrimaryAnnotation("javax.persistence.OneToOne", new ArrayListIterable<String>()); //$NON-NLS-1$
- if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
- JpaArtifactFactory.instance().refreshEntityModel(null, referencedJPT);
- JavaPersistentAttribute attr2 = (JavaPersistentAttribute) referencedJPT.resolveAttribute(referencedAttribute.getName());
- attr2.setMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
- attr2.getJpaProject().getRootContextNode().update();
- JavaOneToOneMapping mapping = (JavaOneToOneMapping) attr2.getMapping();
- OneToOneAnnotation annotation = mapping.getMappingAnnotation();
- if(annotation == null) {
- JpaArtifactFactory.instance().refreshEntityModel(null, referencedJPT);
- annotation = ((JavaOneToOneMapping) attr2.getMapping()).getMappingAnnotation();
- }
- annotation.setMappedBy(ownerAttibute.getName());
- }
-
- }
-
public void addOneToManyUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt,
JavaPersistentAttribute attribute, boolean isMap) {
@@ -238,56 +199,75 @@ public class JpaArtifactFactory {
JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL, isMap);
}
+ public void addOneToOneRelation(IFeatureProvider fp,
+ JavaPersistentType ownerJPT, JavaPersistentAttribute ownerAttibute,
+ JavaPersistentType referencedJPT,
+ JavaPersistentAttribute referencedAttribute, int direction) {
+
+ setMappingKeyToAttribute(fp, ownerJPT, ownerAttibute, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+
+ if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
+ JavaPersistentAttribute resolvedAttribute = setMappingKeyToAttribute(fp, referencedJPT, referencedAttribute, MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ setMappedByAnnotationAttribute(resolvedAttribute, referencedJPT, ownerAttibute);
+ }
+
+ }
+
+ public void addManyToOneRelation(IFeatureProvider fp, JavaPersistentType manySideJPT,
+ JavaPersistentAttribute manySideAttribute, JavaPersistentType singleSideJPT,
+ JavaPersistentAttribute singleSideAttibute, int direction, boolean isMap) {
+
+ setMappingKeyToAttribute(fp, manySideJPT, manySideAttribute, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+
+ if (direction == JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL)
+ return;
+
+ JavaPersistentAttribute resolvedSingleSideAttribute = setMappingKeyToAttribute(fp, singleSideJPT, singleSideAttibute, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, manySideAttribute);
+ if (isMap) {
+ singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ }
public void addOneToManyRelation(IFeatureProvider fp, JavaPersistentType singleSideJPT,
JavaPersistentAttribute singleSideAttibute,
JavaPersistentType manySideJPT,
JavaPersistentAttribute manySideAttribute, int direction, boolean isMap) {
+
+ JavaPersistentAttribute resolvedSingleSideAttribute = setMappingKeyToAttribute(fp, singleSideJPT, singleSideAttibute, MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- //if(singleSideJPT.getAttributeNamed(singleSideAttibute.getName()) == null){
- refreshEntityModel(fp, singleSideJPT);
- //}
-
- JavaPersistentAttribute resolvedSingleSideAttribute = (JavaPersistentAttribute) singleSideJPT
- .resolveAttribute(singleSideAttibute.getName());
- resolvedSingleSideAttribute
- .setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
- resolvedSingleSideAttribute.getJpaProject().getRootContextNode()
- .update();
- JpaArtifactFactory.instance().refreshEntityModel(null, singleSideJPT);
- JavaAttributeMapping mapping = resolvedSingleSideAttribute
- .getMapping();
- if (!mapping.getClass().isInstance(JavaOneToManyMapping.class))
- return;
- OneToManyAnnotation annotation = ((JavaOneToManyMapping)mapping).getMappingAnnotation();
- if (annotation == null) {
- JpaArtifactFactory.instance().refreshEntityModel(null, singleSideJPT);
- mapping = resolvedSingleSideAttribute.getMapping();
- annotation = ((JavaOneToManyMapping)mapping).getMappingAnnotation();
- }
-
- if(annotation == null){
- JpaArtifactFactory.instance().refreshEntityModel(null, singleSideJPT);
- annotation = ((JavaOneToManyMapping)resolvedSingleSideAttribute
- .getMapping()).getMappingAnnotation();
- }
- annotation.setMappedBy(manySideAttribute.getName());
-
- }
- if (isMap)
- singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
- if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
- if(manySideJPT.getAttributeNamed(manySideAttribute.getName()) == null){
- refreshEntityModel(fp, manySideJPT);
- }
-
- JavaPersistentAttribute resolvedManySideAttribute = (JavaPersistentAttribute) manySideJPT
- .resolveAttribute(manySideAttribute.getName());
- resolvedManySideAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
+ setMappingKeyToAttribute(fp, manySideJPT, manySideAttribute, MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ setMappedByAnnotationAttribute(resolvedSingleSideAttribute, singleSideJPT, manySideAttribute);
} else {
addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT, fp);
}
+ if (isMap)
+ singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ private void setMappedByAnnotationAttribute(JavaPersistentAttribute resolvedAttr, JavaPersistentType type1, JavaPersistentAttribute jpa){
+
+ JavaAttributeMapping mapping = resolvedAttr.getMapping();
+ if (!(mapping instanceof RelationshipMapping)) {
+ resolvedAttr.getResourceAttribute().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ }
+ Annotation annotation = mapping.getMappingAnnotation();
+ if (annotation == null) {
+ resolvedAttr.getResourceAttribute().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ annotation = (OwnableRelationshipMappingAnnotation) mapping.getMappingAnnotation();
+ }
+ if (!(annotation instanceof OwnableRelationshipMappingAnnotation))
+ return;
+ ((OwnableRelationshipMappingAnnotation)annotation).setMappedBy(jpa.getName());
+ }
+
+ private JavaPersistentAttribute setMappingKeyToAttribute(IFeatureProvider fp, JavaPersistentType jpt, JavaPersistentAttribute jpa, String mappingKey){
+ JavaPersistentAttribute resolvedManySideAttribute = (JavaPersistentAttribute) jpt.resolveAttribute(jpa.getName());
+ resolvedManySideAttribute.getResourceAttribute().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ resolvedManySideAttribute.setMappingKey(mappingKey);
+ return resolvedManySideAttribute;
}
private void addJoinColumnIfNecessary(JavaPersistentAttribute jpa,
@@ -372,32 +352,7 @@ public class JpaArtifactFactory {
addManyToOneRelation(fp, jpt, attribute, null, null,
JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL, false);
}
-
- public void addManyToOneRelation(IFeatureProvider fp, JavaPersistentType manySideJPT,
- JavaPersistentAttribute manySideAttribute,
- JavaPersistentType singleSideJPT,
- JavaPersistentAttribute singleSideAttibute,
- int direction, boolean isMap) {
-
- refreshEntityModel(fp, manySideJPT);
-
- JavaPersistentAttribute resolvedManySideAttribute = manySideJPT.getAttributeNamed(manySideAttribute.getName());
- resolvedManySideAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
-
- if (direction == JPAEditorConstants.RELATION_TYPE_UNIDIRECTIONAL)
- return;
-
- JavaPersistentAttribute resolvedSingleSideAttribute = singleSideJPT.getAttributeNamed(singleSideAttibute.getName());
- resolvedSingleSideAttribute.setMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- refreshEntityModel(fp, singleSideJPT);
- JavaOneToManyMapping mapping = (JavaOneToManyMapping)resolvedSingleSideAttribute.getMapping();
- OneToManyAnnotation a = mapping.getMappingAnnotation();
- if (a == null)
- return;
- a.setMappedBy(manySideAttribute.getName());
- if (isMap)
- singleSideAttibute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
- }
+
public void addManyToManyBidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt1,
JavaPersistentAttribute attribute1, JavaPersistentType jpt2,
@@ -417,46 +372,16 @@ public class JpaArtifactFactory {
public void addManyToManyRelation(IFeatureProvider fp, JavaPersistentType ownerSideJPT,
JavaPersistentAttribute ownerSideAttribute,
JavaPersistentType inverseSideJPT,
- JavaPersistentAttribute inverseSideAttibute, int direction, boolean isMap) {
+ JavaPersistentAttribute inverseSideAttibute, int direction, boolean isMap) {
- if(ownerSideJPT.getAttributeNamed(ownerSideAttribute.getName()) == null){
- refreshEntityModel(fp, ownerSideJPT);
- }
-
- JavaPersistentAttribute resolvedOwnerSideAttribute = (JavaPersistentAttribute) ownerSideJPT
- .resolveAttribute(ownerSideAttribute.getName());
- resolvedOwnerSideAttribute
- .setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ JavaPersistentAttribute resolvedOwnerSideAttribute = setMappingKeyToAttribute(fp, ownerSideJPT, ownerSideAttribute, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
if (isMap)
resolvedOwnerSideAttribute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
if (direction == JPAEditorConstants.RELATION_TYPE_BIDIRECTIONAL) {
- JpaArtifactFactory.instance().refreshEntityModel(null, inverseSideJPT);
- /*
- if(inverseSideJPT.getAttributeNamed(inverseSideAttibute.getName()) == null){
- refreshEntityModel(fp, inverseSideJPT);
- }
- */
+ JavaPersistentAttribute resolvedInverseSideAttribute = setMappingKeyToAttribute(fp, inverseSideJPT, inverseSideAttibute, MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ setMappedByAnnotationAttribute(resolvedInverseSideAttribute, inverseSideJPT, ownerSideAttribute);
- JavaPersistentAttribute resolvedInverseSideAttribute = (JavaPersistentAttribute) inverseSideJPT
- .resolveAttribute(inverseSideAttibute.getName());
- resolvedInverseSideAttribute
- .setMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
- resolvedInverseSideAttribute.getJpaProject().getRootContextNode()
- .update();
-
- JavaManyToManyMapping mapping = (JavaManyToManyMapping) resolvedInverseSideAttribute
- .getMapping();
- ManyToManyAnnotation a = mapping.getMappingAnnotation();
- if(mapping == null || a == null){
- JpaArtifactFactory.instance().refreshEntityModel(null, inverseSideJPT);
- mapping = (JavaManyToManyMapping) resolvedInverseSideAttribute
- .getMapping();
- a = mapping.getMappingAnnotation();
- }
- if (a == null)
- return;
- a.setMappedBy(ownerSideAttribute.getName());
if (isMap)
resolvedInverseSideAttribute.getResourceAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME);
}
@@ -638,9 +563,9 @@ public class JpaArtifactFactory {
}
public JavaPersistentAttribute addAttribute(IJPAEditorFeatureProvider fp, JavaPersistentType jpt,
- JavaPersistentType attributeType, String mapKeyType, String attributeName,
- String actName, boolean isCollection, ICompilationUnit cu1,
- ICompilationUnit cu2) {
+ JavaPersistentType attributeType, String mapKeyType, String attributeName,
+ String actName, boolean isCollection, ICompilationUnit cu1,
+ ICompilationUnit cu2) {
IType type = null;
try {
JPAEditorUtil.createImport(cu1, cu2.getType(attributeType.getName()).getElementName());
@@ -651,62 +576,11 @@ public class JpaArtifactFactory {
.resolveAttribute(attributeName);
}
if (isCollection) {
- IProject project = jpt.getJpaProject().getProject();
- Properties props = fp.loadProperties(project);
-
- if (JPADiagramPropertyPage.isCollectionType(project, props)) {
- createContentType(attributeType, actName, cu1, type, COLLECTION_TYPE);
- type.createMethod(genGetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, COLLECTION_TYPE), null, false,
- new NullProgressMonitor());
- type.createMethod(genSetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, COLLECTION_TYPE), null, false,
- new NullProgressMonitor());
- } else if (JPADiagramPropertyPage.isListType(project, props)) {
- createContentType(attributeType, actName, cu1, type, LIST_TYPE);
- type.createMethod(genGetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, LIST_TYPE), null, false,
- new NullProgressMonitor());
- type.createMethod(genSetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, LIST_TYPE), null, false,
- new NullProgressMonitor());
- } else if (JPADiagramPropertyPage.isSetType(project, props)) {
- createContentType(attributeType, actName, cu1, type, SET_TYPE);
- type.createMethod(genGetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, SET_TYPE), null, false,
- new NullProgressMonitor());
- type.createMethod(genSetterWithAppropriateType(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, SET_TYPE), null, false,
- new NullProgressMonitor());
- } else {
- mapKeyType = createContentType(mapKeyType, attributeType, actName, cu1, type, MAP_TYPE);
- type.createMethod(genGetterWithAppropriateType(attributeName, mapKeyType,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, MAP_TYPE), null, false,
- new NullProgressMonitor());
- type.createMethod(genSetterWithAppropriateType(attributeName, mapKeyType,
- JPAEditorUtil.returnSimpleName(attributeType.getName()),
- actName, MAP_TYPE), null, false,
- new NullProgressMonitor());
- }
+ createAttributeOfCollectiontype(fp, jpt, attributeType,
+ mapKeyType, attributeName, actName, cu1, type);
} else {
- type
- .createField(
- " private " + JPAEditorUtil.returnSimpleName(attributeType.getName()) + " " + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- type.createMethod(genGetterContents(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
- actName, null, isCollection), null, false,
- new NullProgressMonitor());
- type.createMethod(genSetterContents(attributeName,
- JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
- actName, isCollection), null, false,
- new NullProgressMonitor());
+ createSimpleAttribute(attributeType, attributeName, actName,
+ isCollection, type);
}
} catch (JavaModelException e) {
JPADiagramEditorPlugin.logError("Cannnot create a new attribute with name " + attributeName, e); //$NON-NLS-1$
@@ -720,11 +594,55 @@ public class JpaArtifactFactory {
return res;
}
- private void createContentType(JavaPersistentType attributeType,
+ private void createSimpleAttribute(JavaPersistentType attributeType,
+ String attributeName, String actName, boolean isCollection,
+ IType type) throws JavaModelException {
+ type.createField(" private " + JPAEditorUtil.returnSimpleName(attributeType.getName()) + " "
+ + JPAEditorUtil.decapitalizeFirstLetter(actName) + ";", null, false, new NullProgressMonitor()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ type.createMethod(genGetterContents(attributeName,
+ JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
+ actName, null, isCollection), null, false,
+ new NullProgressMonitor());
+ type.createMethod(genSetterContents(attributeName,
+ JPAEditorUtil.returnSimpleName(attributeType.getName()), null,
+ actName, isCollection), null, false,
+ new NullProgressMonitor());
+ }
+
+ private void createAttributeOfCollectiontype(IJPAEditorFeatureProvider fp,
+ JavaPersistentType jpt, JavaPersistentType attributeType,
+ String mapKeyType, String attributeName, String actName,
+ ICompilationUnit cu1, IType type) throws JavaModelException {
+ IProject project = jpt.getJpaProject().getProject();
+ Properties props = fp.loadProperties(project);
+ if (JPADiagramPropertyPage.isCollectionType(project, props)) {
+ createAttributeByCollectionMethodType(attributeType, null,
+ attributeName, actName, cu1, type, JPAEditorConstants.COLLECTION_TYPE);
+ } else if (JPADiagramPropertyPage.isListType(project, props)) {
+ createAttributeByCollectionMethodType(attributeType, null,
+ attributeName, actName, cu1, type, JPAEditorConstants.LIST_TYPE);
+ } else if (JPADiagramPropertyPage.isSetType(project, props)) {
+ createAttributeByCollectionMethodType(attributeType, null,
+ attributeName, actName, cu1, type, JPAEditorConstants.SET_TYPE);
+ } else {
+ createAttributeByCollectionMethodType(attributeType, mapKeyType,
+ attributeName, actName, cu1, type, JPAEditorConstants.MAP_TYPE);
+ }
+ }
+
+ private void createAttributeByCollectionMethodType(
+ JavaPersistentType attributeType, String mapKeyType, String attributeName,
String actName, ICompilationUnit cu1, IType type, String collectionType)
throws JavaModelException {
- createContentType(null, attributeType,
- actName, cu1, type, collectionType);
+ mapKeyType = createContentType(mapKeyType, attributeType, actName, cu1, type, collectionType);
+ type.createMethod(genGetterWithAppropriateType(attributeName, mapKeyType,
+ JPAEditorUtil.returnSimpleName(attributeType.getName()),
+ actName, collectionType), null, false,
+ new NullProgressMonitor());
+ type.createMethod(genSetterWithAppropriateType(attributeName, mapKeyType,
+ JPAEditorUtil.returnSimpleName(attributeType.getName()),
+ actName, collectionType), null, false,
+ new NullProgressMonitor());
}
private String createContentType(String mapKeyType, JavaPersistentType attributeType,
@@ -1552,23 +1470,12 @@ public class JpaArtifactFactory {
renameAttribute(cu, oldName, newName, fp, this.isMethodAnnotated(jpt));
refreshEntityModel(fp, jpt);
JavaPersistentAttribute newAt = jpt.getAttributeNamed(newName);
- if (newAt == null)
- newAt = jpt.getAttributeNamed(JPAEditorUtil
- .revertFirstLetterCase(newName));
- int c = 0;
- while ((newAt == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- c++;
- try {
- Thread.sleep(PAUSE_DURATION);
- newAt = jpt.getAttributeNamed(newName);
- if (newAt == null)
- newAt = (JavaPersistentAttribute) jpt
- .resolveAttribute(JPAEditorUtil
- .revertFirstLetterCase(newName));
- } catch (InterruptedException e) {
- JPADiagramEditorPlugin.logError("Thread.sleep() interrupted", e); //$NON-NLS-1$
- return null;
- }
+ if (newAt == null) {
+ CompilationUnit unit = jpt.getJavaResourceType().getJavaResourceCompilationUnit().buildASTRoot();
+ jpt.getJavaResourceType().synchronizeWith(unit);
+ jpt.update();
+ jpt.synchronizeWithResourceModel();
+ newAt = jpt.getAttributeNamed(newName);
}
if (newAt == null) {
JPADiagramEditorPlugin.logError("The attribute " + newName + " could not be resolved", new NullPointerException()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1853,14 +1760,14 @@ public class JpaArtifactFactory {
}
*/
- private UnidirectionalRelation produceUniDirRelation(
+ private IUnidirectionalRelation produceUniDirRelation(
JavaPersistentType jpt, JavaPersistentAttribute at, Annotation an,
JavaPersistentType relJPT, IJPAEditorFeatureProvider fp) {
if (isNonOwner(at) || !JPAEditorUtil.getCompilationUnit((JavaPersistentType) at.getParent()).exists())
return null;
String annotationName = JPAEditorUtil.returnSimpleName(an.getAnnotationName());
- UnidirectionalRelation res = null;
+ IUnidirectionalRelation res = null;
String attrName = at.getName();
if (annotationName.equals(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) {
if (!fp.doesRelationExist(jpt, relJPT, attrName, RelType.ONE_TO_ONE,
@@ -2041,13 +1948,6 @@ public class JpaArtifactFactory {
return contents;
}
- private String genGetterWithAppropriateType(String attrName, String attrType,
- String actName, String type) {
- return genGetterWithAppropriateType(attrName, null, attrType,
- actName, type);
- }
-
-
private String genGetterWithAppropriateType(String attrName, String mapKeyType, String attrType,
String actName, String type) {
@@ -2062,12 +1962,6 @@ public class JpaArtifactFactory {
" }\n"; //$NON-NLS-1$
return contents;
}
-
- private String genSetterWithAppropriateType(String attrName, String attrType,
- String actName, String type) {
- return genSetterWithAppropriateType(attrName, null, attrType,
- actName, type);
- }
private String genSetterWithAppropriateType(String attrName, String mapKeyType, String attrType,
String actName, String type) {
@@ -2302,7 +2196,7 @@ public class JpaArtifactFactory {
JavaResourceAttribute jra) {
String relTypeName = null;
try {
- boolean isMap = jra.getTypeName().equals("java.util.Map"); //$NON-NLS-1$
+ boolean isMap = jra.getTypeName().equals(JPAEditorConstants.MAP_TYPE);
relTypeName = jra.getTypeTypeArgumentName(isMap ? 1 : 0);
} catch (Exception e) {}
if (relTypeName == null)

Back to the top