Author: dgeraskov
Date: 2009-10-27 06:14:50 -0400 (Tue, 27 Oct 2009)
New Revision: 18302
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5052
Set default id to "id" column if no id candidate found.
Updated hierarchy search.
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-10-27
05:58:58 UTC (rev 18301)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-10-27
10:14:50 UTC (rev 18302)
@@ -263,8 +263,7 @@
while (it.hasNext()) {
String name = it.next();
String check = name.toLowerCase();
- if ("id".equalsIgnoreCase(check) //$NON-NLS-1$
- || "identity".equalsIgnoreCase(check)) { //$NON-NLS-1$
+ if ("id".equalsIgnoreCase(check)) { //$NON-NLS-1$
primaryIdName = name;
break;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2009-10-27
05:58:58 UTC (rev 18301)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2009-10-27
10:14:50 UTC (rev 18302)
@@ -51,6 +51,7 @@
import org.hibernate.mapping.Column;
import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.JoinedSubclass;
+import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.OneToOne;
@@ -180,6 +181,14 @@
subclass.setEntityName(pastClass.getEntityName());
subclass.setDiscriminatorValue(StringHelper.unqualify(pastClass.getClassName()));
subclass.setAbstract(pastClass.isAbstract());
+ if (subclass instanceof JoinedSubclass) {
+ ((JoinedSubclass) subclass).setTable(new
Table(pastClass.getClassName().toUpperCase()));
+ ((JoinedSubclass) subclass).setKey((KeyValue)
pc.getIdentifierProperty().getValue());
+ }
+ Iterator it = pastClass.getPropertyIterator();
+ while (it.hasNext()) {
+ subclass.addProperty((Property) it.next());
+ }
entry.setValue(subclass);
}
} catch (JavaModelException e) {
@@ -192,9 +201,13 @@
private PersistentClass getMappedSuperclass(IJavaProject project, Map<String,
PersistentClass> persistentClasses, RootClass rootClass) throws JavaModelException{
IType type = Utils.findType(project, rootClass.getClassName());
//TODO not direct superclass?
- if (type.getSuperclassName() != null
- && persistentClasses.get(type.getSuperclassName()) != null){
- return persistentClasses.get(type.getSuperclassName());
+ if (type.getSuperclassName() != null){
+ String[][] supertypes = type.resolveType(type.getSuperclassName());
+ if (supertypes != null){
+ String supertype = supertypes[0][0].length() > 0 ? supertypes[0][0] + '.'
+ supertypes[0][1]
+ : supertypes[0][1];
+ return persistentClasses.get(supertype);
+ }
}
return null;
}
@@ -280,14 +293,19 @@
for (int i = 0; i < fields.length; i++) {
Iterator<VariableDeclarationFragment> itFieldsNames =
fields[i].fragments().iterator();
while(itFieldsNames.hasNext()) {
- VariableDeclarationFragment field = itFieldsNames.next();
- if ("id".equals(field.getName().getIdentifier()) //$NON-NLS-1$
- || "identity".equals(field.getName().getIdentifier())){ //$NON-NLS-1$
- entityInfo.setPrimaryIdName(field.getName().getIdentifier());
+ VariableDeclarationFragment variable = itFieldsNames.next();
+ Type type = ((FieldDeclaration)variable.getParent()).getType();
+ if ("id".equals(variable.getName().getIdentifier()) //$NON-NLS-1$
+ && !type.isArrayType()
+ && !Utils.isImplementInterface(new ITypeBinding[]{type.resolveBinding()},
Collection.class.getName())){
+ entityInfo.setPrimaryIdName(variable.getName().getIdentifier());
return true;
- } else if ("".equals(firstFieldName)){ //$NON-NLS-1$
+ } else if ("".equals(firstFieldName)//$NON-NLS-1$
+ && !type.isArrayType()
+ && !Utils.isImplementInterface(
+ new ITypeBinding[]{type.resolveBinding()}, Collection.class.getName())){
//set first field as id
- firstFieldName = field.getName().getIdentifier();
+ firstFieldName = variable.getName().getIdentifier();
}
}
}
@@ -296,6 +314,20 @@
return true;
}
+ @Override
+ public void endVisit(TypeDeclaration node) {
+ if (rootClass.getIdentifierProperty() == null){
+ //root class should always has id
+ SimpleValue sValue = new SimpleValue();
+ sValue.addColumn(new Column("id".toUpperCase()));//$NON-NLS-1$
+ sValue.setTypeName(Long.class.getName());
+ Property prop = new Property();
+ prop.setName("id"); //$NON-NLS-1$
+ prop.setValue(sValue);
+ rootClass.setIdentifierProperty(prop);
+ }
+ }
+
@SuppressWarnings("unchecked")
public boolean visit(FieldDeclaration node) {
Type type = node.getType();
@@ -519,7 +551,7 @@
} else if (value instanceof org.hibernate.mapping.Map){
SimpleValue map_key = new SimpleValue();
//FIXME: how to detect key-type here
- map_key.setTypeName("String"); //$NON-NLS-1$
+ map_key.setTypeName("string"); //$NON-NLS-1$
((IndexedCollection)value).setIndex(map_key);
}
prop.setCascade("none");//$NON-NLS-1$