Author: dgeraskov
Date: 2007-12-26 06:16:58 -0500 (Wed, 26 Dec 2007)
New Revision: 5440
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmLabelProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1535
Get value type via console configuration loader.
Added some checks that type is accessible when we try to load it.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmLabelProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmLabelProvider.java 2007-12-26
11:16:53 UTC (rev 5439)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmLabelProvider.java 2007-12-26
11:16:58 UTC (rev 5440)
@@ -23,7 +23,7 @@
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
-import org.hibernate.cfg.Configuration;
+import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
@@ -94,7 +94,7 @@
return image;
}
- public String getText(Object element, Configuration cfg) {
+ public String getText(Object element, ConsoleConfiguration cfg) {
if (element instanceof RootClass) {
String name = (String)ormModelNameVisitor.visitPersistentClass((RootClass)element,
null);
if (name == null) {
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-12-26
11:16:53 UTC (rev 5439)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java 2007-12-26
11:16:58 UTC (rev 5440)
@@ -12,11 +12,13 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import java.util.ResourceBundle;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.dialect.Dialect;
import org.hibernate.eclipse.console.workbench.TypeNameValueVisitor;
import org.hibernate.engine.Mapping;
@@ -69,25 +71,27 @@
}
- public String getColumnSqlType(Column column, Object argument) {
+ public String getColumnSqlType(final Column column, Object argument) {
- Configuration cfg = null;
+ ConsoleConfiguration cfg = null;
Mapping mapping = null;
Dialect dialect = null;
+
+ String type = null;
- if (argument instanceof Configuration) {
+ if (argument instanceof ConsoleConfiguration) {
- cfg = (Configuration) argument;
+ cfg = (ConsoleConfiguration) argument;
- if (mappings.containsKey(cfg)) {
+ if (mappings.containsKey(cfg.getConfiguration())) {
mapping = (Mapping) mappings.get(cfg);
} else {
- mapping = cfg.buildMapping();
+ mapping = cfg.getConfiguration().buildMapping();
mappings.put(cfg, mapping);
}
try {
- String dialectName = cfg.getProperty(Environment.DIALECT);
+ String dialectName = cfg.getConfiguration().getProperty(Environment.DIALECT);
if (dialects.containsKey(dialectName)) {
dialect = (Dialect) dialects.get(dialectName);
} else {
@@ -103,9 +107,35 @@
} catch (ClassNotFoundException e) {
ViewPlugin.getDefault().logError(e);
}
+
+ final Mapping fMapping = mapping;
+ final Dialect fDialect = dialect;
+
+ try {
+ type = (String)cfg.execute( new Command() {
+ public Object execute() {
+ return column.getSqlType(fDialect, fMapping);
+ }});
+ } catch(Exception e){
+ }
}
-
- return column.getSqlType(dialect, mapping);
+
+ //if (type != null) {
+ return type;
+ /*} else {
+ if (column.getValue() instanceof SimpleValue) {
+ SimpleValue sValue = (SimpleValue) column.getValue();
+ Properties p = sValue.getTypeParameters();
+ if (p == null)
+ return null;
+ String propType = p.getProperty( "type" );
+ if ( propType != null ) {
+ int sqlType = Integer.decode( propType ).intValue();
+ return dialect.getTypeName( sqlType, column.getLength(), column.getPrecision(),
column.getScale() );
+ }
+ }
+ return null;
+ } */
}
public Object visitPersistentClass(RootClass clazz, Object argument) {
@@ -151,6 +181,7 @@
public Object visitPersistentField(Property field, Object argument) {
StringBuffer name = new StringBuffer();
name.append(field.getName());
+ name.append(" ");
name.append(BUNDLE.getString("OrmModelNameVisitor.Colon"));
String typeString = null;
@@ -159,26 +190,26 @@
} catch (Exception e) {
if (field.getValue() instanceof Component) {
typeString = ((Component)field.getValue()).getComponentClassName();
- } else if (field.getValue().isSimpleValue()) {
+ } else if (field.getValue()!= null && field.getValue().isSimpleValue()) {
typeString = ((SimpleValue)field.getValue()).getTypeName();
}
}
-
-
-
+
if (typeString != null) {
typeString = correctTypeString(typeString);
name.append(SPACE);
name.append(typeString);
+ return name.toString();
}
Value value = field.getValue();
- String typeName = (String) value.accept(new TypeNameValueVisitor(false));
-
- if (typeName!=null) {
- return field.getName() + " : " + typeName;
- }
-
+ String typeName = null;
+ if (value != null){
+ typeName = (String) value.accept(new TypeNameValueVisitor(false));
+ if (typeName!=null) {
+ return field.getName() + " : " + typeName;
+ }
+ }
return field.getName();
}