[338395] Implement One-to-Many with @JoinColumn
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
index 14a16c1..43d7f18 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
@@ -9,25 +9,25 @@
Bundle-ClassPath: .
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
- org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
- org.eclipse.gef;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.graphiti;bundle-version="[0.8.0,1.0.0)",
- org.eclipse.graphiti.mm;bundle-version="[0.8.0,1.0.0)",
- org.eclipse.graphiti.pattern;bundle-version="[0.8.0,1.0.0)",
- org.eclipse.graphiti.ui;bundle-version="[0.8.0,1.0.0)",
- org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.7.0,4.0.0)",
- org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.jpt.jpa.core;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.jpt.jpa.ui;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
- org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)"
+Require-Bundle: org.eclipse.core.expressions,
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.emf.transaction,
+ org.eclipse.gef,
+ org.eclipse.graphiti,
+ org.eclipse.graphiti.mm,
+ org.eclipse.graphiti.pattern,
+ org.eclipse.graphiti.ui,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.ui,
+ org.eclipse.jface.text,
+ org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.utility,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.views.properties.tabbed,
+ org.eclipse.wst.common.emf,
+ org.eclipse.wst.common.project.facet.core
Export-Package: org.eclipse.jpt.jpadiagrameditor.ui.internal,
org.eclipse.jpt.jpadiagrameditor.ui.internal.dialog,
org.eclipse.jpt.jpadiagrameditor.ui.internal.feature,
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
index 515a128..09eb969 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java
@@ -19,7 +19,6 @@
import java.util.Enumeration;
import java.util.List;
import java.util.ListIterator;
-import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -116,10 +115,9 @@
jpaProject = jpt.getJpaProject();
targetProject = jpaProject.getProject();
}
- Properties props = JPADiagramPropertyPage.loadProperties(jpaProject.getProject());
String entityName = getFeatureProvider().getJPAEditorUtil().
generateUniqueEntityName(jpaProject,
- JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject(), props),
+ JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
getFeatureProvider());
if(!checkIsSetPersistenceProviderLibrary(jpaProject)){
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java
index d33d820..15f7b60 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java
@@ -1,7 +1,6 @@
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;
import java.util.List;
-import java.util.Properties;
import org.eclipse.core.resources.IProject;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -56,12 +55,11 @@
targetProject = jpaProject.getProject();
}
- Properties props = JPADiagramPropertyPage.loadProperties(jpaProject.getProject());
String mappedSuperclassName = getFeatureProvider()
.getJPAEditorUtil()
.generateUniqueMappedSuperclassName(
jpaProject,
- JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject(), props),
+ JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()),
getFeatureProvider());
if (!JptJpaCorePlugin.discoverAnnotatedClasses(jpaProject.getProject())) {
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 172bb2b..ec699d4 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
@@ -510,6 +510,53 @@
}
return editorProps;
}
+
+ public static String getDefaultFolder(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return getDefaultFolder(project, props);
+ }
+
+ public static String getDefaultPackage(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return getDefaultPackage(project, props);
+ }
+
+ public static String getDefaultTablePrefixName(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return getDefaultTablePrefixName(project, props);
+ }
+
+ public static boolean doesDirecteEditingAffectClassNameByDefault(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return doesDirecteEditingAffectClassNameByDefault(project, props);
+ }
+
+ public static boolean isAccessFieldBased(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return isAccessFieldBased(project, props);
+ }
+
+ public static boolean isCollectionType(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return isCollectionType(project, props);
+ }
+
+ public static boolean isListType(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return isListType(project, props);
+ }
+
+ public static boolean isSetType(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return isSetType(project, props);
+ }
+
+ public static boolean shouldOneToManyUnidirBeOldStyle(IProject project) {
+ Properties props = JPADiagramPropertyPage.loadProperties(project);
+ return shouldOneToManyUnidirBeOldStyle(project, props);
+ }
+
+//---------------------------------------------------------------------------------------------------
public static String getDefaultFolder(IProject project, Properties props) {
return props.getProperty(PROP_DEFAULT_DIAGRAM_FOLDER.getLocalName());
@@ -546,4 +593,9 @@
String accessType = props.getProperty(PROP_COLLECTION_TYPE.getLocalName());
return accessType.equals("set"); //$NON-NLS-1$;
}
+
+ public static boolean shouldOneToManyUnidirBeOldStyle(IProject project, Properties props) {
+ return Boolean.parseBoolean(props.getProperty(PROP_ONE_TO_MANY_OLD_STYLE.getLocalName()));
+ }
+
}
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 a8121d4..e4a67e8 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
@@ -251,7 +251,7 @@
return null;
StringBuilder res = new StringBuilder(strIt.next());
while (strIt.hasNext()) {
- res.append(" ,"); //$NON-NLS-1$
+ res.append(", "); //$NON-NLS-1$
res.append(strIt.next());
}
return res.toString();
@@ -1111,8 +1111,7 @@
IFile file = folder.getFile(mappedSuperclassShortName + ".java"); //$NON-NLS-1$
if (!file.exists()) {
- Properties props = JPADiagramPropertyPage.loadProperties(project);
- String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project, props) + ";\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ String content = "package " + JPADiagramPropertyPage.getDefaultPackage(project) + ";\n\n" //$NON-NLS-1$ //$NON-NLS-2$
+ "import javax.persistence.*;\n\n" //$NON-NLS-1$
+ "@MappedSuperclass \n" //$NON-NLS-1$
+ "public class " + mappedSuperclassShortName + " {\n\n" //$NON-NLS-1$ //$NON-NLS-2$
@@ -1153,8 +1152,7 @@
}
IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[0];
- Properties props = JPADiagramPropertyPage.loadProperties(project);
- IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(JPADiagramPropertyPage.getDefaultPackage(project, props));
+ IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(JPADiagramPropertyPage.getDefaultPackage(project));
if(!packageFragment.exists())
return false;
IFolder folder = null;
@@ -1361,20 +1359,24 @@
return checkJPAFacetVersion(jpaProject.getProject(), version);
}
+
static public boolean checkJPAFacetVersion(IProject project, String version) {
IFacetedProject fproj = null;
try {
fproj = ProjectFacetsManager.create(project);
} catch (CoreException e) {
+ System.err.println("Could not create faceted project from " + project.getName()); //$NON-NLS-1$
+ e.printStackTrace();
}
Set<IProjectFacetVersion> projFacets = fproj.getProjectFacets();
Iterator<IProjectFacetVersion> it = projFacets.iterator();
while (it.hasNext()) {
IProjectFacetVersion fv = it.next();
- if (fv.getProjectFacet().getId().equals("jpt.jpa")) //$NON-NLS-1$
- return fv.getVersionString().equals(version);
+ if (fv.getProjectFacet().getId().equals("jpt.jpa")) { //$NON-NLS-1$
+ return fv.getVersionString().equals(version);
+ }
}
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/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index fa8668c..27a7024 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
@@ -16,6 +16,7 @@
package org.eclipse.jpt.jpadiagrameditor.ui.internal.util;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
@@ -47,10 +48,14 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.ui.refactoring.RenameSupport;
+import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.MappingKeys;
+import org.eclipse.jpt.jpa.core.context.AttributeMapping;
+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;
@@ -65,10 +70,19 @@
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.resource.java.Annotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.AttributeOverridesAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.EmbeddedIdAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.JoinColumnsAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NestableAttributeOverrideAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.NestableJoinColumnAnnotation;
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;
@@ -81,9 +95,10 @@
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
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.ManyToManyBiDirRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation;
@@ -92,10 +107,6 @@
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.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
-import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
-import org.eclipse.jpt.common.core.JptResourceModel;
-import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
@@ -227,9 +238,104 @@
JavaPersistentAttribute resolvedManySideAttribute = (JavaPersistentAttribute) manySideJPT
.resolveAttribute(manySideAttribute.getName());
resolvedManySideAttribute.setMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ } else {
+ addJoinColumnIfNecessary(resolvedSingleSideAttribute, singleSideJPT, fp);
}
}
+ private void addJoinColumnIfNecessary(JavaPersistentAttribute jpa,
+ JavaPersistentType jpt, IFeatureProvider fp) {
+
+ if (JPAEditorUtil.checkJPAFacetVersion(jpa.getJpaProject(), "1.0") || //$NON-NLS-1$
+ JPADiagramPropertyPage.shouldOneToManyUnidirBeOldStyle(jpa
+ .getJpaProject().getProject()))
+ return;
+ JavaPersistentAttribute[] ids = getIds(jpt);
+ if (ids.length == 0)
+ return;
+ final String tableName = getTableName(jpt);
+ if (ids.length == 1) {
+ if (isSimpleId(ids[0])) {
+ JoinColumnAnnotation an = (JoinColumnAnnotation) jpa
+ .getResourcePersistentAttribute().addAnnotation(
+ JoinColumnAnnotation.ANNOTATION_NAME);
+ String idColName = getColumnName(ids[0]);
+ an.setName(tableName + "_" + idColName); //$NON-NLS-1$
+ an.setReferencedColumnName(idColName);
+ } else {
+ Hashtable<String, String> atNameToColName = getOverriddenColNames(ids[0]);
+ JoinColumnsAnnotation an = (JoinColumnsAnnotation) jpa
+ .getResourcePersistentAttribute().addAnnotation(
+ JoinColumnsAnnotation.ANNOTATION_NAME);
+ PersistenceUnit pu = getPersistenceUnit(jpt);
+ String embeddableTypeName = ids[0].getTypeName();
+ Embeddable emb = pu.getEmbeddable(embeddableTypeName);
+ Iterator<AttributeMapping> amIt = emb.allAttributeMappings();
+ while (amIt.hasNext()) {
+ AttributeMapping am = amIt.next();
+ NestableJoinColumnAnnotation jc = an.addNestedAnnotation();
+ JavaPersistentAttribute at = (JavaPersistentAttribute) am
+ .getPersistentAttribute();
+ String idColName = atNameToColName.get(at.getName());
+ idColName = (idColName != null) ? idColName
+ : getColumnName(at);
+ jc.setName(tableName + "_" + idColName); //$NON-NLS-1$
+ jc.setReferencedColumnName(idColName);
+ }
+ }
+ } else {
+ JoinColumnsAnnotation an = (JoinColumnsAnnotation) jpa
+ .getResourcePersistentAttribute().addAnnotation(
+ JoinColumnsAnnotation.ANNOTATION_NAME);
+ for (JavaPersistentAttribute idAt : ids) {
+ NestableJoinColumnAnnotation jc = an.addNestedAnnotation();
+ String idColName = getColumnName(idAt);
+ jc.setName(tableName + "_" + idColName); //$NON-NLS-1$
+ jc.setReferencedColumnName(idColName);
+ }
+ }
+ }
+
+ private Hashtable<String, String> getOverriddenColNames(
+ JavaPersistentAttribute embIdAt) {
+ Hashtable<String, String> res = new Hashtable<String, String>();
+ AttributeOverrideAnnotation aon = (AttributeOverrideAnnotation) embIdAt
+ .getResourcePersistentAttribute().getAnnotation(
+ AttributeOverrideAnnotation.ANNOTATION_NAME);
+ if (aon != null) {
+ ColumnAnnotation colAn = aon.getColumn();
+ if (colAn == null)
+ return res;
+ String colName = colAn.getName();
+ if (colName == null)
+ return res;
+ res.put(aon.getName(), colName);
+ return res;
+ }
+ AttributeOverridesAnnotation aosn = (AttributeOverridesAnnotation) embIdAt
+ .getResourcePersistentAttribute().getAnnotation(
+ AttributeOverridesAnnotation.ANNOTATION_NAME);
+ if (aosn == null)
+ return res;
+ Iterable<NestableAttributeOverrideAnnotation> it = aosn
+ .getNestedAnnotations();
+ if (it == null)
+ return res;
+ Iterator<NestableAttributeOverrideAnnotation> iter = it.iterator();
+ while (iter.hasNext()) {
+ NestableAttributeOverrideAnnotation an = iter.next();
+ ColumnAnnotation colAn = an.getColumn();
+ if (colAn == null)
+ continue;
+ String colName = colAn.getName();
+ if (colName == null)
+ continue;
+ res.put(an.getName(), colName);
+ }
+ return res;
+ }
+
+
public void addManyToOneUnidirectionalRelation(IFeatureProvider fp, JavaPersistentType jpt,
JavaPersistentAttribute attribute) {
@@ -2142,5 +2248,44 @@
public JpaProject getJpaProject(IProject project) throws CoreException {
return JptJpaCorePlugin.getJpaProject(project);
}
+
+ public JavaPersistentAttribute[] getIds(JavaPersistentType jpt) {
+ ListIterator<JavaPersistentAttribute> attribsIter = jpt.attributes();
+ ArrayList<JavaPersistentAttribute> res = new ArrayList<JavaPersistentAttribute>();
+ while (attribsIter.hasNext()) {
+ JavaPersistentAttribute at = attribsIter.next();
+ if (isId(at))
+ res.add(at);
+ }
+ JavaPersistentAttribute[] ret = new JavaPersistentAttribute[res.size()];
+ return res.toArray(ret);
+ }
+
+ public boolean isId(JavaPersistentAttribute jpa) {
+ return isSimpleId(jpa) || isEmbeddedId(jpa);
+ }
+
+ public boolean isSimpleId(JavaPersistentAttribute jpa) {
+ IdAnnotation an = (IdAnnotation)jpa.getResourcePersistentAttribute().getAnnotation(IdAnnotation.ANNOTATION_NAME);
+ return (an != null);
+ }
+
+ public boolean isEmbeddedId(JavaPersistentAttribute jpa) {
+ EmbeddedIdAnnotation an = (EmbeddedIdAnnotation)jpa.getResourcePersistentAttribute().getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME);
+ return (an != null);
+ }
+
+ public String getColumnName(JavaPersistentAttribute jpa) {
+ String columnName= null;
+ ColumnAnnotation an = (ColumnAnnotation)jpa.
+ getResourcePersistentAttribute().
+ getAnnotation(ColumnAnnotation.ANNOTATION_NAME);
+ if (an != null)
+ columnName = an.getName();
+ if (columnName == null)
+ columnName = jpa.getName();
+ return columnName;
+ }
+
}
\ No newline at end of file