Author: achabatar
Date: 2007-12-04 03:46:07 -0500 (Tue, 04 Dec 2007)
New Revision: 5209
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
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-874
Calling buildMappings() is done only at the beginning, after that Mapping object is
retrieved from Map object.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java 2007-12-03
22:10:58 UTC (rev 5208)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java 2007-12-04
08:46:07 UTC (rev 5209)
@@ -31,7 +31,7 @@
import org.eclipse.gef.editpolicies.SelectionEditPolicy;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
-import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
@@ -71,11 +71,11 @@
while (model.getParent() != null) {
model = model.getParent();
}
- ConsoleConfiguration consoleConfiguration = null;
+ Configuration cfg = null;
if (model instanceof OrmDiagram) {
- consoleConfiguration = ((OrmDiagram) model).getConsoleConfiguration();
+ cfg = ((OrmDiagram) model).getConsoleConfiguration().getConfiguration();
}
- label.setText(ormLabelProvider.getText(getElement(), consoleConfiguration));
+ label.setText(ormLabelProvider.getText(getElement(), cfg));
label.setBackgroundColor(getColor());
label.setIcon(ormLabelProvider.getImage(getElement()));
label.setLabelAlignment(PositionConstants.LEFT);
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-03
22:10:58 UTC (rev 5208)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmLabelProvider.java 2007-12-04
08:46:07 UTC (rev 5209)
@@ -15,7 +15,6 @@
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -25,7 +24,6 @@
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;
@@ -35,7 +33,6 @@
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue;
-import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
@@ -86,7 +83,7 @@
return image;
}
- public String getText(Object element, ConsoleConfiguration consoleConfiguration) {
+ public String getText(Object element, Configuration cfg) {
if (element instanceof RootClass) {
String name = (String)ormModelNameVisitor.visitPersistentClass((RootClass)element,
null);
if (name == null) {
@@ -116,7 +113,7 @@
return name;
}
} else if (element instanceof Column) {
- String name = (String)ormModelNameVisitor.visitDatabaseColumn((Column)element,
consoleConfiguration);
+ String name = (String)ormModelNameVisitor.visitDatabaseColumn((Column)element, cfg);
if (name == null) {
return "OrmElement";
} else {
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-03
22:10:58 UTC (rev 5208)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.view/src/org/jboss/tools/hibernate/ui/view/views/OrmModelNameVisitor.java 2007-12-04
08:46:07 UTC (rev 5209)
@@ -10,11 +10,13 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.view.views;
+import java.util.HashMap;
+import java.util.Map;
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.dialect.Dialect;
import org.hibernate.eclipse.console.workbench.TypeNameValueVisitor;
import org.hibernate.engine.Mapping;
@@ -33,7 +35,7 @@
static private String SPACE = " ";
static private String POINTER = " -> ";
-
+
private ResourceBundle BUNDLE = ResourceBundle
.getBundle(OrmModelNameVisitor.class.getPackage().getName()
+ ".views");
@@ -41,44 +43,61 @@
public OrmModelNameVisitor() {
super();
}
+
+ private Map mappings = new HashMap();
+ private Map dialects = new HashMap();
public Object visitDatabaseColumn(Column column, Object argument) {
- ConsoleConfiguration consoleConfiguration = (ConsoleConfiguration) argument;
- Mapping mapping = consoleConfiguration.getConfiguration()
- .buildMapping();
-
- String dialectName = null;
+ Configuration cfg = null;
+ Mapping mapping = null;
Dialect dialect = null;
- String type = null;
- try {
- dialectName = consoleConfiguration.getConfiguration().getProperty(
- Environment.DIALECT);
- dialect = (Dialect) Class.forName(dialectName).newInstance();
- type = column.getSqlType(dialect, mapping);
- } catch (HibernateException e) {
- ViewPlugin.getDefault().logError(e);
- // ViewPlugin.getDefault().showError("Error", e);
- } catch (InstantiationException e) {
- ViewPlugin.getDefault().logError(e);
- } catch (IllegalAccessException e) {
- ViewPlugin.getDefault().logError(e);
- } catch (ClassNotFoundException e) {
- ViewPlugin.getDefault().logError(e);
+ if (argument instanceof Configuration) {
+
+ cfg = (Configuration) argument;
+
+ if (mappings.containsKey(cfg)) {
+ mapping = (Mapping) mappings.get(cfg);
+ } else {
+ mapping = cfg.buildMapping();
+ mappings.put(cfg, mapping);
+ }
+
+ try {
+ String dialectName = cfg.getProperty(Environment.DIALECT);
+ if (dialects.containsKey(dialectName)) {
+ dialect = (Dialect) dialects.get(dialectName);
+ } else {
+ dialect = (Dialect) Class.forName(dialectName).newInstance();
+ dialects.put(dialectName, dialect);
+ }
+ } catch (HibernateException e) {
+ ViewPlugin.getDefault().logError(e);
+ } catch (InstantiationException e) {
+ ViewPlugin.getDefault().logError(e);
+ } catch (IllegalAccessException e) {
+ ViewPlugin.getDefault().logError(e);
+ } catch (ClassNotFoundException e) {
+ ViewPlugin.getDefault().logError(e);
+ }
}
+ String type = column.getSqlType(dialect, mapping);
+
StringBuffer name = new StringBuffer();
name.append(column.getName());
- name.append(" [");
- name.append(type != null ? type.toUpperCase() : "");
- name.append(column.isNullable() ? " Nullable" : "");
- name.append(HibernateUtils.getTable(column) != null
- && HibernateUtils.isPrimaryKey(column) ? " PK" : "");
- name.append(HibernateUtils.getTable(column) != null
- && HibernateUtils.isForeignKey(column) ? " FK" : "");
- name.append("]");
+ if (type != null) {
+ name.append(" [");
+ name.append(type != null ? type.toUpperCase() : "");
+ name.append(column.isNullable() ? " Nullable" : "");
+ name.append(HibernateUtils.getTable(column) != null
+ && HibernateUtils.isPrimaryKey(column) ? " PK" : "");
+ name.append(HibernateUtils.getTable(column) != null
+ && HibernateUtils.isForeignKey(column) ? " FK" : "");
+ name.append("]");
+ }
return name.toString();