Author: dgeraskov
Date: 2012-01-18 03:59:34 -0500 (Wed, 18 Jan 2012)
New Revision: 37933
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.classpath
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.project
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.settings/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.settings/org.eclipse.jdt.core.prefs
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/build.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/bsh-core-2.0b4.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/jpa/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/log4j-1.2.15.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/antlr-2.7.6.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/cglib-2.2.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-collections-3.1.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-logging-1.0.4.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/dom4j-1.6.1.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/hibernate3.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/javassist-3.12.0.GA.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/jta-1.1.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-api-1.6.1.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-log4j12-1.6.1.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/freemarker.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/hibernate-tools-3.6.0.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/jtidy-r8-20060801.jar
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.xml
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/pom.xml
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeDelegatingDriver.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeTransactionManagerLookup.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/Hibernate3_6Plugin.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryExecutor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CompletionProposal.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EclipseHQLCompletionRequestor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterAttributes.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterDefinition.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExtensionManager.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/IconNameValueVisitor.java
Modified:
trunk/hibernatetools/features/org.hibernate.eclipse.feature/feature.xml
trunk/hibernatetools/plugins/pom.xml
Log:
https://issues.jboss.org/browse/JBIDE-10646
Added support for hibernate3.6
Modified: trunk/hibernatetools/features/org.hibernate.eclipse.feature/feature.xml
===================================================================
--- trunk/hibernatetools/features/org.hibernate.eclipse.feature/feature.xml 2012-01-18
01:56:00 UTC (rev 37932)
+++ trunk/hibernatetools/features/org.hibernate.eclipse.feature/feature.xml 2012-01-18
08:59:34 UTC (rev 37933)
@@ -139,6 +139,13 @@
unpack="false"/>
<plugin
+ id="org.jboss.tools.hibernate3_6"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
id="org.jboss.tools.hibernate4_0"
download-size="0"
install-size="0"
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.classpath
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.classpath
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.classpath 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib"
path="lib/required/slf4j-log4j12-1.6.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/cglib-2.2.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/commons-logging-1.0.4.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/tools/freemarker.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/tools/hibernate-tools-3.6.0.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/tools/jtidy-r8-20060801.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/bsh-core-2.0b4.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/log4j-1.2.15.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/antlr-2.7.6.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/commons-collections-3.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/dom4j-1.6.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/hibernate3.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/javassist-3.12.0.GA.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/jta-1.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/slf4j-api-1.6.1.jar"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.project
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.project
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.project 2012-01-18 08:59:34
UTC (rev 37933)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.hibernate3_6</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/.settings/org.eclipse.jdt.core.prefs 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,8 @@
+#Mon Sep 26 12:36:48 EEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,36 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Hibernate3_6
+Bundle-SymbolicName: org.jboss.tools.hibernate3_6;singleton:=true
+Bundle-Version: 3.4.0.qualifier
+Bundle-Activator: org.jboss.tools.hibernate3_6.Hibernate3_6Plugin
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.hibernate.eclipse;bundle-version="3.4.0",
+ org.eclipse.datatools.connectivity;bundle-version="1.2.2",
+ org.hibernate.eclipse.console;bundle-version="3.4.0",
+ org.eclipse.jface.text;bundle-version="3.7.0",
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.core.variables;bundle-version="3.2.500",
+ org.eclipse.jdt.core;bundle-version="3.7.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ClassPath: lib/required/antlr-2.7.6.jar,
+ lib/required/cglib-2.2.jar,
+ lib/required/commons-collections-3.1.jar,
+ lib/required/commons-logging-1.0.4.jar,
+ lib/required/dom4j-1.6.1.jar,
+ lib/required/hibernate3.jar,
+ lib/required/javassist-3.12.0.GA.jar,
+ lib/required/jta-1.1.jar,
+ lib/required/slf4j-api-1.6.1.jar,
+ lib/required/slf4j-log4j12-1.6.1.jar,
+ lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar,
+ lib/tools/freemarker.jar,
+ lib/tools/hibernate-tools-3.6.0.jar,
+ lib/tools/jtidy-r8-20060801.jar,
+ lib/bsh-core-2.0b4.jar,
+ lib/log4j-1.2.15.jar,
+ .
+Bundle-Vendor: JBoss by Red Hat
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/build.properties
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/build.properties
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/build.properties 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,23 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ lib/,\
+ lib/required/antlr-2.7.6.jar,\
+ lib/required/commons-collections-3.1.jar,\
+ lib/required/dom4j-1.6.1.jar,\
+ lib/required/hibernate3.jar,\
+ lib/required/javassist-3.12.0.GA.jar,\
+ lib/required/jta-1.1.jar,\
+ lib/required/slf4j-api-1.6.1.jar,\
+ lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar,\
+ lib/tools/freemarker.jar,\
+ lib/tools/hibernate-tools-3.6.0.jar,\
+ lib/tools/jtidy-r8-20060801.jar,\
+ lib/bsh-core-2.0b4.jar,\
+ lib/log4j-1.2.15.jar,\
+ lib/required/commons-logging-1.0.4.jar,\
+ lib/required/cglib-2.2.jar,\
+ lib/required/slf4j-log4j12-1.6.1.jar
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/bsh-core-2.0b4.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/bsh-core-2.0b4.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/jpa/hibernate-jpa-2.0-api-1.0.1.Final.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/log4j-1.2.15.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/log4j-1.2.15.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/antlr-2.7.6.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/antlr-2.7.6.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/cglib-2.2.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/cglib-2.2.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-collections-3.1.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-collections-3.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-logging-1.0.4.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/commons-logging-1.0.4.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/dom4j-1.6.1.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/dom4j-1.6.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/hibernate3.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/hibernate3.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/javassist-3.12.0.GA.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/javassist-3.12.0.GA.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/jta-1.1.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/jta-1.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-api-1.6.1.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-api-1.6.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-log4j12-1.6.1.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/required/slf4j-log4j12-1.6.1.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/freemarker.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/freemarker.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/hibernate-tools-3.6.0.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/hibernate-tools-3.6.0.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/jtidy-r8-20060801.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/lib/tools/jtidy-r8-20060801.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.properties
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.properties
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.properties 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1 @@
+hibernate.version=3.6
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.xml
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/plugin.xml 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.hibernate.eclipse.hibernateextension">
+ <hibernateextension
+ classname="org.jboss.tools.hibernate3_6.HibernateExtension3_6"
+ version="%hibernate.version">
+ </hibernateextension>
+ </extension>
+ <extension
+ point="org.hibernate.eclipse.console.consoleextension">
+ <consoleextension
+
classname="org.jboss.tools.hibernate3_6.console.ConsoleExtension3_6"
+ version="%hibernate.version">
+ </consoleextension>
+ </extension>
+
+</plugin>
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/pom.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/pom.xml
(rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/pom.xml 2012-01-18 08:59:34
UTC (rev 37933)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.tools.hibernatetools</groupId>
+ <artifactId>plugins</artifactId>
+ <version>3.4.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.jboss.tools.hibernatetools.plugins</groupId>
+ <artifactId>org.jboss.tools.hibernate3_6</artifactId>
+
+ <packaging>eclipse-plugin</packaging>
+</project>
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/ConfigurationFactory.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,447 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.dom4j.DocumentException;
+import org.dom4j.Node;
+import org.dom4j.io.DOMWriter;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.drivers.jdbc.IJDBCDriverDefinitionConstants;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.console.ConnectionProfileUtil;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.resolver.DialectFactory;
+import org.hibernate.util.ConfigHelper;
+import org.hibernate.util.XMLHelper;
+import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+
+public class ConfigurationFactory {
+
+ public static final String FAKE_TM_LOOKUP =
"org.hibernate.console.FakeTransactionManagerLookup"; //$NON-NLS-1$
+
+ private ConsoleConfigurationPreferences prefs;
+ private Map<String, FakeDelegatingDriver> fakeDrivers;
+
+ public ConfigurationFactory(ConsoleConfigurationPreferences prefs,
+ Map<String, FakeDelegatingDriver> fakeDrivers) {
+ this.prefs = prefs;
+ this.fakeDrivers = fakeDrivers;
+ }
+
+ public ConsoleConfigurationPreferences getPreferences() {
+ return prefs;
+ }
+
+ public Configuration createConfiguration(Configuration localCfg, boolean
includeMappings) {
+ Properties properties = prefs.getProperties();
+
+ if (properties != null) {
+ // in case the transaction manager is empty then we need to inject a faketm since
+ // hibernate will still try and instantiate it.
+ String str = properties.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
+ if (str != null && StringHelper.isEmpty(str)) {
+ properties.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, FAKE_TM_LOOKUP);
+ // properties.setProperty( "hibernate.transaction.factory_class",
"");
+ }
+ }
+ if (localCfg == null) {
+ localCfg = buildConfiguration(properties, includeMappings);
+ } else {
+ // Properties origProperties = cfg.getProperties();
+ // origProperties.putAll(properties);
+ // cfg.setProperties(origProperties);
+ // TODO: this is actually only for jdbc reveng...
+ // localCfg = configureStandardConfiguration( includeMappings, localCfg, properties
);
+ }
+
+ // here both setProperties and configxml have had their chance to tell which
databasedriver
+ // is needed.
+ registerFakeDriver(localCfg.getProperty(Environment.DRIVER));
+ // autoConfigureDialect(localCfg); Disabled for now since it causes very looong
timeouts for
+ // non-running databases + i havent been needed until now...
+
+ // TODO: jpa configuration ?
+ if (includeMappings) {
+ File[] mappingFiles = prefs.getMappingFiles();
+
+ for (int i = 0; i < mappingFiles.length; i++) {
+ File hbm = mappingFiles[i];
+ localCfg = localCfg.addFile(hbm);
+ }
+ }
+ // TODO: HBX-
+ localCfg.setProperty("hibernate.temp.use_jdbc_metadata_defaults",
"false"); //$NON-NLS-1$//$NON-NLS-2$
+ localCfg.setProperty(Environment.HBM2DDL_AUTO, "false"); //$NON-NLS-1$
+ // to fix: JBIDE-5839 & JBIDE-5997 - setup this property: false is default value
+ // to make hibernate tools diff hibernate versions compatible:
+ // if the property not set get NoSuchMethodError with FullTextIndexEventListener
+ if (localCfg.getProperty("hibernate.search.autoregister_listeners") == null)
{ //$NON-NLS-1$
+ localCfg.setProperty("hibernate.search.autoregister_listeners",
"false"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return localCfg;
+ }
+
+ @SuppressWarnings("unused")
+ private void autoConfigureDialect(Configuration localCfg) {
+ if (localCfg.getProperty(Environment.DIALECT) == null) {
+ String url = localCfg.getProperty(Environment.URL);
+ String user = localCfg.getProperty(Environment.USER);
+ String pass = localCfg.getProperty(Environment.PASS);
+ Connection connection = null;
+ try {
+ connection = DriverManager.getConnection(url, user, pass);
+ // SQL Dialect:
+ Dialect dialect = DialectFactory.buildDialect(localCfg.getProperties(), connection);
+ localCfg.setProperty(Environment.DIALECT, dialect.toString());
+ } catch (SQLException e) {
+ // can't determine dialect
+ }
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ // TODO: delegate to some extension point
+ private Configuration buildConfiguration(Properties properties, boolean includeMappings)
{
+ Configuration localCfg = null;
+ if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
+ try {
+ localCfg = buildAnnotationConfiguration();
+ localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_load_annotationconfiguration,
+ e);
+ }
+ } else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
+ try {
+ localCfg = buildJPAConfiguration(getPreferences().getPersistenceUnitName(),
+ properties, prefs.getEntityResolverName(), includeMappings);
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_load_jpa_configuration, e);
+ }
+ } else {
+ localCfg = new Configuration();
+ localCfg = configureStandardConfiguration(includeMappings, localCfg, properties);
+ }
+ return localCfg;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Configuration buildAnnotationConfiguration() throws ClassNotFoundException,
+ InstantiationException, IllegalAccessException {
+ Class<Configuration> clazz = ReflectHelper
+ .classForName("org.hibernate.cfg.AnnotationConfiguration"); //$NON-NLS-1$
+ Configuration newInstance = clazz.newInstance();
+ return newInstance;
+ }
+
+ private Configuration buildJPAConfiguration(String persistenceUnit, Properties
properties,
+ String entityResolver, boolean includeMappings) {
+ if (StringHelper.isEmpty(persistenceUnit)) {
+ persistenceUnit = null;
+ }
+ try {
+ Map<Object, Object> overrides = new HashMap<Object, Object>();
+ if (properties != null) {
+ overrides.putAll(properties);
+ }
+ if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
+ overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
//$NON-NLS-1$
+ }
+ if (StringHelper.isNotEmpty(prefs.getDialectName())) {
+ overrides.put(Environment.DIALECT, prefs.getDialectName());
+ }
+ if (!includeMappings) {
+ overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
+ }
+ if (StringHelper.isEmpty((String)
overrides.get("javax.persistence.validation.mode"))) {//$NON-NLS-1$
+ overrides.put("javax.persistence.validation.mode", "none");
//$NON-NLS-1$//$NON-NLS-2$
+ }
+ Class<?> clazz = ReflectHelper.classForName(
+ "org.hibernate.ejb.Ejb3Configuration", ConsoleConfiguration.class);
//$NON-NLS-1$
+ Object ejb3cfg = clazz.newInstance();
+ if (StringHelper.isNotEmpty(entityResolver)) {
+ Class<?> resolver = ReflectHelper.classForName(entityResolver,
this.getClass());
+ Object object = resolver.newInstance();
+ Method method = clazz.getMethod(
+ "setEntityResolver", new Class[] { EntityResolver.class });//$NON-NLS-1$
+ method.invoke(ejb3cfg, new Object[] { object });
+ }
+ Method method = clazz.getMethod("configure", new Class[] { String.class,
Map.class }); //$NON-NLS-1$
+ if (method.invoke(ejb3cfg, new Object[] { persistenceUnit, overrides }) == null) {
+ String out = NLS.bind(
+ ConsoleMessages.ConsoleConfiguration_persistence_unit_not_found,
+ persistenceUnit);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ method = clazz.getMethod("getHibernateConfiguration", new
Class[0]);//$NON-NLS-1$
+ Configuration invoke = (Configuration) method.invoke(ejb3cfg, (Object[]) null);
+ invoke = configureConnectionProfile(invoke);
+ return invoke;
+ } catch (HibernateConsoleRuntimeException he) {
+ throw he;
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_create_jpa_based_configuration,
+ e);
+ }
+ }
+
+ private Configuration configureStandardConfiguration(final boolean includeMappings,
+ Configuration localCfg, Properties properties) {
+ if (properties != null) {
+ localCfg = localCfg.setProperties(properties);
+ }
+ EntityResolver entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
+ if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) {
+ try {
+ entityResolver = (EntityResolver) ReflectHelper.classForName(
+ prefs.getEntityResolverName()).newInstance();
+ } catch (Exception c) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver
+ + prefs.getEntityResolverName(), c);
+ }
+ }
+ localCfg.setEntityResolver(entityResolver);
+ if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
+ try {
+ NamingStrategy ns = (NamingStrategy) ReflectHelper.classForName(
+ prefs.getNamingStrategy()).newInstance();
+ localCfg.setNamingStrategy(ns);
+ } catch (Exception c) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy
+ + prefs.getNamingStrategy(), c);
+ }
+ }
+ localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver);
+ localCfg = configureConnectionProfile(localCfg);
+ // replace dialect if it is set in preferences
+ if (StringHelper.isNotEmpty(prefs.getDialectName())) {
+ localCfg.setProperty(Environment.DIALECT, prefs.getDialectName());
+ }
+ if
(StringHelper.isEmpty(localCfg.getProperty("javax.persistence.validation.mode")))
{//$NON-NLS-1$
+ localCfg.setProperty("javax.persistence.validation.mode", "none");
//$NON-NLS-1$//$NON-NLS-2$
+ }
+ return localCfg;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Configuration loadConfigurationXML(Configuration localCfg, boolean
includeMappings,
+ EntityResolver entityResolver) {
+ File configXMLFile = prefs.getConfigXMLFile();
+ if (!includeMappings) {
+ org.dom4j.Document doc;
+ XMLHelper xmlHelper = new XMLHelper();
+ InputStream stream = null;
+ String resourceName = "<unknown>"; //$NON-NLS-1$
+ if (configXMLFile != null) {
+ resourceName = configXMLFile.toString();
+ try {
+ stream = new FileInputStream(configXMLFile);
+ } catch (FileNotFoundException e1) {
+ throw new HibernateConsoleRuntimeException(
+ ConsoleMessages.ConsoleConfiguration_could_not_access + configXMLFile,
+ e1);
+ }
+ } else {
+ resourceName = "/hibernate.cfg.xml"; //$NON-NLS-1$
+ if (checkHibernateResoureExistence(resourceName)) {
+ stream = ConfigHelper.getResourceAsStream(resourceName); // simulate
hibernate's
+ // default look up
+ } else {
+ return localCfg;
+ }
+ }
+ try {
+ List<Throwable> errors = new ArrayList<Throwable>();
+ doc = xmlHelper.createSAXReader(resourceName, errors, entityResolver).read(
+ new InputSource(stream));
+ if (errors.size() != 0) {
+ throw new MappingException(
+ ConsoleMessages.ConsoleConfiguration_invalid_configuration, errors
+ .get(0));
+ }
+ List<Node> list = doc.getRootElement()
+ .element("session-factory").elements("mapping"); //$NON-NLS-1$
//$NON-NLS-2$
+ for (Node element : list) {
+ element.getParent().remove(element);
+ }
+ DOMWriter dw = new DOMWriter();
+ Document document = dw.write(doc);
+ return localCfg.configure(document);
+
+ } catch (DocumentException e) {
+ throw new HibernateException(
+ ConsoleMessages.ConsoleConfiguration_could_not_parse_configuration
+ + resourceName, e);
+ } finally {
+ try {
+ if (stream != null)
+ stream.close();
+ } catch (IOException ioe) {
+ // log.warn( "could not close input stream for: " + resourceName, ioe );
+ }
+ }
+ } else {
+ if (configXMLFile != null) {
+ return localCfg.configure(configXMLFile);
+ } else {
+ Configuration resultCfg = localCfg;
+ if (checkHibernateResoureExistence("/hibernate.cfg.xml")) { //$NON-NLS-1$
+ resultCfg = localCfg.configure();
+ }
+ return resultCfg;
+ }
+ }
+ }
+
+ private boolean checkHibernateResoureExistence(String resource) {
+ InputStream is = null;
+ try {
+ is = ConfigHelper.getResourceAsStream(resource);
+ } catch (HibernateException e) {
+ // just ignore
+ } finally {
+ try {
+ if (is != null)
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return (is != null);
+ }
+
+ private Configuration configureConnectionProfile(Configuration localCfg) {
+ String connProfileName = prefs.getConnectionProfileName();
+ if (connProfileName == null) {
+ return localCfg;
+ }
+ IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
+ connProfileName);
+ if (profile != null) {
+ final Properties cpProperties = profile.getProperties(profile.getProviderId());
+ final Properties invokeProperties = localCfg.getProperties();
+ // set this property to null!
+ invokeProperties.remove(Environment.DATASOURCE);
+ localCfg.setProperties(invokeProperties);
+ // seems we should not setup dialect here
+ //String dialect = "org.hibernate.dialect.HSQLDialect";
+ //invoke.setProperty(Environment.DIALECT, dialect);
+ String driverClass = ConnectionProfileUtil.getDriverClass(connProfileName);
+ localCfg.setProperty(Environment.DRIVER, driverClass);
+ //String driverJarPath = driverInstance != null ?
+ // driverInstance.getJarList() : ""; //$NON-NLS-1$
+ String url = cpProperties.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID);
+ // url += "/";// +
+ // cpProperties.getProperty(IJDBCDriverDefinitionConstants.DATABASE_NAME_PROP_ID);
+ localCfg.setProperty(Environment.URL, url);
+ String user =
cpProperties.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID);
+ if (null != user && user.length() > 0) {
+ localCfg.setProperty(Environment.USER, user);
+ }
+ String pass =
cpProperties.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID);
+ if (null != pass && pass.length() > 0) {
+ localCfg.setProperty(Environment.PASS, pass);
+ }
+ } else {
+ String out = NLS.bind(
+ ConsoleMessages.ConsoleConfiguration_connection_profile_not_found,
+ connProfileName);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ return localCfg;
+ }
+
+ /**
+ * DriverManager checks what classloader a class is loaded from thus we register a
FakeDriver
+ * that we know is loaded "properly" which delegates all it class to the real
driver. By doing
+ * so we can convince DriverManager that we can use any dynamically loaded driver.
+ *
+ * @param driverClassName
+ */
+ @SuppressWarnings("unchecked")
+ private void registerFakeDriver(String driverClassName) {
+ if (driverClassName != null) {
+ try {
+ Class<Driver> driverClass = ReflectHelper.classForName(driverClassName);
+ if (!fakeDrivers.containsKey(driverClassName)) { // To avoid "double
registration"
+ FakeDelegatingDriver fakeDelegatingDriver = new FakeDelegatingDriver(
+ driverClass.newInstance());
+ DriverManager.registerDriver(fakeDelegatingDriver);
+ fakeDrivers.put(driverClassName, fakeDelegatingDriver);
+ }
+ } catch (ClassNotFoundException e) {
+ String out =
+ NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (InstantiationException e) {
+ String out =
+ NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (IllegalAccessException e) {
+ String out =
+ NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ } catch (SQLException e) {
+ String out =
+ NLS.bind(ConsoleMessages.ConsoleConfiguration_problems_while_loading_database_driverclass,
driverClassName);
+ throw new HibernateConsoleRuntimeException(out, e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeDelegatingDriver.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeDelegatingDriver.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeDelegatingDriver.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public class FakeDelegatingDriver implements Driver {
+ private Driver driver;
+
+ public FakeDelegatingDriver(Driver d) {
+ this.driver = d;
+ }
+ public boolean acceptsURL(String u) throws SQLException {
+ return this.driver.acceptsURL(u);
+ }
+ public Connection connect(String u, Properties p) throws SQLException {
+ return this.driver.connect(u, p);
+ }
+ public int getMajorVersion() {
+ return this.driver.getMajorVersion();
+ }
+ public int getMinorVersion() {
+ return this.driver.getMinorVersion();
+ }
+ public DriverPropertyInfo[] getPropertyInfo(String u, Properties p)
+ throws SQLException {
+ return this.driver.getPropertyInfo(u, p);
+ }
+ public boolean jdbcCompliant() {
+ return this.driver.jdbcCompliant();
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeTransactionManagerLookup.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeTransactionManagerLookup.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/FakeTransactionManagerLookup.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+
+import org.hibernate.HibernateException;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
+import org.hibernate.transaction.TransactionManagerLookup;
+
+public class FakeTransactionManagerLookup implements TransactionManagerLookup {
+
+ public TransactionManager getTransactionManager(Properties props)
+ throws HibernateException {
+ if ( FakeTransactionManager.INSTANCE == null ) {
+ FakeTransactionManager.INSTANCE = new FakeTransactionManager(props);
+ }
+ return FakeTransactionManager.INSTANCE;
+ }
+
+ public String getUserTransactionName() {
+ return null; //throw new UnsupportedOperationException();
+ }
+
+ public Object getTransactionIdentifier(Transaction transaction) {
+ return transaction;
+ }
+
+}
+
+class FakeTransactionManager implements TransactionManager {
+
+ public static FakeTransactionManager INSTANCE;
+
+ private FakeTransaction current;
+ ConnectionProvider connections;
+
+ public FakeTransactionManager(Properties props) {
+ connections = ConnectionProviderFactory.newConnectionProvider();
+ }
+
+ public void begin() throws NotSupportedException, SystemException {
+ current = new FakeTransaction(this);
+ current.begin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException,
+ IllegalStateException, SystemException {
+ if(current!=null) current.commit();
+ }
+
+
+ public int getStatus() throws SystemException {
+ if(current!=null) {
+ return current.getStatus();
+ } else {
+ return Status.STATUS_NO_TRANSACTION;
+ }
+ }
+
+ public Transaction getTransaction() throws SystemException {
+ return current;
+ }
+
+ public void resume(Transaction tx) throws InvalidTransactionException,
+ IllegalStateException, SystemException {
+ current = (FakeTransaction) tx;
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
+ SystemException {
+ if(current!=null) current.rollback();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException {
+ if(current!=null) current.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int t) throws SystemException {
+ }
+
+ public Transaction suspend() throws SystemException {
+ Transaction result = current;
+ current = null;
+ return result;
+ }
+
+ public FakeTransaction getCurrent() {
+ return current;
+ }
+
+ void endCurrent(FakeTransaction tx) {
+ if (current==tx) current=null;
+ }
+
+}
+
+class FakeTransaction implements Transaction {
+
+ int status;
+ private Connection connection;
+ List<Synchronization> synchronizations = new ArrayList<Synchronization>();
+ private FakeTransactionManager transactionManager;
+
+ FakeTransaction(FakeTransactionManager transactionManager) {
+ status = Status.STATUS_NO_TRANSACTION;
+ this.transactionManager = transactionManager;
+ }
+
+ public void begin() throws SystemException {
+ try {
+ connection = transactionManager.connections.getConnection();
+ }
+ catch (SQLException sqle) {
+
+ sqle.printStackTrace();
+ throw new SystemException(sqle.toString());
+ }
+ status = Status.STATUS_ACTIVE;
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException,
+ IllegalStateException, SystemException {
+
+ if (status == Status.STATUS_MARKED_ROLLBACK) {
+ rollback();
+ }
+ else {
+ status = Status.STATUS_PREPARING;
+
+ for (Synchronization s : synchronizations) {
+ s.beforeCompletion();
+ }
+
+ status = Status.STATUS_COMMITTING;
+
+ try {
+ connection.commit();
+ connection.close();
+ }
+ catch (SQLException sqle) {
+ status = Status.STATUS_UNKNOWN;
+ throw new SystemException();
+ }
+
+ status = Status.STATUS_COMMITTED;
+
+ for (Synchronization s : synchronizations) {
+ s.afterCompletion(status);
+ }
+
+ //status = Status.STATUS_NO_TRANSACTION;
+ transactionManager.endCurrent(this);
+ }
+
+ }
+
+ public boolean delistResource(XAResource arg0, int arg1)
+ throws IllegalStateException, SystemException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean enlistResource(XAResource arg0) throws RollbackException,
+ IllegalStateException, SystemException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public int getStatus() throws SystemException {
+ return status;
+ }
+
+ public void registerSynchronization(Synchronization sync)
+ throws RollbackException, IllegalStateException, SystemException {
+ synchronizations.add(sync);
+ }
+
+ public void rollback() throws IllegalStateException, SystemException {
+
+ status = Status.STATUS_ROLLING_BACK;
+
+// Synch.beforeCompletion() should *not* be called for rollbacks
+// for ( int i=0; i<synchronizations.size(); i++ ) {
+// Synchronization s = (Synchronization) synchronizations.get(i);
+// s.beforeCompletion();
+// }
+
+ status = Status.STATUS_ROLLEDBACK;
+
+ try {
+ connection.rollback();
+ connection.close();
+ }
+ catch (SQLException sqle) {
+ status = Status.STATUS_UNKNOWN;
+ throw new SystemException();
+ }
+
+ for (Synchronization s : synchronizations) {
+ s.afterCompletion(status);
+ }
+
+ //status = Status.STATUS_NO_TRANSACTION;
+ transactionManager.endCurrent(this);
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException {
+ status = Status.STATUS_MARKED_ROLLBACK;
+ }
+
+ void setConnection(Connection connection) {
+ this.connection = connection;
+ }
+
+ public Connection getConnection() {
+ return connection;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/Hibernate3_6Plugin.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/Hibernate3_6Plugin.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/Hibernate3_6Plugin.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Dmitry Geraskov
+ * The activator class controls the plug-in life cycle
+ */
+public class Hibernate3_6Plugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.hibernate3_6";
//$NON-NLS-1$
+
+ // The shared instance
+ private static Hibernate3_6Plugin plugin;
+
+ /**
+ * The constructor
+ */
+ public Hibernate3_6Plugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Hibernate3_6Plugin getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,326 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Settings;
+import org.hibernate.console.ConsoleConfigClassLoader;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.execution.DefaultExecutionContext;
+import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.console.ext.QueryResult;
+import org.hibernate.console.ext.QueryResultImpl;
+import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import org.hibernate.console.preferences.PreferencesClassPathUtils;
+
+/**
+ *
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateExtension3_6 implements HibernateExtension {
+
+ private ConsoleConfigClassLoader classLoader = null;
+
+ private ExecutionContext executionContext;
+
+ private ConsoleConfigurationPreferences prefs;
+
+ private Configuration configuration;
+
+ private SessionFactory sessionFactory;
+
+ private Map<String, FakeDelegatingDriver> fakeDrivers = new HashMap<String,
FakeDelegatingDriver>();
+
+ public HibernateExtension3_6() {
+ }
+
+ @Override
+ public String getHibernateVersion() {
+ return "3.6";
+ }
+
+ @Override
+ public QueryResult executeHQLQuery(String hql,
+ QueryInputModel queryParameters) {
+ Session session = null;
+ try {
+ try {
+ session = sessionFactory.openSession();
+ return QueryExecutor.executeHQLQuery(this, session, hql, queryParameters);
+ } catch (Throwable e){
+ //Incompatible library versions could throw subclasses of Error, like
AbstractMethodError
+ //may be there is a sense to say to user that the reason is probably a wrong CC
version
+ //(when catch a subclass of Error)
+ return new QueryResultImpl(e);
+ }
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public QueryResult executeCriteriaQuery(final String criteriaCode,
+ final QueryInputModel model) {
+ return (QueryResult) execute(new Command() {
+ public Object execute() {
+ Session session = null;
+ try {
+ try {
+ session = sessionFactory.openSession();
+ return QueryExecutor.executeCriteriaQuery(session, criteriaCode, model);
+ } catch (Throwable e){
+ //Incompatible library versions could throw subclasses of Error, like
AbstractMethodError
+ //may be there is a sense to say to user that the reason is probably a wrong CC
version
+ //(when catch a subclass of Error)
+ return new QueryResultImpl(e);
+ }
+ } finally {
+ if (session != null && session.isOpen()){
+ try {
+ session.close();
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+ }
+ }
+ });
+
+ }
+
+ /**
+ * @param ConsoleConfigurationPreferences the prefs to set
+ */
+ public void setConsoleConfigurationPreferences(ConsoleConfigurationPreferences prefs) {
+ this.prefs = prefs;
+ }
+
+ public void build() {
+ configuration = buildWith(null, true);
+ }
+
+ @Override
+ public void buildSessionFactory() {
+ execute(new Command() {
+ public Object execute() {
+ if (sessionFactory != null) {
+ throw new HibernateException("Factory was not closed before attempt to build a
new Factory");
+ }
+ sessionFactory = configuration.buildSessionFactory();
+ return null;
+ }
+ });
+ }
+
+ @Override
+ public boolean closeSessionFactory() {
+ boolean res = false;
+ if (sessionFactory != null) {
+ sessionFactory.close();
+ sessionFactory = null;
+ res = true;
+ }
+ return res;
+ }
+
+ public Configuration buildWith(final Configuration cfg, final boolean includeMappings)
{
+ reinitClassLoader();
+ //TODO handle user libraries here
+ executionContext = new DefaultExecutionContext(prefs.getName(), classLoader);
+ Configuration result = (Configuration)execute(new Command() {
+ public Object execute() {
+ ConfigurationFactory cf = new ConfigurationFactory(prefs, fakeDrivers);
+ return cf.createConfiguration(cfg, includeMappings);
+ }
+ });
+ return result;
+ }
+
+ /**
+ * Create class loader - so it uses the original urls list from preferences.
+ */
+ protected void reinitClassLoader() {
+ boolean recreateFlag = true;
+ final URL[] customClassPathURLs =
PreferencesClassPathUtils.getCustomClassPathURLs(prefs);
+ if (classLoader != null) {
+ // check -> do not recreate class loader in case if urls list is the same
+ final URL[] oldURLS = classLoader.getURLs();
+ if (customClassPathURLs.length == oldURLS.length) {
+ int i = 0;
+ for (; i < oldURLS.length; i++) {
+ if (!customClassPathURLs[i].sameFile(oldURLS[i])) {
+ break;
+ }
+ }
+ if (i == oldURLS.length) {
+ recreateFlag = false;
+ }
+ }
+ }
+ if (recreateFlag) {
+ reset();
+ classLoader = createClassLoader(customClassPathURLs);
+ }
+ }
+
+ protected ConsoleConfigClassLoader createClassLoader(final URL[] customClassPathURLs) {
+ ConsoleConfigClassLoader classLoader = AccessController.doPrivileged(new
PrivilegedAction<ConsoleConfigClassLoader>() {
+ public ConsoleConfigClassLoader run() {
+ return new ConsoleConfigClassLoader(customClassPathURLs,
Thread.currentThread().getContextClassLoader()) {
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ try {
+ return super.findClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ } catch (IllegalStateException e){
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
+ try {
+ return super.loadClass(name, resolve);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ try {
+ return super.loadClass(name);
+ } catch (ClassNotFoundException cnfe) {
+ throw cnfe;
+ }
+ }
+
+ public URL getResource(String name) {
+ return super.getResource(name);
+ }
+ };
+ }
+ });
+ return classLoader;
+ }
+
+ public String getName() {
+ return prefs.getName();
+ }
+
+ public Object execute(Command c) {
+ if (executionContext != null) {
+ return executionContext.execute(c);
+ }
+ final String msg =
NLS.bind(ConsoleMessages.ConsoleConfiguration_null_execution_context, getName());
+ throw new HibernateException(msg);
+ }
+
+ @Override
+ public boolean reset() {
+ boolean res = false;
+ // reseting state
+ if (configuration != null) {
+ configuration = null;
+ res = true;
+ }
+
+ boolean tmp = closeSessionFactory();
+ res = res || tmp;
+ if (executionContext != null) {
+ executionContext.execute(new Command() {
+ public Object execute() {
+ Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
+ while (it.hasNext()) {
+ try {
+ DriverManager.deregisterDriver(it.next());
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+ });
+ }
+ if (fakeDrivers.size() > 0) {
+ fakeDrivers.clear();
+ res = true;
+ }
+ tmp = cleanUpClassLoader();
+ res = res || tmp;
+ executionContext = null;
+ return res;
+ }
+
+ protected boolean cleanUpClassLoader() {
+ boolean res = false;
+ ClassLoader classLoaderTmp = classLoader;
+ while (classLoaderTmp != null) {
+ if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
+ ((ConsoleConfigClassLoader)classLoaderTmp).close();
+ res = true;
+ }
+ classLoaderTmp = classLoaderTmp.getParent();
+ }
+ if (classLoader != null) {
+ classLoader = null;
+ res = true;
+ }
+ return res;
+ }
+
+ @Override
+ public boolean hasConfiguration() {
+ return configuration != null;
+ }
+
+ /**
+ * @return
+ */
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public Settings getSettings(final Configuration cfg) {
+ return (Settings) execute(new Command() {
+ public Object execute() {
+ return cfg.buildSettings();
+ }
+ });
+ }
+
+ @Override
+ public boolean isSessionFactoryCreated() {
+ return sessionFactory != null;
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryExecutor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryExecutor.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryExecutor.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,230 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.console.ext.QueryResult;
+import org.hibernate.console.ext.QueryResultImpl;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.Type;
+import org.hibernate.util.ReflectHelper;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class QueryExecutor {
+
+ public static QueryResult executeHQLQuery(HibernateExtension hibernateExtension, Session
session, String hql,
+ final QueryInputModel queryParameters) {
+
+ final Query query = session.createQuery(hql);
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+
+ list = new ArrayList<Object>();
+ hibernateExtension.execute(new Command() {
+
+ @Override
+ public Object execute() {
+ setupParameters(query, queryParameters);
+ return null;
+ }
+ });
+
+ long startTime = System.currentTimeMillis();
+ QueryResultImpl result = new QueryResultImpl(list,
+ queryTime);
+ try {
+ Iterator<?> iter = query.list().iterator(); // need to be user-controllable to
toggle between iterate, scroll etc.
+ queryTime = System.currentTimeMillis() - startTime;
+ while (iter.hasNext() ) {
+ Object element = iter.next();
+ list.add(element);
+ }
+ result.setPathNames(getHQLPathNames(query));
+ } catch (HibernateException e){
+ result.addException(e);
+ }
+ return result;
+
+ }
+
+ public static QueryResult executeCriteriaQuery(Session session, String criteriaCode,
+ QueryInputModel model) {
+
+ try {
+ List<Object> list = Collections.emptyList();
+ long queryTime = 0;
+ if (criteriaCode.indexOf("System.exit") >= 0) { // TODO: externalize run
so we don't need this bogus check! //$NON-NLS-1$
+ return new QueryResultImpl(new IllegalArgumentException(
+ ConsoleMessages.JavaPage_not_allowed));
+ } else {
+ Interpreter ip = setupInterpreter(session);
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if (o instanceof Criteria) {
+ Criteria criteria = (Criteria) o;
+ if (model.getMaxResults() != null) {
+ criteria.setMaxResults(model.getMaxResults().intValue());
+ }
+
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ } else if (o instanceof List<?>) {
+ list = (List<Object>) o;
+ if (model.getMaxResults() != null) {
+ list = list.subList(0, Math.min(list.size(), model
+ .getMaxResults().intValue()));
+ }
+ } else {
+ list = new ArrayList<Object>();
+ list.add(o);
+ }
+ }
+ return new QueryResultImpl(list,
+ Collections.singletonList(ConsoleMessages.JavaPage_no_info), queryTime);
+ } catch (EvalError e) {
+ return new QueryResultImpl(e);
+ } catch (HibernateException e) {
+ return new QueryResultImpl(e);
+ }
+ }
+
+ private static List<String> getHQLPathNames(Query query) {
+ List<String> l = Collections.emptyList();
+
+ if(query==null) return l;
+ String[] returnAliases = null;
+ try {
+ returnAliases = query.getReturnAliases();
+ } catch(NullPointerException e) {
+ // ignore -
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ if(returnAliases==null) {
+ Type[] t;
+ try {
+ t = query.getReturnTypes();
+ } catch(NullPointerException npe) {
+ t = new Type[] { null };
+ // ignore -
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2188
+ }
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ Type type = t[i];
+ if(type==null) {
+ l.add("<multiple types>"); //$NON-NLS-1$
+ } else {
+ l.add(type.getName() );
+ }
+ }
+ } else {
+ String[] t = returnAliases;
+ l = new ArrayList<String>(t.length);
+
+ for (int i = 0; i < t.length; i++) {
+ l.add(t[i]);
+ }
+ }
+
+ return l;
+ }
+
+ private static void setupParameters(Query query2, QueryInputModel model) {
+ if(model.getMaxResults()!=null) {
+ query2.setMaxResults( model.getMaxResults().intValue() );
+ }
+ ConsoleQueryParameter[] qp = model.getQueryParameters();
+ for (int i = 0; i < qp.length; i++) {
+ ConsoleQueryParameter parameter = qp[i];
+
+ String typeName = parameter.getType().getClass().getName();
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), convertToType(typeName));
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values),
convertToType(typeName));
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ),
convertToType(typeName));
+ }
+ }
+ }
+ }
+
+ /**
+ * Method converts Hibernate3 to Hibernate3_6 classes
+ * @param typeClassName
+ * @return
+ */
+ private static Type convertToType(String typeClassName){
+ try {
+ return (Type) ReflectHelper.classForName(typeClassName).newInstance();
+ } catch (Exception e) {
+ throw new HibernateConsoleRuntimeException("Can't instantiate hibernate type
" + typeClassName, e);
+ }
+ }
+
+ private static Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+
+ private static Interpreter setupInterpreter(Session session) throws EvalError,
HibernateException {
+ Interpreter interpreter = new Interpreter();
+
+ interpreter.set("session", session); //$NON-NLS-1$
+ interpreter.setClassLoader( Thread.currentThread().getContextClassLoader() );
+ SessionImplementor si = (SessionImplementor)session;
+
+ Map<String, ?> map = si.getFactory().getAllClassMetadata();
+
+ Iterator<String> iterator = map.keySet().iterator();
+ //TODO: filter non classes.
+ String imports = ""; //$NON-NLS-1$
+ while (iterator.hasNext() ) {
+ String element = iterator.next();
+ imports += "import " + element + ";\n"; //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
+ imports += "import org.hibernate.criterion.*;\n"; //$NON-NLS-1$
+ imports += "import org.hibernate.*;\n"; //$NON-NLS-1$
+ // TODO: expose the parameters as values to be used in the code.
+ interpreter.eval(imports);
+
+ return interpreter;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CompletionProposal.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CompletionProposal.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CompletionProposal.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+
+/**
+ * Generic completion proposal to be used as is, or as base for other completion
proposals.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public class CompletionProposal implements ICompletionProposal,
ICompletionProposalExtension {
+
+ private String displayString;
+ private String replacementString;
+ private int replacementOffset;
+ private int documentOffset = -1;
+ private int replacementLength;
+ private int cursorPosition;
+ private Image image;
+ private IContextInformation contextInformation;
+ private int contextInformationPosition;
+ private char[] triggerCharacters;
+ private String additionalProposalInfo;
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param additionalInfo additional information about the completion proposal
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset offset of the text to be replaced
+ * @param documentOffset offset of the document
+ * @param replacementLength length of the text to be replaced
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal If set
+ * to <code>null</code>, the replacement string will be taken
+ * as display string.
+ */
+ public CompletionProposal( String additionalInfo, String replacementString, int
replacementOffset,
+ int documentOffset, int replacementLength, Image image, String
displayString,
+ IContextInformation contextInformation ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = documentOffset;
+ this.replacementLength = replacementLength;
+ this.image = image;
+ this.displayString = displayString != null ? displayString : replacementString;
+
+ this.cursorPosition = replacementString.length();
+
+ this.contextInformation = contextInformation;
+
+ this.triggerCharacters = null;
+ this.additionalProposalInfo = additionalInfo;
+ }
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset the offset of the text to be replaced
+ * @param replacementLength the length of the text to be replaced
+ * @param cursorPosition the position of the cursor following the insert
+ * relative to replacementOffset
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal
+ * @param contentInformation the context information associated with this proposal
+ * @param additionalProposalInfo the additional information associated with
+ * this proposal
+ */
+ public CompletionProposal( String replacementString, int replacementOffset, int
replacementLength,
+ int cursorPosition, Image image, String displayString, IContextInformation
contextInformation,
+ String additionalProposalInfo ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = replacementOffset;
+ this.replacementLength = replacementLength;
+ this.cursorPosition = cursorPosition;
+ this.image = image;
+ this.displayString = displayString;
+ this.contextInformation = contextInformation;
+ this.additionalProposalInfo = additionalProposalInfo;
+
+ }
+
+ public void setContextInformation( IContextInformation contextInformation ) {
+ this.contextInformation = contextInformation;
+ contextInformationPosition = (contextInformation != null ? cursorPosition : -1);
+ }
+
+ /**
+ * Sets the trigger characters.
+ *
+ * @param triggerCharacters The set of characters which can trigger the
+ * application of this completion proposal
+ */
+ public void setTriggerCharacters( char[] triggerCharacters ) {
+ this.triggerCharacters = triggerCharacters;
+ }
+
+ /**
+ * Sets the cursor position relative to the insertion offset. By default
+ * this is the length of the completion string (Cursor positioned after the
+ * completion)
+ *
+ * @param cursorPosition The cursorPosition to set
+ */
+ public void setCursorPosition( int cursorPosition ) {
+
+ if (cursorPosition >= 0) {
+ this.cursorPosition = cursorPosition;
+ this.contextInformationPosition = (contextInformation != null ?
cursorPosition : -1);
+ }
+ }
+
+ public void apply( IDocument document, char trigger, int offset ) {
+ try {
+ // patch replacement length
+
+ int delta = offset - (documentOffset + replacementLength);
+ if (delta > 0)
+ replacementLength += delta;
+
+ if (trigger == (char) 0) {
+ replace( document, documentOffset, replacementLength, replacementString
);
+ }
+ else {
+ StringBuffer buffer = new StringBuffer( replacementString );
+
+ if ((replacementLength < buffer.length() && buffer.charAt(
replacementLength ) != trigger)) {
+ buffer.insert( cursorPosition, trigger );
+ ++cursorPosition;
+ }
+
+ replace( document, documentOffset, replacementLength, buffer.toString()
);
+ }
+
+ int oldLen = document.getLength();
+ documentOffset += document.getLength() - oldLen;
+ }
+ catch (BadLocationException e) {
+ HibernateConsolePlugin.getDefault().log( e );
+ }
+ }
+
+ /**
+ * Replaces the document content at the specified offset and length with the
+ * specified string.
+ *
+ * @param document the document opened in the editor
+ * @param offset offset to the document content to be replaced
+ * @param length length of text to be replaced
+ * @param string replacement string
+ * @throws BadLocationException
+ */
+ private void replace( IDocument document, int offset, int length, String string )
throws BadLocationException {
+ if (document != null && string != null && offset >= 0
&& length >= 0) {
+ if (!document.get( offset, length ).equals( string ))
+ document.replace( offset, length, string );
+ }
+ }
+
+ public void apply( IDocument document ) {
+ apply( document, (char) 0, documentOffset + replacementLength );
+ }
+
+ public Point getSelection( IDocument document ) {
+ return new Point( documentOffset + cursorPosition, 0 );
+ }
+
+ public IContextInformation getContextInformation() {
+ return contextInformation;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public String getDisplayString() {
+ return displayString;
+ }
+
+ public String getAdditionalProposalInfo() {
+ return additionalProposalInfo;
+ }
+
+ public char[] getTriggerCharacters() {
+ return triggerCharacters;
+ }
+
+ public int getContextInformationPosition() {
+ return replacementOffset + contextInformationPosition;
+ }
+
+ public int getReplacementOffset() {
+ return replacementOffset;
+ }
+
+ public void setReplacementOffset( int replacementOffset ) {
+
+ if (replacementOffset >= 0) {
+ this.replacementOffset = replacementOffset;
+ }
+ }
+
+ public int getReplacementLength() {
+ return replacementLength;
+ }
+
+ public void setReplacementLength( int replacementLength ) {
+
+ if (replacementLength >= 0) {
+ this.replacementLength = replacementLength;
+ }
+ }
+
+ public String getReplacementString() {
+ return replacementString;
+ }
+
+ public void setReplacementString( String replacementString ) {
+ this.replacementString = replacementString;
+ }
+
+ public void setImage( Image image ) {
+ this.image = image;
+ }
+
+ public boolean isValidFor( IDocument document, int offset ) {
+ if (offset < replacementOffset)
+ return false;
+
+ int replacementLength = replacementString == null ? 0 :
replacementString.length();
+ if (offset >= replacementOffset + replacementLength)
+ return false;
+
+ try {
+ int length = offset - replacementOffset;
+ String start = document.get( replacementOffset, length );
+ return replacementString.substring( 0, length ).equalsIgnoreCase( start );
+ }
+ catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,303 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.OverrideRepository;
+import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
+import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.launch.CodeGenerationStrings;
+import org.hibernate.eclipse.launch.CodeGenerationUtils;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.ide.completion.HQLCodeAssist;
+import org.hibernate.tool.ide.completion.IHQLCodeAssist;
+import org.jboss.tools.hibernate3_6.HibernateExtension3_6;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConsoleExtension3_6 implements ConsoleExtension {
+
+ private HibernateExtension3_6 hibernateExtension;
+
+ public ConsoleExtension3_6(){}
+
+ public void setHibernateException(HibernateExtension hibernateExtension){
+ this.hibernateExtension = (HibernateExtension3_6) hibernateExtension;
+ }
+
+ @Override
+ public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ if (!hibernateExtension.hasConfiguration()){
+ try {
+ hibernateExtension.build();
+ hibernateExtension.execute( new ExecutionContext.Command() {
+ public Object execute() {
+ if(hibernateExtension.hasConfiguration()) {
+ hibernateExtension.getConfiguration().buildMappings();
+ }
+ return null;
+ }
+ });
+ } catch (HibernateException e){
+ //FIXME
+ //String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
+ //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
+ }
+ }
+ IHQLCodeAssist hqlEval = new HQLCodeAssist(hibernateExtension.getConfiguration());
+ query = query.replace('\t', ' ');
+ hqlEval.codeComplete(query, currentOffset, requestor);
+ return new CompletionProposalsResult(requestor.getCompletionProposals(),
requestor.getLastErrorMessage());
+ }
+
+ /* (non-Javadoc)
+ * @see
org.hibernate.eclipse.console.ext.ConsoleExtension#launchExporters(org.hibernate.eclipse.console.ext.ILaunchConfiguration,
java.lang.String, org.hibernate.eclipse.console.ext.ILaunch,
org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void launchExporters(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ Assert.isNotNull(configuration);
+ Assert.isNotNull(monitor);
+ ExporterAttributes attributes = new ExporterAttributes(configuration);
+ List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
+ for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
+ ExporterFactory exFactory = iter.next();
+ if (!exFactory.isEnabled(configuration)) {
+ iter.remove();
+ }
+ }
+
+ try {
+ Set<String> outputDirectories = new HashSet<String>();
+ ExporterFactory[] exporters = exporterFactories.toArray( new
ExporterFactory[exporterFactories.size()] );
+ ArtifactCollector collector = runExporters(attributes, exporters,
outputDirectories, monitor);
+
+ for (String path : outputDirectories) {
+ CodeGenerationUtils.refreshOutputDir(path);
+ }
+
+ //RefreshTab.refreshResources(configuration, monitor);
+
+ // code formatting needs to happen *after* refresh to make sure eclipse will format
the uptodate files!
+ if(collector!=null) {
+ //formatGeneratedCode( monitor, collector );
+ }
+
+
+ } catch(Exception e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ } catch(NoClassDefFoundError e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e),
666));
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final
IProgressMonitor monitor)
+ throws CoreException
+ {
+
+
monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for
+ attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ ConsoleConfiguration cc =
KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
+ if (attributes.isReverseEngineer()) {
+ monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
+ }
+ final Configuration cfg = buildConfiguration(attributes, (HibernateExtension3_6)
cc.getHibernateExtension(), ResourcesPlugin.getWorkspace().getRoot());
+
+ monitor.worked(1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ return (ArtifactCollector) hibernateExtension.execute(new Command() {
+
+ public Object execute() {
+ ArtifactCollector artifactCollector = new ArtifactCollector();
+
+ // Global properties
+ Properties props = new Properties();
+ props.put(CodeGenerationStrings.EJB3, "" +
attributes.isEJB3Enabled()); //$NON-NLS-1$
+ props.put(CodeGenerationStrings.JDK5, "" +
attributes.isJDK5Enabled()); //$NON-NLS-1$
+
+ for (int i = 0; i < exporterFactories.length; i++)
+ {
+
monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
+
+ Properties globalProperties = new Properties();
+ globalProperties.putAll(props);
+
+ Exporter exporter;
+ try {
+ //FIXME - the exporters are not the same here!
+ //may be need to create it using the data from exporter definition???
+ exporter = exporterFactories[i].createConfiguredExporter(cfg,
attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties,
outputDirectories, artifactCollector);
+ } catch (CoreException e) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up
+ exporterFactories[i].getExporterDefinition(), e);
+ }
+
+ try {
+ exporter.start();
+ } catch(HibernateException he) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running
+ exporterFactories[i].getExporterDefinition().getDescription(), he);
+ }
+ monitor.worked(1);
+ }
+ return artifactCollector;
+ }
+
+ });
+
+
+ }
+
+
+ private Configuration buildConfiguration(final ExporterAttributes attributes,
HibernateExtension3_6 cc, IWorkspaceRoot root) {
+ final boolean reveng = attributes.isReverseEngineer();
+ final String reverseEngineeringStrategy = attributes.getRevengStrategy();
+ final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
+ final IResource revengres = PathHelper.findMember( root,
attributes.getRevengSettings());
+
+ if(reveng) {
+ Configuration configuration = null;
+ if(cc.hasConfiguration()) {
+ configuration = cc.getConfiguration();
+ } else {
+ configuration = cc.buildWith( null, false );
+ }
+
+ final JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
+ Properties properties = configuration.getProperties();
+ cfg.setProperties( properties );
+ cc.buildWith(cfg,false);
+
+ cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
+
+ cc.execute(new Command() { // need to execute in the consoleconfiguration to let it
handle classpath stuff!
+
+ public Object execute() {
+ //todo: factor this setup of revengstrategy to core
+ ReverseEngineeringStrategy res = new DefaultReverseEngineeringStrategy();
+
+ OverrideRepository repository = null;
+
+ if(revengres!=null) {
+ File file = PathHelper.getLocation( revengres ).toFile();
+ repository = new OverrideRepository();
+ repository.addFile(file);
+ }
+
+ if (repository != null){
+ res = repository.getReverseEngineeringStrategy(res);
+ }
+
+ if(reverseEngineeringStrategy!=null &&
reverseEngineeringStrategy.trim().length()>0) {
+ res = loadreverseEngineeringStrategy(reverseEngineeringStrategy, res);
+ }
+
+ ReverseEngineeringSettings qqsettings = new ReverseEngineeringSettings(res)
+ .setDefaultPackageName(attributes.getPackageName())
+ .setDetectManyToMany( attributes.detectManyToMany() )
+ //.setDetectOneToOne( attributes.detectOneToOne() )
+ .setDetectOptimisticLock( attributes.detectOptimisticLock() );
+
+ res.setSettings(qqsettings);
+
+ cfg.setReverseEngineeringStrategy( res );
+
+ cfg.readFromJDBC();
+ cfg.buildMappings();
+ return null;
+ }
+ });
+
+ return cfg;
+ } else {
+ cc.build();
+ final Configuration configuration = cc.getConfiguration();
+
+ cc.execute(new Command() {
+ public Object execute() {
+
+ configuration.buildMappings();
+ return configuration;
+ }
+ });
+ return configuration;
+ }
+ }
+
+ // TODO: merge with revstrategy load in JDBCConfigurationTask
+ @SuppressWarnings("unchecked")
+ private ReverseEngineeringStrategy loadreverseEngineeringStrategy(final String
className, ReverseEngineeringStrategy delegate) {
+ try {
+ Class<ReverseEngineeringStrategy> clazz =
ReflectHelper.classForName(className);
+ Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new
Class[] { ReverseEngineeringStrategy.class });
+ return constructor.newInstance(new Object[] { delegate });
+ }
+ catch (NoSuchMethodException e) {
+ try {
+ Class<?> clazz = ReflectHelper.classForName(className);
+ ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
+ return rev;
+ }
+ catch (Exception eq) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_default_noarg_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, eq);
+ }
+ }
+ catch (Exception e) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_one_argument_delegate_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, e);
+ }
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EclipseHQLCompletionRequestor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EclipseHQLCompletionRequestor.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EclipseHQLCompletionRequestor.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Value;
+import org.hibernate.tool.ide.completion.HQLCompletionProposal;
+import org.hibernate.tool.ide.completion.IHQLCompletionRequestor;
+import org.hibernate.util.xpl.StringHelper;
+
+public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor {
+
+ private final List<ICompletionProposal> result = new
ArrayList<ICompletionProposal>();
+ private String lastErrorMessage;
+ private final int virtualOffset;
+
+ public EclipseHQLCompletionRequestor() {
+ virtualOffset = 0;
+ }
+
+ public EclipseHQLCompletionRequestor(int virtualOffset) {
+ this.virtualOffset = virtualOffset;
+ }
+
+ public List<ICompletionProposal> getCompletionProposals() {
+ return result;
+ }
+
+ public boolean accept(HQLCompletionProposal proposal) {
+ result.add(new CompletionProposal(proposal.getCompletion(), // replacementString
+ proposal.getReplaceStart()+virtualOffset, // replacementOffset
+ proposal.getReplaceEnd()-proposal.getReplaceStart(), // replacementLength
+ proposal.getCompletion().length(), // cursorPosition (relativeTo
replacementStart)
+ getImage(proposal),
+ getDisplayString(proposal),
+ null,
+ null));
+ return true;
+ }
+
+ private String getDisplayString(HQLCompletionProposal proposal) {
+ StringBuffer buf = new StringBuffer(proposal.getSimpleName());
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ if(proposal.getEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append(" - "); //$NON-NLS-1$
+ buf.append(StringHelper.qualifier( proposal.getEntityName() ));
+ } else if(proposal.getShortEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.ALIAS_REF:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ if(proposal.getEntityName().indexOf( "." )>=0) { //$NON-NLS-1$
+ buf.append( " - " + StringHelper.unqualify( proposal.getEntityName() ));
//$NON-NLS-1$
+ } else {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ break;
+ default:
+
+ }
+
+
+ return buf.toString();
+ }
+
+ private Image getImage(HQLCompletionProposal proposal) {
+ String key = null;
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ case HQLCompletionProposal.ALIAS_REF:
+ key = ImageConstants.MAPPEDCLASS;
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ Property property = proposal.getProperty();
+ if(property!=null) {
+ if(property.getPersistentClass()!=null
+ && property.getPersistentClass().getIdentifierProperty()==property) {
+ key = ImageConstants.IDPROPERTY;
+ } else {
+ key = getIconNameForValue(property.getValue());
+ }
+ } else {
+ key = ImageConstants.PROPERTY;
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ key = null;
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ key = ImageConstants.FUNCTION;
+ break;
+ default:
+ key = null;
+ }
+
+ return key==null?null:EclipseImages.getImage( key );
+ }
+
+ public void completionFailure(String errorMessage) {
+ lastErrorMessage = errorMessage;
+ }
+
+ public String getLastErrorMessage() {
+ return lastErrorMessage;
+ }
+
+ public void clear() {
+ result.clear();
+ lastErrorMessage = null;
+ }
+
+ static private String getIconNameForValue(Value value) {
+ String result;
+
+ result = (String) value.accept(new IconNameValueVisitor());
+
+ if(result==null) {
+ result = ImageConstants.UNKNOWNPROPERTY;
+ }
+ return result;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterAttributes.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterAttributes.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterAttributes.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,376 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+
+// This class was created to centralize launch configuration attribute loading/saving
+// (and also to clean up CodeGenerationLaunchDelegate considerably)
+public class ExporterAttributes
+{
+ private boolean reverseEngineer, useOwnTemplates, enableJDK5, enableEJB3,
preferBasicCompositeIds;
+ private boolean useExternalProcess;
+ private String consoleConfigurationName;
+ private String revengSettings;
+ private String revengStrategy;
+ private String packageName;
+ private String outputPath;
+ private String templatePath;
+ private List<ExporterFactory> exporterFactories;
+
+ private boolean autoManyToManyDetection;
+ private boolean autoOneToOneDetection;
+ private boolean autoVersioning;
+
+ public ExporterAttributes () { }
+
+ public ExporterAttributes (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ initialize(configuration);
+ }
+
+ public void initialize (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ try {
+ consoleConfigurationName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,"");
//$NON-NLS-1$
+ outputPath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,"");
//$NON-NLS-1$
+ reverseEngineer =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, false);
+ revengSettings =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
""); //$NON-NLS-1$
+ revengStrategy =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
""); //$NON-NLS-1$
+ useOwnTemplates =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,false);
+ useExternalProcess =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_EXTERNAL_PROCESS, false);
+ enableJDK5 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5,false);
+ enableEJB3 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,false);
+ packageName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,"");
//$NON-NLS-1$
+ templatePath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,"");
//$NON-NLS-1$
+ preferBasicCompositeIds =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
true);
+ autoManyToManyDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY, true);
+ autoOneToOneDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE, true);
+ autoVersioning = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING, true);
+
+
+ if (!useOwnTemplates) {
+ templatePath = null;
+ }
+
+ exporterFactories = readExporterFactories(configuration);
+ } catch (CoreException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ }
+ }
+
+ public static String getLaunchAttributePrefix(String exporterId) {
+ return HibernateLaunchConstants.ATTR_EXPORTERS + "." + exporterId;
//$NON-NLS-1$
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<ExporterFactory> readExporterFactories(ILaunchConfiguration
configuration) throws CoreException {
+
+ List<String> exporterNames =
configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null);
+
+ if(exporterNames!=null) {
+ Map<String, ExporterDefinition> exDefinitions =
ExtensionManager.findExporterDefinitionsAsMap();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (String exporterId : exporterNames) {
+ String extensionId =
configuration.getAttribute(getLaunchAttributePrefix(exporterId) +
".extension_id", (String)null); //$NON-NLS-1$
+
+ ExporterDefinition expDef = exDefinitions.get(extensionId);
+ if(expDef==null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in,
extensionId, configuration.getName());
+ throw new HibernateConsoleRuntimeException(out);
+ } else {
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, exporterId );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+ }
+ return factories;
+
+ } else {
+ // fall back to old way of reading if list of exporters does not exist.
+ ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (int i = 0; i < exDefinitions.length; i++) {
+ ExporterDefinition expDef = exDefinitions[i];
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, expDef.getId() );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+
+ return factories;
+ }
+ }
+
+ public static void saveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, Set<ExporterFactory>
enabledExporters, Set<String> deletedExporterIds) {
+
+
+ List<String> names = new ArrayList<String>();
+ for (ExporterFactory ef : exporterFactories) {
+ configuration.setAttribute(getLaunchAttributePrefix(ef.getId()) +
".extension_id", ef.getExporterDefinition().getId()); //$NON-NLS-1$
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = getLaunchAttributePrefix(ef.getId()) + ".properties";
//$NON-NLS-1$
+ names.add(ef.getId());
+ ef.setEnabled( configuration, enabled, false );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+
+ deletedExporterIds.removeAll(names);
+
+ for (String deleted : deletedExporterIds) {
+ configuration.setAttribute( getLaunchAttributePrefix( deleted ), (String)null);
+ configuration.setAttribute(getLaunchAttributePrefix(deleted ) +
".extension_id", (String)null); //$NON-NLS-1$
+ configuration.setAttribute(getLaunchAttributePrefix(deleted) +
".properties", (String)null); //$NON-NLS-1$
+ }
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, names);
+ }
+
+ public static void oldSaveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, List<ExporterFactory>
enabledExporters) {
+
+ for (ExporterFactory ef : exporterFactories) {
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = ef.getId() + ".properties"; //$NON-NLS-1$
+
+ ef.setEnabled( configuration, enabled, true );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+ }
+
+
+ private Path pathOrNull(String p) {
+ if(p==null || p.trim().length()==0) {
+ return null;
+ } else {
+ return new Path(p);
+ }
+ }
+
+ public String getOutputPath()
+ {
+ return outputPath;
+ }
+
+ public void setOutputPath(String outputPath)
+ {
+ this.outputPath = outputPath;
+ }
+
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ public String getRevengSettings()
+ {
+ return revengSettings;
+ }
+
+ public void setRevengSettings(String revengSettings)
+ {
+ this.revengSettings = revengSettings;
+ }
+
+ public String getRevengStrategy()
+ {
+ return revengStrategy;
+ }
+
+ public void setRevengStrategy(String revengStrategy)
+ {
+ this.revengStrategy = revengStrategy;
+ }
+
+ public String getTemplatePath()
+ {
+ return templatePath;
+ }
+
+ public void setTemplatePath(String templatePath)
+ {
+ this.templatePath = templatePath;
+ }
+
+ public String getConsoleConfigurationName()
+ {
+ return consoleConfigurationName;
+ }
+
+ public void setConsoleConfigurationName(String consoleConfigurationName)
+ {
+ this.consoleConfigurationName = consoleConfigurationName;
+ }
+
+ public boolean isEJB3Enabled()
+ {
+ return enableEJB3;
+ }
+
+ public void setEnableEJB3(boolean enableEJB3)
+ {
+ this.enableEJB3 = enableEJB3;
+ }
+
+ public boolean isJDK5Enabled()
+ {
+ return enableJDK5;
+ }
+
+ public void setEnableJDK5(boolean enableJDK5)
+ {
+ this.enableJDK5 = enableJDK5;
+ }
+
+ public boolean isPreferBasicCompositeIds()
+ {
+ return preferBasicCompositeIds;
+ }
+
+ public void setPreferBasicCompositeIds(boolean preferBasicCompositeIds)
+ {
+ this.preferBasicCompositeIds = preferBasicCompositeIds;
+ }
+
+ public boolean isReverseEngineer()
+ {
+ return reverseEngineer;
+ }
+
+ public void setReverseEngineer(boolean reverseEngineer)
+ {
+ this.reverseEngineer = reverseEngineer;
+ }
+
+ public boolean isUseOwnTemplates()
+ {
+ return useOwnTemplates;
+ }
+
+ public void setUseOwnTemplates(boolean useOwnTemplates)
+ {
+ this.useOwnTemplates = useOwnTemplates;
+ }
+
+ public boolean isUseExternalProcess()
+ {
+ return useExternalProcess;
+ }
+
+ public void setUseExternalProcess(boolean useExternalProcess)
+ {
+ this.useExternalProcess = useExternalProcess;
+ }
+
+ public List<ExporterFactory> getExporterFactories() {
+ return exporterFactories;
+ }
+
+ public boolean detectManyToMany() {
+ return autoManyToManyDetection;
+ }
+
+ public boolean detectOptimisticLock() {
+ return autoVersioning;
+ }
+
+ public boolean detectOneToOne() {
+ return autoOneToOneDetection;
+ }
+
+ /**
+ * Check exporter attributes and return message with description what is wrong with
attributes.
+ *
+ * @return message
+ */
+ public String checkExporterAttributes() {
+ String msg = null;
+ boolean notSelected = consoleConfigurationName == null ||
consoleConfigurationName.length() <= 0;
+ if (notSelected) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_console_cfg_must_be_specified;
+ }
+ if (msg == null) {
+ msg = PathHelper.checkDirectory(outputPath,
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, true);
+ }
+ if (msg == null) {
+ if (reverseEngineer && packageName.length() > 0) {
+ IStatus val= JavaConventions.validatePackageName(packageName);
+ if (val.getSeverity() == IStatus.ERROR || val.getSeverity() ==
IStatus.WARNING) {
+ msg = val.getMessage();
+ }
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && revengSettings.trim().length() > 0) {
+ msg = PathHelper.checkFile(revengSettings,
HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_3, true);
+ }
+ }
+ if (msg == null) {
+ if (useOwnTemplates) {
+ msg = PathHelper.checkDirectory(templatePath,
HibernateConsoleMessages.CodeGenerationSettingsTab_template_dir, true);
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && !preferBasicCompositeIds) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_script_can_not_be_generated_correctly_without;
+ }
+ }
+ return msg;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterDefinition.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterDefinition.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterDefinition.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.tool.hbm2x.Exporter;
+
+/**
+ * Represents what is specified in plugin.xml about possible exporters.
+ *
+ */
+public class ExporterDefinition {
+
+ private String classname;
+
+ private String description;
+
+ private String id;
+
+ private ImageDescriptor iconDescriptor;
+
+ private Map<String, ExporterProperty> properties;
+
+ private IConfigurationElement element;
+
+ public ExporterDefinition(IConfigurationElement element) {
+ init(element.getAttribute( "classname" ), //$NON-NLS-1$
+ element.getAttribute( "description" ), //$NON-NLS-1$
+ element.getAttribute( "id" ), //$NON-NLS-1$
+ createProperties( element ),
+ createIcon( element ));
+ this.element = element;
+ }
+
+ protected void init(String className, String description, String id, Map<String,
ExporterProperty> properties, ImageDescriptor icon) {
+ this.classname = className;
+ this.description = description;
+ this.id = id;
+ this.properties = properties;
+ this.iconDescriptor = icon;
+ }
+
+ static private ImageDescriptor createIcon(IConfigurationElement element) {
+ if ( element.getAttribute( "icon" ) != null ) { //$NON-NLS-1$
+ return AbstractUIPlugin.imageDescriptorFromPlugin(
+ element.getNamespace(), element.getAttribute( "icon" ) ); //$NON-NLS-1$
+ } else {
+ return null;
+ }
+ }
+
+ static private Map<String, ExporterProperty>
createProperties(IConfigurationElement element) {
+ Map<String, ExporterProperty> properties = new HashMap<String,
ExporterProperty>();
+
+ IConfigurationElement propertyElements[] = element
+ .getChildren( "property" ); //$NON-NLS-1$
+ for (int i = 0; i < propertyElements.length; i++) {
+ ExporterProperty property = new ExporterProperty(
+ propertyElements[i].getAttribute("name"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("description"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("value"), //$NON-NLS-1$
+ Boolean.valueOf(propertyElements[i].getAttribute("required")).booleanValue());
//$NON-NLS-1$
+ String type = propertyElements[i].getAttribute("type"); //$NON-NLS-1$
+ if (type != null){
+ property.setType(type);
+ }
+ properties.put(property.getName(),property);
+ }
+ return properties;
+ }
+
+
+ public Exporter createExporterInstance() {
+ Exporter exporter = null;
+
+ try {
+ exporter = (Exporter) ReflectHelper.classForName( classname ).newInstance();
+ }
+ catch (InstantiationException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+ catch (IllegalAccessException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname)); }
+ catch (ClassNotFoundException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+
+ return exporter;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public ImageDescriptor getIconDescriptor() {
+ return iconDescriptor;
+ }
+
+ public Map<String, ExporterProperty> getExporterProperties() {
+ return properties;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ // if we put this in some "namespace" we should have a way to either
+ // migrate an existing one...
+ enabled = configuration.getAttribute( id, false );
+ }
+ catch (CoreException e) {
+ // log and assume false
+ HibernateConsolePlugin.getDefault().log(e);
+ return false;
+ }
+
+ return enabled;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getExporterTag() {
+ return getId().substring(getId().lastIndexOf(".") + 1); //$NON-NLS-1$
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterFactory.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExporterFactory.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,381 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.model.impl.ExporterFactoryStrings;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.eclipse.launch.ExporterAttributes;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.GenericExporter;
+import org.hibernate.tool.hbm2x.Hbm2DDLExporter;
+import org.hibernate.tool.hbm2x.QueryExporter;
+
+/**
+ * ExporterFactory is used in UI to hold additional configuration for Exporter
definitions
+ * @author max
+ *
+ */
+public class ExporterFactory {
+
+ private ExporterDefinition definition;
+
+ final Map<String, String> inputProperties;
+
+ private boolean enabled = true;
+
+ private final String exporterId;
+
+ public ExporterFactory(ExporterDefinition definition, String exporterId) {
+ this.definition = definition;
+ this.exporterId = exporterId;
+ inputProperties = new HashMap<String, String>();
+ }
+
+ public Map<String, ExporterProperty> getDefaultExporterProperties() {
+ return definition.getExporterProperties();
+ }
+
+ public String setProperty(String key, String value) {
+ return inputProperties.put( key, value );
+ }
+
+ public void removeProperty(String propertyName) {
+ inputProperties.remove( propertyName );
+ }
+
+ public String getPropertyValue(String key) {
+ if(inputProperties.containsKey( key )) {
+ return inputProperties.get( key );
+ } else {
+ ExporterProperty ep = definition.getExporterProperties().get( key );
+ if(ep!=null) {
+ return ep.getDefaultValue();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public boolean isEnabled() {
+ return enabled ;
+ }
+
+ public void setEnabled(boolean b) {
+ enabled = b;
+ }
+
+ public ExporterDefinition getExporterDefinition() {
+ return definition;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ enabled = configuration.getAttribute( getId(), false );
+ } else {
+ enabled =
configuration.getAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()), false);
+ }
+ } catch(CoreException ce) {
+ // ignore; assume false
+ enabled=false;
+ }
+
+ setEnabled( enabled );
+ return isEnabled();
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled,
boolean oldSettings) {
+ setEnabled( enabled );
+ if(oldSettings) {
+ configuration.setAttribute( getId(), isEnabled() );
+ } else {
+ configuration.setAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()),
isEnabled());
+ }
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled)
{
+
+ boolean oldSettings = true;
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ oldSettings = true;
+ } else {
+ oldSettings = false;
+ }
+ } catch(CoreException ce) {
+ // ignore and assume settings are old
+ }
+
+ setEnabled(configuration, enabled, oldSettings);
+ }
+
+ public Map<String, String> getProperties() {
+ return inputProperties;
+ }
+
+ public String getId() {
+ return exporterId;
+ }
+
+ public String getExporterTag() {
+ return definition.getExporterTag();
+ }
+
+ public String getExporterDefinitionId() {
+ return definition.getId();
+ }
+
+ public void setProperties(Map<String, String> props) {
+ inputProperties.clear();
+ inputProperties.putAll( props );
+ }
+
+ public ExporterProperty getExporterProperty(String key) {
+ return definition.getExporterProperties().get( key );
+ }
+
+ public boolean hasLocalValueFor(String string) {
+ return inputProperties.containsKey( string );
+ }
+
+ /** Method that resolves an expression through eclipses built-in variable manager.
+ * @throws CoreException if expression could not be evaluated. */
+ public static String resolve(String expression) throws CoreException {
+ if (expression == null) {
+ return null;
+ }
+ IStringVariableManager variableManager =
VariablesPlugin.getDefault().getStringVariableManager();
+ return variableManager.performStringSubstitution(expression, false);
+ }
+
+ /**
+ * ExporterFactory update a collection of output directories,
+ * true if new output directory was added into the set of outputDirs.
+ *
+ * @param defOutDir
+ * @param globalProps
+ * @param outputDirs
+ * @return true if new output directory added
+ * @throws CoreException
+ */
+ public boolean collectOutputDirectories(String defOutDir, final Properties globalProps,
+ Set<String> outputDirs) throws CoreException {
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProps);
+ props.putAll(getProperties());
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+ String outputPath = defOutDir;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ boolean res = false;
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ res = outputDirs.add(loc);
+ }
+ return res;
+ }
+
+ /**
+ * Creates exporter with the specified settings; also resolves any relevant properties
via Eclipse VariablesPlugin.
+ * @param collector
+ * @throws CoreException in case of resolve variables issues.
+ */
+ public Exporter createConfiguredExporter(Configuration cfg, String
defaultOutputDirectory,
+ String customTemplatePath, Properties globalProperties, Set<String>
outputDirectories, ArtifactCollector collector) throws CoreException {
+
+ Exporter exporter = getExporterDefinition().createExporterInstance();
+
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProperties);
+ props.putAll(getProperties());
+
+ exporter.setProperties(props);
+ exporter.setArtifactCollector(collector);
+
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+
+ String outputPath = defaultOutputDirectory;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ if (outputPath != null && loc == null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_output_dir_in_does_not_exist,
+ resolvedOutputDir, getExporterDefinition().getDescription());
+ throw new HibernateConsoleRuntimeException(out);
+ }
+
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ outputDirectories.add(loc);
+ exporter.setOutputDirectory(new File(loc));
+ }
+
+ exporter.setConfiguration(cfg);
+
+ List<String> templatePathList = new ArrayList<String>();
+ if (extract.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ String resolveTemplatePath =
resolve(extract.getProperty(ExporterFactoryStrings.TEMPLATE_PATH));
+ StringTokenizer st = new StringTokenizer(resolveTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath == null) {
+ out +=
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolveTemplatePath, getExporterDefinition().getDescription()) +
'\n';
+ } else {
+ templatePathList.add(locationAsStringPath);
+ }
+ }
+ if (out.length() > 0 ){
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+
+ if (StringHelper.isNotEmpty(customTemplatePath)) {
+ String resolvedCustomTemplatePath = resolve(customTemplatePath);
+ StringTokenizer st = new StringTokenizer(resolvedCustomTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath != null) {
+ templatePathList.add(locationAsStringPath);
+ } else {
+ out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolvedCustomTemplatePath, getExporterDefinition().getDescription());
+ }
+ }
+ if (!("".equals(out))) { //$NON-NLS-1$
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+ exporter.setTemplatePath(templatePathList.toArray(new
String[templatePathList.size()]));
+ // special handling for GenericExporter (TODO: be delegated via plugin.xml)
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbmtemplate")) {
//$NON-NLS-1$
+ GenericExporter ge = (GenericExporter) exporter;
+ ge.setFilePattern(extract.getProperty(ExporterFactoryStrings.FILE_PATTERN));
+ ge.setTemplateName(extract.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
+ ge.setForEach(extract.getProperty(ExporterFactoryStrings.FOR_EACH));
+ }
+ // special handling for Hbm2DDLExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbm2ddl")) {
//$NON-NLS-1$
+ Hbm2DDLExporter ddlExporter = (Hbm2DDLExporter) exporter;
+ //avoid users to delete their databases with a single click
+ boolean exportToDatabse =
Boolean.parseBoolean(extract.getProperty(ExporterFactoryStrings.EXPORTTODATABASE));
+ ddlExporter.setExport(exportToDatabse);
+ if (!exportToDatabse && props.containsKey("outputFileName")){
+ //FIXME this is a workaround for
https://issues.jboss.org/browse/JBIDE-10558
+ //schema.ddl file is not generated
+ //if exportToDatabse=scriptToConsole=false
+ ddlExporter.getProperties().put("scriptToConsole", "true");
+ }
+ }
+ // special handling for QueryExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.query")) {
//$NON-NLS-1$
+ QueryExporter queryExporter = (QueryExporter) exporter;
+ List<String> queryStrings = new ArrayList<String>();
+ queryStrings.add(extract.getProperty(ExporterFactoryStrings.QUERY_STRING,
"")); //$NON-NLS-1$
+ queryExporter.setQueries(queryStrings);
+ queryExporter.setFilename(extract.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
+ }
+ return exporter;
+ }
+
+ /**
+ * Extract and update GUI specific exporter properties
+ *
+ * @param exporterId
+ * @param props - properties which values remain
+ * @param extract - separated updated properties
+ * @throws CoreException
+ */
+ public static void extractExporterProperties(
+ String exporterId, Properties props, Properties extract) throws CoreException {
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ extract.put(ExporterFactoryStrings.OUTPUTDIR,
resolve(props.getProperty(ExporterFactoryStrings.OUTPUTDIR)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ extract.put(ExporterFactoryStrings.TEMPLATE_PATH,
resolve(props.getProperty(ExporterFactoryStrings.TEMPLATE_PATH)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.TEMPLATE_PATH);
+ }
+ if (exporterId.equals("org.hibernate.tools.hbmtemplate")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.FILE_PATTERN)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FILE_PATTERN, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FILE_PATTERN, tmp);
+ props.remove(ExporterFactoryStrings.FILE_PATTERN);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_NAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.TEMPLATE_NAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.TEMPLATE_NAME, tmp);
+ props.remove(ExporterFactoryStrings.TEMPLATE_NAME);
+ }
+ if (props.containsKey(ExporterFactoryStrings.FOR_EACH)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FOR_EACH, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FOR_EACH, tmp);
+ props.remove(ExporterFactoryStrings.FOR_EACH);
+ }
+ }
+ // special handling for Hbm2DDLExporter
+ if (exporterId.equals("org.hibernate.tools.hbm2ddl")) { //$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.EXPORTTODATABASE,
props.getProperty(ExporterFactoryStrings.EXPORTTODATABASE, Boolean.toString(false)));
+ props.remove(ExporterFactoryStrings.EXPORTTODATABASE);
+ }
+ // special handling for QueryExporter
+ if (exporterId.equals("org.hibernate.tools.query")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.QUERY_STRING)) {
+ tmp = props.getProperty(ExporterFactoryStrings.QUERY_STRING, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.QUERY_STRING, tmp);
+ props.remove(ExporterFactoryStrings.QUERY_STRING);
+ }
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTFILENAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.OUTPUTFILENAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.OUTPUTFILENAME, tmp);
+ props.remove(ExporterFactoryStrings.OUTPUTFILENAME);
+ }
+ }
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExtensionManager.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExtensionManager.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ExtensionManager.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ *
+ * @author dgeraskov
+ *
+ */
+public class ExtensionManager
+{
+ public static final String EXPORTERS_EXTENSION_ID =
"org.hibernate.eclipse.console.exporters"; //$NON-NLS-1$
+
+ private static IExtension[] findExtensions (String extensionId)
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionId);
+ return extensionPoint.getExtensions();
+ }
+
+ public static ExporterDefinition[] findExporterDefinitions ()
+ {
+ List<ExporterDefinition> exporters = new
ArrayList<ExporterDefinition>();
+
+ IExtension[] extensions = findExtensions(EXPORTERS_EXTENSION_ID);
+ for (int i = 0; i < extensions.length; i++)
+ {
+ IConfigurationElement elements[] = extensions[i].getConfigurationElements();
+ for (int j = 0; j < elements.length; j++)
+ {
+ ExporterDefinition exporter = new ExporterDefinition(elements[j]);
+ exporters.add(exporter);
+ }
+ }
+
+ return exporters.toArray(new ExporterDefinition[exporters.size()]);
+ }
+
+ /**
+ * return map of ExporterDefinitions keyed by id
+ */
+ public static Map<String, ExporterDefinition> findExporterDefinitionsAsMap() {
+ Map<String, ExporterDefinition> result = new HashMap<String,
ExporterDefinition>();
+
+ ExporterDefinition[] findExporterDefinitions = findExporterDefinitions();
+ for (int i = 0; i < findExporterDefinitions.length; i++) {
+ ExporterDefinition exporterDefinition = findExporterDefinitions[i];
+ result.put(exporterDefinition.getId(), exporterDefinition);
+ }
+
+ return result;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/IconNameValueVisitor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/IconNameValueVisitor.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/IconNameValueVisitor.java 2012-01-18
08:59:34 UTC (rev 37933)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_6.console;
+
+import org.hibernate.console.ImageConstants;
+import org.hibernate.mapping.Any;
+import org.hibernate.mapping.Array;
+import org.hibernate.mapping.Bag;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.IdentifierBag;
+import org.hibernate.mapping.List;
+import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.Map;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.mapping.PrimitiveArray;
+import org.hibernate.mapping.Set;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.ValueVisitor;
+
+/**
+ *
+ * @author dgeraskov
+ *
+ */
+final class IconNameValueVisitor implements ValueVisitor {
+
+ public Object accept(OneToOne oto) {
+ return ImageConstants.ONETOONE;
+ }
+
+ public Object accept(ManyToOne mto) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(Component component) {
+ return ImageConstants.COMPONENT;
+ }
+
+ public Object accept(DependantValue value) {
+ return ImageConstants.UNKNOWNPROPERTY;
+ }
+
+ public Object accept(SimpleValue value) {
+ return ImageConstants.PROPERTY;
+ }
+
+ public Object accept(Any any) {
+ return ImageConstants.PROPERTY;
+ }
+
+ public Object accept(Set set) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(OneToMany many) {
+ return ImageConstants.ONETOMANY;
+ }
+
+ public Object accept(Map map) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(Array list) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(PrimitiveArray primitiveArray) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(List list) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(IdentifierBag bag) {
+ return ImageConstants.MANYTOONE;
+ }
+
+ public Object accept(Bag bag) {
+ return ImageConstants.MANYTOONE;
+ }
+
+}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/pom.xml
===================================================================
--- trunk/hibernatetools/plugins/pom.xml 2012-01-18 01:56:00 UTC (rev 37932)
+++ trunk/hibernatetools/plugins/pom.xml 2012-01-18 08:59:34 UTC (rev 37933)
@@ -25,6 +25,7 @@
<module>org.jboss.tools.hibernate.xml</module>
<module>org.jboss.tools.hibernate.xml.ui</module>
<module>org.jboss.tools.hibernate3_5</module>
+ <module>org.jboss.tools.hibernate3_6</module>
<module>org.jboss.tools.hibernate4_0</module>
</modules>
</project>