Author: mdryakhlenkov
Date: 2007-08-06 11:37:16 -0400 (Mon, 06 Aug 2007)
New Revision: 2918
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java
Log:
EXIN-413: Incorrect relations between elements of diagram
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java 2007-08-06
15:00:45 UTC (rev 2917)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java 2007-08-06
15:37:16 UTC (rev 2918)
@@ -62,28 +62,30 @@
Iterator iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
Property field = (Property)iterator.next();
- if (!field.isComposite()) {
- boolean typeIsAccessible = true;
- if (field.getValue().isSimpleValue() &&
((SimpleValue)field.getValue()).isTypeSpecified()) {
- try {
- field.getValue().getType();
- } catch (Exception e) {
- typeIsAccessible = false;
+ if (!field.isBackRef()) {
+ if (!field.isComposite()) {
+ boolean typeIsAccessible = true;
+ if (field.getValue().isSimpleValue() &&
((SimpleValue)field.getValue()).isTypeSpecified()) {
+ try {
+ field.getValue().getType();
+ } catch (Exception e) {
+ typeIsAccessible = false;
+ }
}
- }
- if (field.getValue().isSimpleValue() &&
!((SimpleValue)field.getValue()).isTypeSpecified()) {
- bodyOrmShape = new Shape(field);
- } else if (typeIsAccessible && field.getValue().getType().isEntityType()) {
+ if (field.getValue().isSimpleValue() &&
!((SimpleValue)field.getValue()).isTypeSpecified()) {
+ bodyOrmShape = new Shape(field);
+ } else if (typeIsAccessible && field.getValue().getType().isEntityType())
{
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (typeIsAccessible &&
field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
bodyOrmShape = new ExpandeableShape(field);
- } else if (typeIsAccessible &&
field.getValue().getType().isCollectionType()) {
- bodyOrmShape = new ComponentShape(field);
- } else {
- bodyOrmShape = new Shape(field);
+ getChildren().add(bodyOrmShape);
}
- getChildren().add(bodyOrmShape);
- } else {
- bodyOrmShape = new ExpandeableShape(field);
- getChildren().add(bodyOrmShape);
}
}
} else if (ormElement instanceof Subclass) {
@@ -106,37 +108,41 @@
Iterator iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
Property field = (Property)iterator.next();
- if (!field.isComposite()) {
- if (field.getValue().isSimpleValue()) {
- bodyOrmShape = new Shape(field);
- } else if (field.getValue().getType().isEntityType()) {
+ if (!field.isBackRef()) {
+ if (!field.isComposite()) {
+ if (field.getValue().isSimpleValue()) {
+ bodyOrmShape = new Shape(field);
+ } else if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
bodyOrmShape = new ExpandeableShape(field);
- } else if (field.getValue().getType().isCollectionType()) {
- bodyOrmShape = new ComponentShape(field);
- } else {
- bodyOrmShape = new Shape(field);
+ getChildren().add(bodyOrmShape);
}
- getChildren().add(bodyOrmShape);
- } else {
- bodyOrmShape = new ExpandeableShape(field);
- getChildren().add(bodyOrmShape);
}
}
Iterator iter = ((Subclass)ormElement).getPropertyIterator();
while (iter.hasNext()) {
Property property = (Property)iter.next();
- if (!property.isComposite()) {
- if (property.getValue().getType().isEntityType()) {
+ if (!property.isBackRef()) {
+ if (!property.isComposite()) {
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ } else {
bodyOrmShape = new ExpandeableShape(property);
- } else if (property.getValue().getType().isCollectionType()) {
- bodyOrmShape = new ComponentShape(property);
- } else {
- bodyOrmShape = new Shape(property);
}
- } else {
- bodyOrmShape = new ExpandeableShape(property);
+ getChildren().add(bodyOrmShape);
}
- getChildren().add(bodyOrmShape);
}
} else if (ormElement instanceof Table) {
Iterator iterator = ((Table)getOrmElement()).getColumnIterator();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java 2007-08-06
15:00:45 UTC (rev 2917)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java 2007-08-06
15:37:16 UTC (rev 2918)
@@ -23,6 +23,8 @@
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
+import org.hibernate.type.EntityType;
+import org.hibernate.type.ManyToOneType;
public class OrmModelNameVisitor /*implements IOrmModelVisitor*/ {
@@ -42,204 +44,6 @@
this.viewer = viewer;
}
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitOrmModel(org.jboss.tools.hibernate.core.IOrmProject,
java.lang.Object)
- */
-// public Object visitOrmProject(IOrmProject schema, Object argument) {
-// return schema.getName();
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitDatabaseSchema(org.jboss.tools.hibernate.core.IDatabaseSchema,
java.lang.Object)
- */
-// public Object visitDatabaseSchema(IDatabaseSchema schema, Object argument) {
-// if (schema.getName() == null || schema.getName().trim().length() == 0) {
-// return BUNDLE
-// .getString("OrmModelNameVisitor.DefaultDatabaseSchema");
-// } else {
-// return schema.getName();
-// }
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitDatabaseTable(org.jboss.tools.hibernate.core.IDatabaseTable,
java.lang.Object)
- */
-// public Object visitDatabaseTable(IDatabaseTable table, Object argument) {
-// // Table name (Class1, Class2 ...)
-// // add tau 13.04.2005
-// // edit tau 28.04.2005 -> vs ()
-// StringBuffer name = new StringBuffer();
-// name.append(table.getName());
-//
-// IPersistentClassMapping[] classMappings = table
-// .getPersistentClassMappings();
-// if (classMappings.length != 0) {
-// name.append(POINTER);
-// for (int i = 0; i < classMappings.length; i++) {
-// IPersistentClass persistentClass = classMappings[i]
-// .getPersistentClass();
-// if (persistentClass != null) {
-// name.append(persistentClass.getName());
-// name.append(BUNDLE.getString("OrmModelNameVisitor.Comma"));
-// name.append(" ");
-// }
-// }
-// name.delete(name.length() - 2, name.length());
-// }
-// return name.toString();
-//
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitDatabaseColumn(org.jboss.tools.hibernate.core.IDatabaseColumn,
java.lang.Object)
- */
-// public Object visitDatabaseColumn(IDatabaseColumn column, Object argument) {
-// // update tau 16.03.2005
-// StringBuffer name = new StringBuffer();
-// name.append(column.getName());
-// //by Nick 22.04.2005
-//
-// int length = -1;
-// int scale = -1;
-//
-// if (!column.isNativeType()) {
-// int typeCode = column.getSqlTypeCode();
-// String typeName = column.getSqlTypeName();
-//
-// if (typeName == null)
-// typeCode = Types.NULL;
-//
-// //by Nick
-//
-// // (tau->tau) Column types should be shown in the following manner:
-// /*
-//
-// Character types:
-// VARCHAR(length)
-// CHAR(length)
-//
-// Numeric types:
-// NUMBER(length, precision)
-// NUMERIC(length, precision)
-//
-// Other types:
-// BIT
-// INTEGER
-// BIGNINT
-// DATE
-// FLOAT
-// REAL
-// CLOB
-// BINARY
-// etc. */
-// //by Nick 22.04.2005
-// // TODO (tau->tau)
-// // testing for ORACLE
-// // edit tau 28.04.2005 -> vs ()
-// switch (typeCode) {
-// case Types.VARCHAR:
-// case Types.CHAR:
-// case Types.NUMERIC:
-// case Types.DECIMAL: //8.07.2005 by Nick DECIMAL JDBC type denotes Oracle NUMBER type
-// //changed by Nick 10.05.2005 - fixes "->" in SQL types
-// if (typeCode == Types.NUMERIC || typeCode == Types.DECIMAL) {
-// length = column.getPrecision();
-// scale = column.getScale();
-// } else {
-// length = column.getLength();
-// }
-//
-// default:
-// break;
-//
-// }
-// } else {
-// if (column.getLength() > Column.DEFAULT_LENGTH) {
-// length = column.getLength();
-// } else if (column.getPrecision() > Column.DEFAULT_PRECISION
-// || column.getScale() > Column.DEFAULT_SCALE) {
-// length = column.getPrecision() > Column.DEFAULT_PRECISION ? (column
-// .getPrecision())
-// : (column.getScale() > 0 ? column.getScale() : 1);
-// scale = column.getScale();
-// }
-// }
-//
-// StringBuffer typeName = new StringBuffer(column.getSqlTypeName());
-//
-// //by Nick
-//
-// // (tau->tau) Column types should be shown in the following manner:
-// /*
-//
-// Character types:
-// VARCHAR(length)
-// CHAR(length)
-//
-// Numeric types:
-// NUMBER(length, precision)
-// NUMERIC(length, precision)
-//
-// Other types:
-// BIT
-// INTEGER
-// BIGNINT
-// DATE
-// FLOAT
-// REAL
-// CLOB
-// BINARY
-// etc. */
-// //by Nick 22.04.2005
-// /*
-// switch (key) {
-// case value:
-//
-// break;
-//
-// default:
-// break;
-// }
-// */
-//
-// // TODO (tau->tau)
-// // testing for ORACLE
-//
-// StringBuffer lpBuffer = new StringBuffer();
-// //name.append(POINTER);
-//
-// if (length > Column.DEFAULT_LENGTH) {
-// lpBuffer.append(SPACE);
-// lpBuffer.append(BUNDLE
-// .getString("OrmModelNameVisitor.OpenBrackets"));
-// lpBuffer.append(length);
-// if (scale > Column.DEFAULT_SCALE) {
-// lpBuffer.append(BUNDLE.getString("OrmModelNameVisitor.Comma"));
-// lpBuffer.append(SPACE);
-// lpBuffer.append(scale);
-// }
-// lpBuffer.append(BUNDLE
-// .getString("OrmModelNameVisitor.CloseBrackets"));
-// }
-// //by Nick
-//
-// if (typeName.length() != 0) {
-// // edit tau 28.04.2005 -> vs ()
-// //8.07.2005 by Nick DECIMAL JDBC type denotes Oracle NUMBER type
-// //changed by Nick 10.05.2005 - fixes "->" in SQL types
-// name.append(BUNDLE.getString("OrmModelNameVisitor.Colon"));
-// name.append(SPACE);
-// typeName.append(lpBuffer);
-// }
-//
-// name.append(typeName);
-// // name.append(SPACE);
-//
-// // by Nick
-// return name.toString();
-//
-// }
-
public Object visitDatabaseColumn(Column column, Object argument) {
// update tau 16.03.2005
StringBuffer name = new StringBuffer();
@@ -406,68 +210,6 @@
}
- /* (non-Javadoc)
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitDatabaseConstraint(org.jboss.tools.hibernate.core.IDatabaseConstraint,
java.lang.Object)
- */
-// public Object visitDatabaseConstraint(IDatabaseConstraint constraint,
-// Object argument) {
-// return constraint.getName();
-// }
-
- /* (non-Javadoc)
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPackage(org.jboss.tools.hibernate.core.IPackage,
java.lang.Object)
- */
-// public Object visitPackage(IPackage pakage, Object argument) {
-// if (pakage.getName() == null || pakage.getName().trim().length() == 0) {
-// return BUNDLE.getString("OrmModelNameVisitor.DefaultPackageName");
-// } else {
-// //return pakage.getName();
-// return pakage.getProjectQualifiedName();
-// }
-// }
-
- /* (non-Javadoc)
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitMapping(org.jboss.tools.hibernate.core.IMapping,
java.lang.Object)
- */
-// public Object visitMapping(IMapping mapping, Object argument) {
-// return mapping.getName();
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitMappingStorage(org.jboss.tools.hibernate.core.IMappingStorage,
java.lang.Object)
- */
-// public Object visitMappingStorage(IMappingStorage storage, Object argument) {
-// return storage.getName();
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPersistentClass(org.jboss.tools.hibernate.core.IPersistentClass,
java.lang.Object)
- */
-// public Object visitPersistentClass(IPersistentClass clazz, Object argument) {
-//
-// StringBuffer name = new StringBuffer();
-// if (((OrmContentProvider) viewer.getContentProvider()).getTip() ==
OrmContentProvider.PACKAGE_CLASS_FIELD_CONTENT_PROVIDER) {
-// name.append(clazz.getShortName());
-// } else {
-// name.append(clazz.getName());
-// }
-//
-// //edit tau 24.04.2006
-// IDatabaseTable table = clazz.getDatabaseTable(); // upd tau 06.06.2005
-// //IDatabaseTable table = HibernateAutoMappingHelper.getPrivateTable(classMapping); //
upd tau 18.04.2005
-// if (table != null) {
-// String tableName = table.getName();
-// if (tableName != null) {
-// //name.append(" (");
-// name.append(POINTER);
-// name.append(tableName);
-// //name.append(")");
-// }
-// }
-//
-// return name.toString();
-// }
-
public Object visitPersistentClass(RootClass clazz, Object argument) {
StringBuffer name = new StringBuffer();
@@ -502,208 +244,38 @@
public Object visitPersistentClass(Subclass clazz, Object argument) {
StringBuffer name = new StringBuffer();
-// if (((OrmContentProvider) viewer.getContentProvider()).getTip() ==
OrmContentProvider.PACKAGE_CLASS_FIELD_CONTENT_PROVIDER) {
- name.append(clazz.getEntityName());
-// } else {
-// name.append(clazz.getEntityName());
-// }
+ name.append(clazz.getEntityName());
- //edit tau 24.04.2006
- Table table = clazz.getTable(); // upd tau 06.06.2005
- //IDatabaseTable table = HibernateAutoMappingHelper.getPrivateTable(classMapping); //
upd tau 18.04.2005
+ Table table = clazz.getTable();
if (table != null) {
- String tableName = table.getName();
+ String tableName = TextUtil.getTableName(table);
if (tableName != null) {
- //name.append(" (");
name.append(POINTER);
name.append(tableName);
- //name.append(")");
}
}
return name.toString();
}
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPersistentField(org.jboss.tools.hibernate.core.IPersistentField,
java.lang.Object)
- */
-// public Object visitPersistentField(IPersistentField field, Object argument) {
-// StringBuffer name = new StringBuffer();
-// name.append(field.getName());
-// name.append(BUNDLE.getString("OrmModelNameVisitor.Colon"));
-// String typeString = field.getType();
-//
-// if (typeString != null) {
-// //added by Nick 31.03.2005
-// IPersistentValueMapping value = null;
-// if (field.getMapping() != null)
-// value = field.getMapping().getPersistentValueMapping();
-//
-// //added by Nick 18.04.2005 - to handle BLOB mappings
-// if (Signature.getArrayCount(typeString) != 0) {
-// // changed by Nick 20.10.2005
-// int depth = Signature.getArrayCount(typeString);
-// typeString = Signature.getElementType(typeString);
-// for (int i = 0; i < depth; i++) {
-// typeString += "[]";
-// }
-// // by Nick
-// }
-//
-// //by Nick
-// if (value != null && value instanceof CollectionMapping
-// && !(value instanceof ArrayMapping)) {
-// String elementsClsName = ((CollectionMapping) value)
-// .getCollectionElementClassName();
-// if (elementsClsName != null)
-// typeString = field.getType() + "(" + elementsClsName + ")";
-// }
-//
-// if (value != null && value instanceof CollectionMapping) {
-// //added by Nick 12.05.2005 to show collection table in explorer
-// IDatabaseTable collectionTable = ((CollectionMapping) value)
-// .getCollectionTable();
-// if (collectionTable != null
-// && collectionTable.getShortName() != null)
-// typeString += POINTER + collectionTable.getShortName();
-// //by Nick
-// }
-// //by Nick
-// name.append(typeString);
-//
-// // added by Nick 29.07.2005
-// if (field.getGenerifiedTypes() != null) {
-// String[] types = field.getGenerifiedTypes();
-//
-// StringBuffer buf = new StringBuffer("<");
-//
-// for (int i = 0; i < types.length; i++) {
-// String string = types[i];
-// buf.append(string);
-//
-// if (i != types.length - 1)
-// buf.append(", ");
-// }
-//
-// buf.append(">");
-//
-// name.append(buf);
-// }
-// // by Nick
-// }
-// return name.toString();
-//
-// }
-
public Object visitPersistentField(Property field, Object argument) {
StringBuffer name = new StringBuffer();
name.append(field.getName());
name.append(BUNDLE.getString("OrmModelNameVisitor.Colon"));
- String typeString = "";
- try {
+ String typeString = null;
+ if (field.getType().isEntityType()) {
+ typeString = ((EntityType)field.getType()).getAssociatedEntityName();
+ } else {
typeString = field.getType().getReturnedClass().getName();
- } catch (Exception e) {}
-
+ }
if (typeString != null) {
-/* IPersistentValueMapping value = null;
- if (field.getMapping() != null)
- value = field.getMapping().getPersistentValueMapping();
-
- if (Signature.getArrayCount(typeString) != 0)
- {
- int depth = Signature.getArrayCount(typeString);
- typeString = Signature.getElementType(typeString);
- for (int i = 0; i < depth; i++) {
- typeString += "[]";
- }
- }
-
- if (value != null && value instanceof CollectionMapping &&
!(value instanceof ArrayMapping))
- {
- String elementsClsName =
((CollectionMapping)value).getCollectionElementClassName();
- if (elementsClsName != null)
- typeString = field.getType() + "(" + elementsClsName +
")";
- }
-
- if (value != null && value instanceof CollectionMapping)
- {
- IDatabaseTable collectionTable =
((CollectionMapping)value).getCollectionTable();
- if (collectionTable != null && collectionTable.getShortName() !=
null)
- typeString += POINTER + collectionTable.getShortName();
- }*/
name.append(typeString);
-
-/* if (field.getGenerifiedTypes() != null)
- {
- String[] types = field.getGenerifiedTypes();
-
- StringBuffer buf = new StringBuffer("<");
-
- for (int i = 0; i < types.length; i++) {
- String string = types[i];
- buf.append(string);
-
- if (i != types.length - 1)
- buf.append(", ");
- }
-
- buf.append(">");
-
- name.append(buf);
- }*/
- }
+ }
+
return name.toString();
}
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPersistentClassMapping(org.jboss.tools.hibernate.core.IPersistentClassMapping,
java.lang.Object)
- */
-// public Object visitPersistentClassMapping(IPersistentClassMapping mapping,
-// Object argument) {
-// // add tau 22.04.2005
-// // Class mapping should be shown as Class name -> table name
-//
-// StringBuffer name = new StringBuffer();
-// name.append(mapping.getName());
-//
-// IDatabaseTable table = HibernateAutoMappingHelper
-// .getPrivateTable(mapping); // upd tau 22.04.2005
-// if (table != null) {
-// String tableName = table.getName();
-// if (tableName != null) {
-// name.append(POINTER);
-// name.append(tableName);
-// }
-// }
-//
-// return name.toString();
-//
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPersistentFieldMapping(org.jboss.tools.hibernate.core.IPersistentFieldMapping,
java.lang.Object)
- */
-// public Object visitPersistentFieldMapping(IPersistentFieldMapping mapping,
-// Object argument) {
-// return mapping.getName();
-// }
-
- /**
- * @see
org.jboss.tools.hibernate.core.IOrmModelVisitor#visitPersistentValueMapping(org.jboss.tools.hibernate.core.IPersistentValueMapping,
java.lang.Object)
- */
-// public Object visitPersistentValueMapping(IPersistentValueMapping mapping,
-// Object argument) {
-// return mapping.getName();
-// }
-
- // add tau 27.07.2005
-// public Object visitNamedQueryMapping(INamedQueryMapping mapping,
-// Object argument) {
-// return mapping.getName();
-// }
-
-
public Object visitCollectionKeyMapping(DependantValue mapping, Object argument) {
return "key";
}