JBoss Tools SVN: r39899 - trunk/build/parent.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 14:47:43 -0400 (Wed, 28 Mar 2012)
New Revision: 39899
Modified:
trunk/build/parent/pom.xml
Log:
apply patch for JBIDE-11374 - new default for local.site is file:///${user.home}/.m2/jbosstools-target-platform_3.3.indigo.SR2/ unless -Phudson is activated
Modified: trunk/build/parent/pom.xml
===================================================================
--- trunk/build/parent/pom.xml 2012-03-28 16:59:28 UTC (rev 39898)
+++ trunk/build/parent/pom.xml 2012-03-28 18:47:43 UTC (rev 39899)
@@ -35,9 +35,10 @@
<!-- 1a. URL of latest JBT target platform site -->
<jbosstools-target-site>http://download.jboss.org/jbosstools/updates/target-platform_3.3.indigo.S...</jbosstools-target-site>
- <!-- 1b. or use -Plocal.site -Dlocal.site=file:///home/$user/trunk/build/target-platform/REPO/ -->
+ <!-- 1b. or use -Plocal.site -Dlocal.site=file:///${HOME}/trunk/build/target-platform/REPO/ -->
<!-- TODO: don't forget to update JBDS .updatesite jobs when this value changes! -->
- <local.site>file:///home/hudson/static_build_env/jbds/target-platform_3.3.indigo.SR2/e372M-wtp332M.target/</local.site>
+ <!-- TODO: see also 'hudson' profile below for other default value -->
+ <local.site>file:///${user.home}/.m2/jbosstools-target-platform_3.3.indigo.SR2/</local.site>
<!-- 2a. URL of latest JBT nightly staging composite site (all the components
in once place) -->
@@ -585,6 +586,9 @@
<name>BUILD_NUMBER</name>
</property>
</activation>
+ <properties>
+ <local.site>file:///home/hudson/static_build_env/jbds/target-platform_3.3.indigo.SR2/e372M-wtp332M.target/</local.site>
+ </properties>
<build>
<plugins>
<plugin>
12 years, 1 month
JBoss Tools SVN: r39898 - trunk/build.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 12:59:28 -0400 (Wed, 28 Mar 2012)
New Revision: 39898
Modified:
trunk/build/pom.xml
Log:
jmx build depends on common, tests, and usage
Modified: trunk/build/pom.xml
===================================================================
--- trunk/build/pom.xml 2012-03-28 16:59:06 UTC (rev 39897)
+++ trunk/build/pom.xml 2012-03-28 16:59:28 UTC (rev 39898)
@@ -67,6 +67,7 @@
<id>jmx-bootstrap</id>
<modules>
<module>../tests</module>
+ <module>../common</module>
<module>../jmx</module>
<module>../usage</module>
</modules>
12 years, 1 month
JBoss Tools SVN: r39897 - trunk/download.jboss.org/jbosstools/builds/cascade.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 12:59:06 -0400 (Wed, 28 Mar 2012)
New Revision: 39897
Modified:
trunk/download.jboss.org/jbosstools/builds/cascade/swimlanes.txt
Log:
jmx build depends on common, tests, and usage
Modified: trunk/download.jboss.org/jbosstools/builds/cascade/swimlanes.txt
===================================================================
--- trunk/download.jboss.org/jbosstools/builds/cascade/swimlanes.txt 2012-03-28 16:42:38 UTC (rev 39896)
+++ trunk/download.jboss.org/jbosstools/builds/cascade/swimlanes.txt 2012-03-28 16:59:06 UTC (rev 39897)
@@ -36,6 +36,7 @@
forge -> [NONE]
(all but common and tests) -> usage
+jmx -> tests, common, usage
examples -> portlet, jst, runtime
portlet -> seam, as, tests, usage
seam -> hibernate, jsf
12 years, 1 month
JBoss Tools SVN: r39896 - trunk/download.jboss.org/jbosstools/examples.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2012-03-28 12:42:38 -0400 (Wed, 28 Mar 2012)
New Revision: 39896
Modified:
trunk/download.jboss.org/jbosstools/examples/project-examples-shared-3.3....
Log:
JBIDE-11433 activate the arq-jbossas-remote profile by default when creating new projects from JBoss Central
Modified: trunk/download.jboss.org/jbosstools/examples/project-examples-shared-3.3....
===================================================================
--- trunk/download.jboss.org/jbosstools/examples/project-examples-shared-3.3.... 2012-03-28 15:17:45 UTC (rev 39895)
+++ trunk/download.jboss.org/jbosstools/examples/project-examples-shared-3.3.... 2012-03-28 16:42:38 UTC (rev 39896)
@@ -44,6 +44,7 @@
</fixes>
<importType>mavenArchetype</importType>
<importTypeDescription>The project example requires the m2e, m2eclipse-wtp and JBoss Maven Integration features.</importTypeDescription>
+ <defaultMavenProfiles>arq-jbossas-remote</defaultMavenProfiles>
<mavenArchetype>
<archetypeGroupId>org.jboss.spec.archetypes</archetypeGroupId>
<archetypeArtifactId>jboss-javaee6-webapp-archetype</archetypeArtifactId>
@@ -100,7 +101,8 @@
</fixes>
<importType>mavenArchetype</importType>
<importTypeDescription>The project example requires the m2e, m2eclipse-wtp and JBoss Maven Integration features.</importTypeDescription>
- <mavenArchetype>
+ <defaultMavenProfiles>arq-jbossas-remote</defaultMavenProfiles>
+ <mavenArchetype>
<archetypeGroupId>org.jboss.spec.archetypes</archetypeGroupId>
<archetypeArtifactId>jboss-javaee6-webapp-ear-archetype</archetypeArtifactId>
<archetypeVersion>7.0.2.CR2</archetypeVersion>
@@ -208,8 +210,8 @@
</fixes>
<importType>mavenArchetype</importType>
<importTypeDescription>The project example requires the m2e, m2eclipse-wtp and JBoss Maven Integration features.</importTypeDescription>
- <defaultMavenProfiles>jee6</defaultMavenProfiles>
- <mavenArchetype>
+ <defaultMavenProfiles>arq-jbossas-remote</defaultMavenProfiles>
+ <mavenArchetype>
<archetypeGroupId>org.richfaces.archetypes</archetypeGroupId>
<archetypeArtifactId>richfaces-archetype-kitchensink</archetypeArtifactId>
<archetypeVersion>4.2.0.Final-2</archetypeVersion>
@@ -327,7 +329,11 @@
</fixes>
<importType>mavenArchetype</importType>
<importTypeDescription>The project example requires the m2e, m2eclipse-wtp, JBoss Maven Integration and Google Plugin for Eclipse features.</importTypeDescription>
- <mavenArchetype>
+ <!-- Activating the profile causes a build error :
+ 'dependencies.dependency.version' for org.jboss.as:jboss-as-arquillian-container-remote:jar is missing.
+ <defaultMavenProfiles>arq-jbossas-remote</defaultMavenProfiles>
+ -->
+ <mavenArchetype>
<archetypeGroupId>org.jboss.errai.archetypes</archetypeGroupId>
<archetypeArtifactId>kitchensink-quickstart</archetypeArtifactId>
<archetypeVersion>2.0-Beta3-jbt</archetypeVersion>
12 years, 1 month
JBoss Tools SVN: r39895 - in trunk/forge: features/org.jboss.tools.forge.test.feature and 8 other directories.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 11:17:45 -0400 (Wed, 28 Mar 2012)
New Revision: 39895
Added:
trunk/forge/plugins/org.jboss.tools.forge.core/plugin.properties
trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/plugin.properties
trunk/forge/plugins/org.jboss.tools.forge.runtime/plugin.properties
trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.properties
Modified:
trunk/forge/features/org.jboss.tools.forge.feature/feature.properties
trunk/forge/features/org.jboss.tools.forge.feature/feature.xml
trunk/forge/features/org.jboss.tools.forge.test.feature/feature.properties
trunk/forge/features/org.jboss.tools.forge.test.feature/feature.xml
trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.forge.runtime/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF
Log:
externalize provider, bundlename, description, copyright, etc. into properties files; set plugins to be plugins (in manifest.mf)
Modified: trunk/forge/features/org.jboss.tools.forge.feature/feature.properties
===================================================================
--- trunk/forge/features/org.jboss.tools.forge.feature/feature.properties 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/features/org.jboss.tools.forge.feature/feature.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -1,3 +1,19 @@
+###############################################################################
+# Copyright (c) 2012 Red Hat, Inc. and others.
+# All rights reserved. This program and the accompanying materials
+# are 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
+#
+# Contributors:
+# JBoss by Red Hat - Initial implementation.
+##############################################################################
+# feature.properties
+# contains externalized strings for feature.xml
+# "%foo" in feature.xml corresponds to the key "foo" in this file
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# This file should be translated.
+
featureName=Forge Tools
featureProvider=JBoss by Red Hat
@@ -7,6 +23,15 @@
# "description" property - description of the feature
description=Plugins for using Seam Forge from within Eclipse.
+# "copyright" property - text of the "Feature Update Copyright"
+copyright=Copyright (c) 2010-2012 Red Hat, Inc. and others.\n\
+All rights reserved. This program and the accompanying materials\n\
+are made available under the terms of the Eclipse Public License v1.0\n\
+which accompanies this distribution, and is available at\n\
+http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\
+JBoss by Red Hat - Initial implementation.\n
+ ############### end of copyright property ####################################
+
# "licenseURL" property - URL of the "Feature License"
# do not translate value - just change to point to a locale-specific HTML page
licenseURL=license.html
Modified: trunk/forge/features/org.jboss.tools.forge.feature/feature.xml
===================================================================
--- trunk/forge/features/org.jboss.tools.forge.feature/feature.xml 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/features/org.jboss.tools.forge.feature/feature.xml 2012-03-28 15:17:45 UTC (rev 39895)
@@ -3,15 +3,14 @@
id="org.jboss.tools.forge.feature"
label="%featureName"
version="1.0.0.qualifier"
- provider-name="JBoss by Red Hat">
+ provider-name="%featureProvider">
- <description url="http://www.example.com/description">
+ <description>
%description
</description>
- <copyright url="http://www.example.com/copyright">
- JBoss, Home of Professional Open Source
-Copyright (c) 2006-2012 Red Hat, Inc., and individual contributors as indicated by the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors.
+ <copyright>
+ %copyright
</copyright>
<license url="%licenseURL">
Modified: trunk/forge/features/org.jboss.tools.forge.test.feature/feature.properties
===================================================================
--- trunk/forge/features/org.jboss.tools.forge.test.feature/feature.properties 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/features/org.jboss.tools.forge.test.feature/feature.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -12,6 +12,11 @@
# do not translate value - just change to point to a locale-specific HTML page
licenseURL=license.html
+copyright=JBoss, Home of Professional Open Source\n\
+Copyright (c) 2012 Red Hat, Inc., and individual contributors as indicated \
+by the @authors tag. See the copyright.txt in the distribution \
+for a full listing of individual contributors.
+
# START NON-TRANSLATABLE
# "license" property - text of the "Feature Update License"
# should be plain text version of license agreement pointed to be "licenseURL"
Modified: trunk/forge/features/org.jboss.tools.forge.test.feature/feature.xml
===================================================================
--- trunk/forge/features/org.jboss.tools.forge.test.feature/feature.xml 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/features/org.jboss.tools.forge.test.feature/feature.xml 2012-03-28 15:17:45 UTC (rev 39895)
@@ -6,8 +6,7 @@
</description>
<copyright>
- JBoss, Home of Professional Open Source
-Copyright (c) 2006-2012 Red Hat, Inc., and individual contributors as indicated by the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors.
+ %copyright
</copyright>
<license url="%licenseURL">
Modified: trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/META-INF/MANIFEST.MF 2012-03-28 15:17:45 UTC (rev 39895)
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Forge Core
+Bundle-Name: %BundleName
Bundle-SymbolicName: org.jboss.tools.forge.core;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
@@ -13,4 +13,5 @@
org.jboss.tools.forge.core.preferences,
org.jboss.tools.forge.core.process
Bundle-Activator: org.jboss.tools.forge.core.ForgeCorePlugin
-Bundle-Vendor: JBoss by Red Hat
+Bundle-Vendor: %BundleProvider
+Bundle-Localization: plugin
Added: trunk/forge/plugins/org.jboss.tools.forge.core/plugin.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.core/plugin.properties (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.core/plugin.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -0,0 +1,2 @@
+BundleProvider=JBoss by Red Hat
+BundleName=Forge Core
\ No newline at end of file
Modified: trunk/forge/plugins/org.jboss.tools.forge.runtime/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.runtime/META-INF/MANIFEST.MF 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/plugins/org.jboss.tools.forge.runtime/META-INF/MANIFEST.MF 2012-03-28 15:17:45 UTC (rev 39895)
@@ -1,10 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Forge Runtime Plugin
+Bundle-Name: %BundleName
Bundle-SymbolicName: org.jboss.tools.forge.runtime
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-Vendor: JBoss by Red Hat
+Bundle-Vendor: %BundleProvider
+Bundle-Localization: plugin
Eclipse-BundleShape: dir
Export-Package: javax.enterprise.event,
javax.inject,
Added: trunk/forge/plugins/org.jboss.tools.forge.runtime/plugin.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.runtime/plugin.properties (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.runtime/plugin.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -0,0 +1,2 @@
+BundleProvider=JBoss by Red Hat
+BundleName=Forge Runtime Plugin
\ No newline at end of file
Modified: trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/META-INF/MANIFEST.MF 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/META-INF/MANIFEST.MF 2012-03-28 15:17:45 UTC (rev 39895)
@@ -1,10 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Forge Runtime Extensions
+Bundle-Name: %BundleName
Bundle-SymbolicName: org.jboss.tools.forge.runtime.ext
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-BundleShape: dir
-Bundle-Vendor: JBoss by Red Hat
+Bundle-Vendor: %BundleProvider
+Bundle-Localization: plugin
Bundle-ClassPath: bin/
Require-Bundle: org.jboss.tools.forge.runtime;bundle-version="1.0.0"
Added: trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/plugin.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/plugin.properties (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.runtime.ext/plugin.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -0,0 +1,2 @@
+BundleProvider=JBoss by Red Hat
+BundleName=Forge Runtime Extensions
\ No newline at end of file
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF 2012-03-28 15:17:22 UTC (rev 39894)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF 2012-03-28 15:17:45 UTC (rev 39895)
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Forge Tools
+Bundle-Name: %BundleName
Bundle-SymbolicName: org.jboss.tools.forge.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.ui,
@@ -28,4 +28,5 @@
Bundle-Activator: org.jboss.tools.forge.ui.ForgeUIPlugin
Bundle-ClassPath: .
Export-Package: org.jboss.tools.forge.ui.console
-Bundle-Vendor: JBoss by Red Hat
+Bundle-Vendor: %BundleProvider
+Bundle-Localization: plugin
Added: trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.properties (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.properties 2012-03-28 15:17:45 UTC (rev 39895)
@@ -0,0 +1,2 @@
+BundleProvider=JBoss by Red Hat
+BundleName=Forge Tools
\ No newline at end of file
12 years, 1 month
JBoss Tools SVN: r39894 - in trunk/forge/plugins/org.jboss.tools.forge.runtime: src and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 11:17:22 -0400 (Wed, 28 Mar 2012)
New Revision: 39894
Added:
trunk/forge/plugins/org.jboss.tools.forge.runtime/src/.gitkeep
Modified:
trunk/forge/plugins/org.jboss.tools.forge.runtime/build.properties
Log:
add missing src/ folder and source.. directive to build.properties
Modified: trunk/forge/plugins/org.jboss.tools.forge.runtime/build.properties
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.runtime/build.properties 2012-03-28 15:10:20 UTC (rev 39893)
+++ trunk/forge/plugins/org.jboss.tools.forge.runtime/build.properties 2012-03-28 15:17:22 UTC (rev 39894)
@@ -1,3 +1,4 @@
+source.. = src/
bin.includes = META-INF/,\
modules/,\
jboss-modules.jar,\
Added: trunk/forge/plugins/org.jboss.tools.forge.runtime/src/.gitkeep
===================================================================
12 years, 1 month
JBoss Tools SVN: r39893 - in trunk: tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: ljelinko
Date: 2012-03-28 11:10:20 -0400 (Wed, 28 Mar 2012)
New Revision: 39893
Modified:
trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/example/AbstractPortletExampleGatein.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/ExampleTest.java
Log:
Added possibility to configure if test should be skiped in case an example is not found
Modified: trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/example/AbstractPortletExampleGatein.java
===================================================================
--- trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/example/AbstractPortletExampleGatein.java 2012-03-28 15:06:44 UTC (rev 39892)
+++ trunk/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/example/AbstractPortletExampleGatein.java 2012-03-28 15:10:20 UTC (rev 39893)
@@ -19,4 +19,9 @@
public String getExampleCategory() {
return "Portlet for GateIn 3.1/EPP 5.x";
}
+
+ @Override
+ protected boolean failOnMissingExample() {
+ return true;
+ }
}
Modified: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/ExampleTest.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/ExampleTest.java 2012-03-28 15:06:44 UTC (rev 39892)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/ExampleTest.java 2012-03-28 15:10:20 UTC (rev 39893)
@@ -64,8 +64,20 @@
importExample(wiz);
postImport();
executeExample();
+ } else if (failOnMissingExample()){
+ throw new AssertionError("The example " + getExampleName() + " was not found");
}
}
+
+ /**
+ * The default behavior is to finish the thest gracefully if the example does not exist.
+ * When this behavior is not desirable, subclasses can change the behavior by overriding this
+ * method.
+ */
+ protected boolean failOnMissingExample(){
+ return false;
+ }
+
private SWTBot existsExample() {
SWTBot wiz = open.newObject(JBossToolsProjectExamples.LABEL);
// wait for progress shell (downloading & parsing example xml)
12 years, 1 month
JBoss Tools SVN: r39892 - in trunk/hibernatetools/plugins: org.hibernate.eclipse/src/org/hibernate/console/ext and 18 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2012-03-28 11:06:44 -0400 (Wed, 28 Mar 2012)
New Revision: 39892
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HQLQueryPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/JavaPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CollectionPropertySource.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EntityPropertySource.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HQLQueryPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/JavaPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CollectionPropertySource.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EntityPropertySource.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HQLQueryPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/JavaPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CollectionPropertySource.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EntityPropertySource.java
Removed:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/CollectionPropertySource.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/EntityPropertySource.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionDefinition.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/HibernatePropertySourceProvider.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/QueryPagePropertySource.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/.classpath
trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/lib/tools/hibernate-tools.jar
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryHelper.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF
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/QueryHelper.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.hibernate4_0/.classpath
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryHelper.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
Log:
https://issues.jboss.org/browse/JBIDE-11343
https://issues.jboss.org/browse/JBIDE-11412
Reworked property source provider for Hibernate entity
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/AbstractQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -26,8 +26,8 @@
import java.util.ArrayList;
import java.util.List;
-import org.hibernate.HibernateException;
import org.hibernate.Session;
+import org.hibernate.console.ext.HibernateExtension;
/**
* @author MAX
@@ -38,11 +38,11 @@
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private int id;
private Session session;
- private final ConsoleConfiguration cfg;
+ private final HibernateExtension extension;
protected List<Object> list;
protected long queryTime = -1; //shows how long query runs
protected boolean sticky = true;
- private List<Throwable> exceptions = new ArrayList<Throwable>();
+ protected List<Throwable> exceptions = new ArrayList<Throwable>();
protected String tabName;
protected QueryInputModel model;
@@ -61,8 +61,8 @@
}
}
- public AbstractQueryPage(ConsoleConfiguration cfg, QueryInputModel model) {
- this.cfg = cfg;
+ public AbstractQueryPage(HibernateExtension extension, QueryInputModel model) {
+ this.extension = extension;
this.model = model;
}
/**
@@ -72,17 +72,6 @@
return exceptions;
}
- public void release() {
- if (getSession().isOpen() ) {
- try {
- getSession().close();
- }
- catch (HibernateException e) {
- exceptions.add(e);
- }
- }
- }
-
/**
* @return
*/
@@ -138,9 +127,10 @@
release();
pcs.firePropertyChange("exceptions", null, exceptions); //$NON-NLS-1$
}
-
- public ConsoleConfiguration getConsoleConfiguration() {
- return cfg;
+
+ @Override
+ public HibernateExtension getHibernateExtension() {
+ return extension;
}
public long getQueryTime(){
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -296,21 +296,17 @@
}
public QueryPage executeHQLQuery(final String hql, final QueryInputModel queryParameters) {
- QueryPage qp = new org.hibernate.console.ext.HQLQueryPage(ConsoleConfiguration.this,hql,queryParameters);
+ QueryPage qp = getHibernateExtension().executeHQLQuery(hql, queryParameters);
qp.setId(++execcount);
fireQueryPageCreated(qp);
return qp;
}
public QueryPage executeBSHQuery(final String queryString, final QueryInputModel model) {
- return (QueryPage)execute(new Command() {
- public Object execute() {
- QueryPage qp = new org.hibernate.console.ext.JavaPage(ConsoleConfiguration.this,queryString,model);
- qp.setId(++execcount);
- fireQueryPageCreated(qp);
- return qp;
- }
- });
+ QueryPage qp = getHibernateExtension().executeCriteriaQuery(queryString, model);
+ qp.setId(++execcount);
+ fireQueryPageCreated(qp);
+ return qp;
}
@SuppressWarnings("unchecked")
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,177 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.hibernate.console;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.type.Type;
-
-
-public class HQLQueryPage extends AbstractQueryPage {
-
- private Query query;
- private String queryString;
-
- public List<Object> getList() {
- if (query==null) return Collections.emptyList();
- if (list == null) {
- try {
-
- //list = query.list();
- list = new ArrayList<Object>();
- setupParameters(query, model);
- long startTime = System.currentTimeMillis();
- 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);
- }
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
- }
- catch (HibernateException e) {
- list = Collections.emptyList();
- addException(e);
- } catch (IllegalArgumentException e) {
- list = Collections.emptyList();
- addException(e);
- }
- }
- return list;
- }
-
-
- private 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];
-
- try {
- int pos = Integer.parseInt(parameter.getName());
- //FIXME no method to set positioned list value
- query2.setParameter(pos, calcValue( parameter ), parameter.getType());
- } catch(NumberFormatException nfe) {
- Object value = parameter.getValue();
- if (value != null && value.getClass().isArray()){
- Object[] values = (Object[])value;
- query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
- } else {
- query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
- }
- }
- }
- }
-
- private Object calcValue(ConsoleQueryParameter parameter) {
- return parameter.getValueForQuery();
- }
-
- /**
- * @param session
- * @param string
- * @param queryParameters
- */
- public HQLQueryPage(ConsoleConfiguration cfg, String string, QueryInputModel model) {
- super(cfg, model);
- queryString = string;
- setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
- }
-
- public void setSession(Session s) {
- super.setSession(s);
- try {
- query = this.getSession().createQuery(getQueryString());
- } catch (HibernateException e) {
- addException(e);
- } catch (Exception e) {
- addException( e );
- }
- }
-
- /**
- * @return
- */
- public String getQueryString() {
- return queryString; // cannot use query since it might be null because of an error!
- }
-
- public void setQueryString(String queryString) {
- this.queryString = queryString;
- list = null;
- }
-
- public List<String> getPathNames() {
- List<String> l = Collections.emptyList();
-
- try {
- 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]);
- }
- }
- } catch (HibernateException he) {
- addException(he);
- }
-
- return l;
- }
-}
\ No newline at end of file
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,161 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.hibernate.console;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.engine.SessionImplementor;
-
-import bsh.EvalError;
-import bsh.Interpreter;
-
-/**
- * @author MAX
- *
- *
- */
-public class JavaPage extends AbstractQueryPage {
-
- private String criteriaCode;
-
- Criteria criteria = null;
-
- private Interpreter ip;
-
- /**
- * @param model
- * @param session2
- */
- public JavaPage(ConsoleConfiguration cfg, String criteriaCode, QueryInputModel model) {
- super(cfg, model);
- this.criteriaCode = criteriaCode;
- setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
- }
-
- @SuppressWarnings("unchecked")
- public void setSession(Session s) {
- super.setSession(s);
- try {
- if(criteriaCode.indexOf( "System.exit" )>=0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
- list = Collections.emptyList();
- addException( new IllegalArgumentException(ConsoleMessages.JavaPage_not_allowed) );
- return;
- }
- ip = setupInterpreter(getSession() );
- Object o = ip.eval(criteriaCode);
- // ugly! TODO: make un-ugly!
- if(o instanceof Criteria) {
- criteria = (Criteria) o;
- if(model.getMaxResults()!=null) {
- criteria.setMaxResults( model.getMaxResults().intValue() );
- }
- } 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);
- }
- }
- catch (EvalError e) {
- addException(e);
- }
- catch (HibernateException e) {
- addException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- private 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;
- }
-
- @SuppressWarnings("unchecked")
- public List<Object> getList() {
- if(list!=null) return list;
- try {
- if(criteria!=null) {
- long startTime = System.currentTimeMillis();
- list = criteria.list();
- queryTime = System.currentTimeMillis() - startTime;
- }
- else {
- return Collections.emptyList();
- }
- }
- catch (HibernateException e) {
- list = Collections.emptyList();
- addException(e);
- }
- return list;
- }
-
- public List<String> getPathNames() {
- List<String> l = new ArrayList<String>();
- l.add(ConsoleMessages.JavaPage_no_info);
- return l;
- }
-
- public String getQueryString() {
- return criteriaCode;
- }
- public void setQueryString(String queryString) {
- this.criteriaCode = queryString;
- list = null;
- ip = null;
- }
-
- public void release() {
-
- super.release();
- }
-}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -25,6 +25,7 @@
import java.util.List;
import org.hibernate.Session;
+import org.hibernate.console.ext.HibernateExtension;
/**
* @author MAX
@@ -74,7 +75,7 @@
public Session getSession();
public void setSession(Session session);
- public ConsoleConfiguration getConsoleConfiguration();
+ public HibernateExtension getHibernateExtension();
public void addPropertyChangeListener(PropertyChangeListener listener);
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,99 +0,0 @@
-package org.hibernate.console.ext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.console.AbstractQueryPage;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.QueryInputModel;
-
-/**
- *
- * @author Dmitry Geraskov
- *
- */
-public class HQLQueryPage extends AbstractQueryPage {
-
- private String queryString;
- private QueryResult queryResult;
-
- /**
- * @param session
- * @param string
- * @param queryParameters
- */
- public HQLQueryPage(ConsoleConfiguration cfg, String string, QueryInputModel model) {
- super(cfg, model);
- queryString = string;
- setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
- }
-
- public List<Object> getList() {
- if (queryString==null) return Collections.emptyList();
- if (list == null) {
- updateQueryResults();
- }
- return list;
- }
-
- private void updateQueryResults(){
- try {
- list = new ArrayList<Object>();
- queryResult = getConsoleConfiguration().getHibernateExtension()
- .executeHQLQuery(queryString, model);
- if (!queryResult.hasExceptions()){
- Iterator<?> iter = queryResult.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = queryResult.getQueryTime();
- while (iter.hasNext() ) {
- Object element = iter.next();
- list.add(element);
- }
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
- } else {
- for (Throwable e : queryResult.getExceptions()) {
- addException(e);
- }
- }
- } catch (HibernateException e) {
- addException(e);
- } catch (IllegalArgumentException e) {
- addException(e);
- }
- }
-
- public List<String> getPathNames() {
- try {
- if (queryResult == null){
- updateQueryResults();
- }
- } catch (HibernateException e) {
- addException(e);
- }
-
- return queryResult == null ? Collections.<String>emptyList() : queryResult.getPathNames();
- }
-
- public void setSession(Session s) {
- //do nothing - remove this method
- }
-
- @Override
- public void release() {
- //session is not set, nothing to release
- }
-
- public String getQueryString() {
- return queryString;
- }
-
- public void setQueryString(String queryString) {
- this.queryString = queryString;
- list = null;
- queryResult = null;
- }
-
-}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -11,6 +11,7 @@
package org.hibernate.console.ext;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.QueryPage;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
@@ -37,9 +38,9 @@
//TODO do we really need this?
public String getHibernateVersion();
- public QueryResult executeHQLQuery(final String hql, final QueryInputModel queryParameters);
+ public QueryPage executeHQLQuery(String hql, QueryInputModel queryParameters);
- public QueryResult executeCriteriaQuery(final String criteria, final QueryInputModel queryParameters);
+ public QueryPage executeCriteriaQuery(String criteria, QueryInputModel queryParameters);
//FIXME remove this method
public boolean hasConfiguration();
@@ -55,4 +56,8 @@
public boolean isSessionFactoryCreated();
+ public boolean hasExecutionContext();
+
+ public String getConsoleConfigurationName();
+
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -40,7 +40,6 @@
this.hibernateVersion = hibernateVersion;
}
- //TODO do we need to create new instance every time?
public HibernateExtension createHibernateExtensionInstance() {
HibernateExtension hiberanteExtension = null;
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.hibernate.console.ext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.console.AbstractQueryPage;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.QueryInputModel;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public class JavaPage extends AbstractQueryPage {
-
- private String criteriaCode;
- private QueryResult queryResult;
-
- /**
- * @param model
- * @param session2
- */
- public JavaPage(ConsoleConfiguration cfg, String criteriaCode, QueryInputModel model) {
- super(cfg, model);
- this.criteriaCode = criteriaCode;
- setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
- }
-
- public List<Object> getList() {
- if (criteriaCode==null) return Collections.emptyList();
- if (list == null) {
- updateQueryResults();
- }
- return list;
- }
-
- private void updateQueryResults(){
- try {
- list = new ArrayList<Object>();
- queryResult = getConsoleConfiguration().getHibernateExtension()
- .executeCriteriaQuery(criteriaCode, model);
- if (!queryResult.hasExceptions()){
- Iterator<?> iter = queryResult.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
- queryTime = queryResult.getQueryTime();
- while (iter.hasNext() ) {
- Object element = iter.next();
- list.add(element);
- }
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
- } else {
- for (Throwable e : queryResult.getExceptions()) {
- addException(e);
- }
- }
- } catch (HibernateException e) {
- addException(e);
- } catch (IllegalArgumentException e) {
- addException(e);
- }
- }
-
- public void release() {
- //session is not set, nothing to release
- }
-
- public List<String> getPathNames() {
- try {
- return queryResult == null ? Collections.<String>emptyList() : queryResult.getPathNames();
- } catch (HibernateException e) {
- addException(e);
- }
- return null;
- }
-
-
- public void setSession(Session s) {
- //do nothing
- }
-
- public String getQueryString() {
- return criteriaCode;
- }
-
- @Override
- public void setQueryString(String criteriaCode) {
- this.criteriaCode = criteriaCode;
- list = null;
- queryResult = null;
- }
-
-}
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.hibernate.console.ext;
-
-import java.util.List;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public interface QueryResult {
-
- public List<Object> list();
-
- public List<String> getPathNames();
-
- public long getQueryTime();
-
- public boolean hasExceptions();
-
- public List<Throwable> getExceptions();
-
- public void setPathNames(List<String> pathNames);
-
-}
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 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.hibernate.console.ext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public class QueryResultImpl implements QueryResult {
-
- private List<Object> list = new ArrayList<Object>();;
-
- private List<String> pathNames = Collections.emptyList();
-
- private long execTime;
-
- private List<Throwable> exceptions = new ArrayList<Throwable>();
-
- public QueryResultImpl(List<Object> list, long execTime){
- this.list = list;
- this.execTime = execTime;
- }
-
- public QueryResultImpl(List<Object> list, List<String> pathNames, long execTime){
- this(list, execTime);
- this.pathNames = pathNames;
- }
-
- public QueryResultImpl(Throwable e){
- exceptions.add(e);
- }
-
- @Override
- public List<Object> list() {
- return list;
- }
-
- @Override
- public List<String> getPathNames() {
- return pathNames;
- }
-
- @Override
- public void setPathNames(List<String> pathNames) {
- this.pathNames = pathNames;
- }
-
- public long getExecTime() {
- return execTime;
- }
-
- @Override
- public long getQueryTime() {
- return execTime;
- }
-
- public void addException(Throwable e){
- exceptions.add(e);
- }
-
- public List<Throwable> getExceptions(){
- return this.exceptions;
- }
-
- @Override
- public boolean hasExceptions() {
- return getExceptions().size() > 0;
- }
-
-}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -17,6 +17,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.hibernate.console.QueryPage;
import org.hibernate.console.ext.HibernateExtension;
/**
@@ -27,7 +29,7 @@
public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int position);
- public void setHibernateException(HibernateExtension hibernateExtension);
+ public void setHibernateExtention(HibernateExtension hibernateExtension);
/**
*
@@ -41,4 +43,6 @@
public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException;
+ public IPropertySource getPropertySource(Object object, QueryPage selectedQueryPage);
+
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionDefinition.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionDefinition.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionDefinition.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -43,7 +43,7 @@
try {
ConsoleExtension consoleExtension = (ConsoleExtension) element
.createExecutableExtension(CLASSNAME);
- consoleExtension.setHibernateException(hibernateExtension);
+ consoleExtension.setHibernateExtention(hibernateExtension);
return consoleExtension;
} catch (CoreException e) {
e.printStackTrace();
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/CollectionPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/CollectionPropertySource.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/CollectionPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,99 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.hibernate.eclipse.console.views.properties;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.eclipse.ui.views.properties.IPropertySource;
-import org.eclipse.ui.views.properties.PropertyDescriptor;
-
-public class CollectionPropertySource implements IPropertySource {
-
- private Collection<?> collection;
-
- IPropertyDescriptor[] descriptors = null;
-
- Map<Object, Object> values = new WeakHashMap<Object, Object>();
-
- public CollectionPropertySource(Collection<?> propertyValue) {
- collection = propertyValue;
- }
-
- public Object getEditableValue() {
- return null;
- }
-
- public IPropertyDescriptor[] getPropertyDescriptors() {
- if(descriptors==null) {
- PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
- for (int i = 0; i < properties.length; i++) {
- properties[i] = new PropertyDescriptor(Integer.valueOf(i),"#" + i); //$NON-NLS-1$
- }
- descriptors = properties;
- }
- return descriptors;
- }
-
- public Object getPropertyValue(Object id) {
- Object value = values.get(id);
- if(value==null) {
- Integer i = (Integer) id;
- Iterator<?> iterator = collection.iterator();
- int base = 0;
-
- while(iterator.hasNext()) {
-
- value = iterator.next();
-
- if(base==i.intValue()) {
- values.put(id, value);
- return value;
- } else {
- value=null;
- }
- base++;
- }
- }
-
- return value;
- }
-
- public boolean isPropertySet(Object id) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void resetPropertyValue(Object id) {
- // TODO Auto-generated method stub
-
- }
-
- public void setPropertyValue(Object id, Object value) {
-
-
- }
-
-}
Deleted: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/EntityPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/EntityPropertySource.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/EntityPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,173 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.hibernate.eclipse.console.views.properties;
-
-import java.util.Collection;
-
-import org.eclipse.ui.views.properties.IPropertyDescriptor;
-import org.eclipse.ui.views.properties.IPropertySource2;
-import org.eclipse.ui.views.properties.PropertyDescriptor;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.console.execution.ExecutionContext;
-import org.hibernate.console.execution.ExecutionContext.Command;
-import org.hibernate.eclipse.console.HibernateConsoleMessages;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.metadata.CollectionMetadata;
-import org.hibernate.persister.entity.AbstractEntityPersister;
-import org.hibernate.proxy.HibernateProxyHelper;
-import org.hibernate.tuple.entity.EntityMetamodel;
-
-
-
-public class EntityPropertySource implements IPropertySource2
-{
- private Object reflectedObject;
- private IPropertyDescriptor[] propertyDescriptors;
-
- private final String consoleConfigName;
- private final Session currentSession;
- private ClassMetadata classMetadata;
-
- public EntityPropertySource(final Object object, final Session currentSession, String consoleConfigName)
- {
- this.currentSession = currentSession;
- this.consoleConfigName = consoleConfigName;
- reflectedObject = object;
- if(currentSession.isOpen()) {
- classMetadata = currentSession.getSessionFactory().getClassMetadata( currentSession.getEntityName(reflectedObject) );
- } else {
- classMetadata = currentSession.getSessionFactory().getClassMetadata( HibernateProxyHelper.getClassWithoutInitializingProxy(reflectedObject));
- }
-
- }
-
-
- public Object getEditableValue() {
- return ""; //$NON-NLS-1$
- }
-
- public IPropertyDescriptor[] getPropertyDescriptors() {
- if (propertyDescriptors == null) {
- ConsoleConfiguration consoleConfig = KnownConfigurations.getInstance().find(consoleConfigName);
- if (consoleConfig != null) {
- ExecutionContext executionContext = consoleConfig.getExecutionContext();
- if (executionContext == null) {
- consoleConfig.build();
- executionContext = consoleConfig.getExecutionContext();
- }
- if (executionContext != null) {
- executionContext.execute(new Command() {
- public Object execute() {
- propertyDescriptors = initializePropertyDescriptors(classMetadata);
- return null;
- }
- });
- }
- }
- }
- return propertyDescriptors;
- }
-
- static protected IPropertyDescriptor[] initializePropertyDescriptors(ClassMetadata classMetadata) {
-
- String[] propertyNames = classMetadata.getPropertyNames();
- int length = propertyNames.length;
-
- PropertyDescriptor identifier = null;
-
- if(classMetadata.hasIdentifierProperty() ) {
- identifier = new PropertyDescriptor(classMetadata.getIdentifierPropertyName(), classMetadata.getIdentifierPropertyName());
- identifier.setCategory(HibernateConsoleMessages.EntityPropertySource_identifier);
- length++;
- }
-
- PropertyDescriptor[] properties = new PropertyDescriptor[length];
-
- int idx = 0;
- if(identifier!=null) {
- properties[idx++] = identifier;
- }
-
- for (int i = 0; i < propertyNames.length; i++) {
- PropertyDescriptor prop = new PropertyDescriptor(propertyNames[i],propertyNames[i]);
- prop.setCategory(HibernateConsoleMessages.EntityPropertySource_properties);
- properties[i+idx] = prop;
- }
-
- return properties;
- }
-
-
- public Object getPropertyValue(Object id) {
- Object propertyValue;
-
- if(id.equals(classMetadata.getIdentifierPropertyName())) {
- propertyValue = classMetadata.getIdentifier(reflectedObject, EntityMode.POJO);
- } else {
- try {
- propertyValue = classMetadata.getPropertyValue(reflectedObject, (String)id, EntityMode.POJO);
- } catch (HibernateException he) {
- propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
- if (classMetadata instanceof AbstractEntityPersister) {
- AbstractEntityPersister aep = (AbstractEntityPersister)classMetadata;
- EntityMetamodel emm = aep.getEntityMetamodel();
- if (emm != null) {
- Integer idx = emm.getPropertyIndexOrNull((String)id);
- if (idx != null) {
- propertyValue = emm.getTuplizer(EntityMode.POJO).getPropertyValue(reflectedObject, idx);
- }
- }
- }
- }
- }
-
- if (propertyValue instanceof Collection<?>) {
- CollectionMetadata collectionMetadata = currentSession.getSessionFactory().getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
- if(collectionMetadata!=null) {
- propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
- }
- }
- return propertyValue;
- }
-
- public boolean isPropertySet(Object id) {
- return false; // we can not decide this at the given point.
- }
-
- public void resetPropertyValue(Object id) {
-
- }
-
- public void setPropertyValue(Object id, Object value) {
- // lets not support editing in the raw properties view - to flakey ui.
- //classMetadata.setPropertyValue(reflectedObject, (String) id, value, EntityMode.POJO);
- }
-
- public boolean isPropertyResettable(Object id) {
- return false;
- }
-
-}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/HibernatePropertySourceProvider.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/HibernatePropertySourceProvider.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/HibernatePropertySourceProvider.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -25,6 +25,8 @@
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.hibernate.Session;
import org.hibernate.console.QueryPage;
+import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.console.ext.ConsoleExtensionManager;
import org.hibernate.eclipse.console.views.QueryPageTabView;
import org.hibernate.proxy.HibernateProxyHelper;
@@ -45,17 +47,21 @@
{
return new QueryPagePropertySource( (QueryPage)object);
}
- else if (object instanceof CollectionPropertySource) {
+ else if (object instanceof IPropertySource) {
return (IPropertySource) object;
}
else {
+ QueryPage selectedQueryPage = view.getSelectedQueryPage();
+ ConsoleExtension consoleExtension = ConsoleExtensionManager.getConsoleExtension(selectedQueryPage.getHibernateExtension());
+ return consoleExtension.getPropertySource(object, selectedQueryPage);
+ /*return (IPropertySource) selectedQueryPage.getAdapter(IPropertySource.class);
// maybe we should be hooked up with the queryview to get this ?
- /*Session currentSession = view.getSelectedQueryPage().getSession();
+ Session currentSession = .getSession();
String consoleConfigName = view.getSelectedQueryPage().getConsoleConfiguration().getName();
if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
return new EntityPropertySource(object, currentSession, consoleConfigName);
} else {*/
- return null;
+ //return null;
//}
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/QueryPagePropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/QueryPagePropertySource.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/properties/QueryPagePropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -101,7 +101,7 @@
public Object getPropertyValue(Object id) {
if(CONFIGURATION_TEXT.equals(id) ) {
- return page.getConsoleConfiguration().getName();
+ return page.getHibernateExtension().getConsoleConfigurationName();
}
if(QUERY_TEXT.equals(id) ) {
return page.getQueryString();
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConfigurationAdapterFactory.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -108,7 +108,7 @@
private Object getPropertySource(Object adaptableObject) {
- return null;//new GenericPropertySource(adaptableObject);
+ return new GenericPropertySource(adaptableObject);
}
private Object getDeferredAdapter(Object adaptableObject) {
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -58,12 +58,10 @@
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.hibernate.HibernateException;
-import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.QueryPage;
-import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.eclipse.console.AbstractQueryEditor;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -144,18 +142,8 @@
if (queryPage == null || !getPinToOneResTab()) {
queryPage = cfg.executeBSHQuery(getQueryString(), getQueryInputModel().getCopyForQuery() );
} else {
- final ConsoleConfiguration cfg0 = cfg;
- cfg.execute(new Command() {
- public Object execute() {
- KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
- Session session = cfg0.getSessionFactory().openSession();
- queryPage.setModel(getQueryInputModel().getCopyForQuery());
- queryPage.setQueryString(getQueryString());
- queryPage.setSession(session);
- KnownConfigurations.getInstance().getQueryPageModel().add(queryPage);
- return null;
- }
- });
+ KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
+ queryPage = cfg.executeBSHQuery(getQueryString(), getQueryInputModel().getCopyForQuery());
}
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -58,11 +58,9 @@
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.hibernate.Session;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.QueryPage;
-import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.eclipse.console.AbstractQueryEditor;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -448,18 +446,8 @@
if (queryPage == null || !getPinToOneResTab()) {
queryPage = cfg.executeHQLQuery(getQueryString(), getQueryInputModel().getCopyForQuery());
} else {
- final ConsoleConfiguration cfg0 = cfg;
- cfg.execute(new Command() {
- public Object execute() {
- KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
- Session session = cfg0.getSessionFactory().openSession();
- queryPage.setModel(getQueryInputModel().getCopyForQuery());
- queryPage.setQueryString(getQueryString());
- queryPage.setSession(session);
- KnownConfigurations.getInstance().getQueryPageModel().add(queryPage);
- return null;
- }
- });
+ KnownConfigurations.getInstance().getQueryPageModel().remove(queryPage);
+ queryPage = cfg.executeHQLQuery(getQueryString(), getQueryInputModel().getCopyForQuery());
}
}
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/.classpath
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/.classpath 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/.classpath 2012-03-28 15:06:44 UTC (rev 39892)
@@ -22,7 +22,7 @@
<classpathentry exported="true" kind="lib" path="lib/hibernate/proxool-0.8.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hibernate/swarmcache-1.0rc2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/tools/freemarker.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/tools/hibernate-tools.jar" sourcepath="C:/dev/workspaces/RedHat/hibernate_trunk-orig/hibernateext.tools.trunk/src"/>
+ <classpathentry exported="true" kind="lib" path="lib/tools/hibernate-tools.jar" sourcepath="C:/dev/workspaces/RedHat/_Git/hibernate-tools.core/hibernate-tools"/>
<classpathentry exported="true" kind="lib" path="lib/bsh-core-2.0b4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hibernate/jgroups-2.2.8.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hibernate/antlr-2.7.6.jar"/>
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.libs/lib/tools/hibernate-tools.jar
===================================================================
(Binary files differ)
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -78,7 +78,7 @@
private ComboDialogField dialectName;
- private Button selectMethod;
+ private Button useConsoleConfiguration;
private Group dbGroup;
@@ -129,26 +129,26 @@
createChildControls(container);
- selectMethod = new Button(container, SWT.CHECK);
- selectMethod.setText(Messages.GenerateInitWizardPage_use_console_configuration);
- selectMethod.setSelection(true);
- selectMethod.addSelectionListener(new SelectionListener(){
+ useConsoleConfiguration = new Button(container, SWT.CHECK);
+ useConsoleConfiguration.setText(Messages.GenerateInitWizardPage_use_console_configuration);
+ useConsoleConfiguration.setSelection(true);
+ useConsoleConfiguration.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
- consoleConfigurationName.setEnabled(selectMethod.getSelection());
- hibernateVersion.setEnabled(!selectMethod.getSelection());
- connectionProfileName.setEnabled(!selectMethod.getSelection());
- schemaName.setEnabled(!selectMethod.getSelection());
- dialectName.setEnabled(!selectMethod.getSelection());
+ consoleConfigurationName.setEnabled(useConsoleConfiguration.getSelection());
+ hibernateVersion.setEnabled(!useConsoleConfiguration.getSelection());
+ connectionProfileName.setEnabled(!useConsoleConfiguration.getSelection());
+ schemaName.setEnabled(!useConsoleConfiguration.getSelection());
+ dialectName.setEnabled(!useConsoleConfiguration.getSelection());
dialogChanged();
}});
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = numColumns;
- selectMethod.setLayoutData(gd);
+ useConsoleConfiguration.setLayoutData(gd);
consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
@@ -214,7 +214,7 @@
}
connectionProfileName.doFillIntoGrid(dbGroup, numColumns);
connectionProfileName.setDialogFieldListener(fieldlistener);
- connectionProfileName.setEnabled(!selectMethod.getSelection());
+ connectionProfileName.setEnabled(!useConsoleConfiguration.getSelection());
//****************************dialect*****************
dialectName = new ComboDialogField(SWT.NONE);
dialectName.setLabelText(HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect);
@@ -234,8 +234,12 @@
Control[] controls = schemaName.doFillIntoGrid(dbGroup, numColumns);
// Hack to tell the text field to stretch!
( (GridData)controls[1].getLayoutData() ).grabExcessHorizontalSpace = true;
- schemaName.setEnabled(!selectMethod.getSelection());
+ schemaName.setEnabled(!useConsoleConfiguration.getSelection());
}
+
+ protected boolean isUseConsoleConfiguration(){
+ return useConsoleConfiguration.getSelection();
+ }
protected String getHibernateVersion(){
return hibernateVersion.getText();
@@ -251,12 +255,12 @@
return;
}
- if (selectMethod.getSelection() && (StringHelper.isEmpty(getConfigurationName()))){
+ if (useConsoleConfiguration.getSelection() && (StringHelper.isEmpty(getConfigurationName()))){
setPageComplete(false);
setErrorMessage(Messages.GenerateInitWizardPage_err_msg_select_console_configuration);
return;
}
- if (!selectMethod.getSelection() && (StringHelper.isEmpty(getConnectionProfileName()))){
+ if (!useConsoleConfiguration.getSelection() && (StringHelper.isEmpty(getConnectionProfileName()))){
setPageComplete(false);
setErrorMessage(Messages.GenerateInitWizardPage_err_msg_select_connection_profile);
return;
@@ -285,7 +289,7 @@
}
public String getConfigurationName() {
- if (selectMethod.getSelection())
+ if (useConsoleConfiguration.getSelection())
return consoleConfigurationName.getText();
return createConsoleConfiguration();
}
@@ -311,7 +315,7 @@
}
public boolean isTemporaryConfiguration(){
- return !selectMethod.getSelection();
+ return !useConsoleConfiguration.getSelection();
}
public JpaProject getJpaProject(){
@@ -353,7 +357,7 @@
if (!AUTODETECT.equals(dialectName.getText())){
return helper.getDialectClass(dialectName.getText());
}
- if (!selectMethod.getSelection()){
+ if (!useConsoleConfiguration.getSelection()){
String driver = ConnectionProfileUtil.getDriverClass(getConnectionProfileName());
return helper.getDialect(driver);
}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF 2012-03-28 15:06:44 UTC (rev 39892)
@@ -14,7 +14,8 @@
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",
- org.eclipse.datatools.connectivity;bundle-version="1.2.0"
+ org.eclipse.datatools.connectivity;bundle-version="1.2.0",
+ org.eclipse.ui.views;bundle-version="3.6.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.debug.core
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HQLQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HQLQueryPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HQLQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_5;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.type.Type;
+
+
+public class HQLQueryPage extends AbstractQueryPage {
+
+ private Query query;
+ private String queryString;
+
+ public List<Object> getList() {
+ if (query==null) return Collections.emptyList();
+ if (list == null) {
+ try {
+
+ //list = query.list();
+ list = new ArrayList<Object>();
+ setupParameters(query, model);
+ long startTime = System.currentTimeMillis();
+ 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);
+ }
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ } catch (IllegalArgumentException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ }
+ return list;
+ }
+
+
+ private 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];
+
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), parameter.getType());
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
+ }
+ }
+ }
+ }
+
+ private Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+ /**
+ * @param session
+ * @param string
+ * @param queryParameters
+ */
+ public HQLQueryPage(HibernateExtension extension, String string, QueryInputModel model) {
+ super(extension, model);
+ queryString = string;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ query = this.getSession().createQuery(getQueryString());
+ } catch (HibernateException e) {
+ addException(e);
+ } catch (Exception e) {
+ addException( e );
+ }
+ }
+
+ /**
+ * @return
+ */
+ public String getQueryString() {
+ return queryString; // cannot use query since it might be null because of an error!
+ }
+
+ public void setQueryString(String queryString) {
+ this.queryString = queryString;
+ list = null;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = Collections.emptyList();
+
+ try {
+ 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]);
+ }
+ }
+ } catch (HibernateException he) {
+ addException(he);
+ }
+
+ return l;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/HibernateExtension3_5.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -28,13 +28,12 @@
import org.hibernate.console.ConsoleConfigClassLoader;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.QueryPage;
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;
import org.hibernate.eclipse.libs.FakeDelegatingDriver;
@@ -67,53 +66,29 @@
}
@Override
- public QueryResult executeHQLQuery(String hql,
- QueryInputModel queryParameters) {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.executeHQLQuery(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);
+ public QueryPage executeHQLQuery(final String hql,
+ final QueryInputModel queryParameters) {
+ return (QueryPage)execute(new Command() {
+ public Object execute() {
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new HQLQueryPage(HibernateExtension3_5.this, hql,queryParameters);
+ qp.setSession(session);
+ return qp;
}
- } finally {
- if (session != null && session.isOpen()){
- try {
- session.close();
- } catch (HibernateException e) {
- return new QueryResultImpl(e);
- }
- }
- }
+ });
}
@Override
- public QueryResult executeCriteriaQuery(String criteriaCode,
- QueryInputModel model) {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.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);
+ public QueryPage executeCriteriaQuery(final String criteriaCode,
+ final QueryInputModel model) {
+ return (QueryPage)execute(new Command() {
+ public Object execute() {
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new JavaPage(HibernateExtension3_5.this,criteriaCode,model);
+ qp.setSession(session);
+ return qp;
}
- } finally {
- if (session != null && session.isOpen()){
- try {
- session.close();
- } catch (HibernateException e) {
- return new QueryResultImpl(e);
- }
- }
- }
+ });
}
/**
@@ -334,4 +309,14 @@
}
});
}
+
+ @Override
+ public boolean hasExecutionContext() {
+ return executionContext != null;
+ }
+
+ @Override
+ public String getConsoleConfigurationName() {
+ return prefs.getName();
+ }
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/JavaPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/JavaPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/JavaPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_5;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.engine.SessionImplementor;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author MAX
+ *
+ *
+ */
+public class JavaPage extends AbstractQueryPage {
+
+ private String criteriaCode;
+
+ Criteria criteria = null;
+
+ private Interpreter ip;
+
+ /**
+ * @param model
+ * @param session2
+ */
+ public JavaPage(HibernateExtension extension, String criteriaCode, QueryInputModel model) {
+ super(extension, model);
+ this.criteriaCode = criteriaCode;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ if(criteriaCode.indexOf( "System.exit" )>=0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
+ list = Collections.emptyList();
+ addException( new IllegalArgumentException(ConsoleMessages.JavaPage_not_allowed) );
+ return;
+ }
+ ip = setupInterpreter(getSession() );
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if(o instanceof Criteria) {
+ criteria = (Criteria) o;
+ if(model.getMaxResults()!=null) {
+ criteria.setMaxResults( model.getMaxResults().intValue() );
+ }
+ } 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);
+ }
+ }
+ catch (EvalError e) {
+ addException(e);
+ }
+ catch (HibernateException e) {
+ addException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private 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;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Object> getList() {
+ if(list!=null) return list;
+ try {
+ if(criteria!=null) {
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ }
+ else {
+ return Collections.emptyList();
+ }
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ return list;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = new ArrayList<String>();
+ l.add(ConsoleMessages.JavaPage_no_info);
+ return l;
+ }
+
+ public String getQueryString() {
+ return criteriaCode;
+ }
+ public void setQueryString(String queryString) {
+ this.criteriaCode = queryString;
+ list = null;
+ ip = null;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryHelper.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryHelper.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/QueryHelper.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -10,205 +10,27 @@
******************************************************************************/
package org.jboss.tools.hibernate3_5;
-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.SessionFactory;
-import org.hibernate.console.ConsoleMessages;
-import org.hibernate.console.ConsoleQueryParameter;
-import org.hibernate.console.QueryInputModel;
import org.hibernate.console.execution.ExecutionContext;
-import org.hibernate.console.ext.HibernateException;
-import org.hibernate.console.ext.QueryResult;
-import org.hibernate.console.ext.QueryResultImpl;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.QLFormatHelper;
-import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.HQLQueryPlan;
import org.hibernate.hql.QueryTranslator;
import org.hibernate.impl.SessionFactoryImpl;
import org.hibernate.type.Type;
import org.hibernate.util.xpl.StringHelper;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author Dmitry Geraskov
*
*/
public class QueryHelper {
- public static QueryResult executeHQLQuery(Session session, String hql,
- QueryInputModel queryParameters) {
-
- Query query = session.createQuery(hql);
- List<Object> list = Collections.emptyList();
- long queryTime = 0;
-
- list = new ArrayList<Object>();
- setupParameters(query, queryParameters);
- 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];
-
- try {
- int pos = Integer.parseInt(parameter.getName());
- //FIXME no method to set positioned list value
- query2.setParameter(pos, calcValue( parameter ), parameter.getType());
- } catch(NumberFormatException nfe) {
- Object value = parameter.getValue();
- if (value != null && value.getClass().isArray()){
- Object[] values = (Object[])value;
- query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
- } else {
- query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
- }
- }
- }
- }
-
- 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;
- }
-
static String generateSQL(ExecutionContext executionContext, final SessionFactory sessionFactory, final String query) {
if(StringHelper.isEmpty(query)) return ""; //$NON-NLS-1$
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CollectionPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CollectionPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CollectionPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_5.console;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class CollectionPropertySource implements IPropertySource {
+
+ private Collection<?> collection;
+
+ IPropertyDescriptor[] descriptors = null;
+
+ Map<Object, Object> values = new WeakHashMap<Object, Object>();
+
+ public CollectionPropertySource(Collection<?> propertyValue) {
+ collection = propertyValue;
+ }
+
+ public Object getEditableValue() {
+ return null;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if(descriptors==null) {
+ PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
+ for (int i = 0; i < properties.length; i++) {
+ properties[i] = new PropertyDescriptor(Integer.valueOf(i),"#" + i); //$NON-NLS-1$
+ }
+ descriptors = properties;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ Object value = values.get(id);
+ if(value==null) {
+ Integer i = (Integer) id;
+ Iterator<?> iterator = collection.iterator();
+ int base = 0;
+
+ while(iterator.hasNext()) {
+
+ value = iterator.next();
+
+ if(base==i.intValue()) {
+ values.put(id, value);
+ return value;
+ } else {
+ value=null;
+ }
+ base++;
+ }
+ }
+
+ return value;
+ }
+
+ public boolean isPropertySet(Object id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void resetPropertyValue(Object id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+
+
+ }
+
+}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -29,6 +29,8 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
@@ -38,7 +40,7 @@
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.QueryPage;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
import org.hibernate.console.ext.HibernateExtension;
@@ -49,6 +51,7 @@
import org.hibernate.eclipse.launch.CodeGenerationStrings;
import org.hibernate.eclipse.launch.CodeGenerationUtils;
import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.proxy.HibernateProxyHelper;
import org.hibernate.tool.hbm2x.ArtifactCollector;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
@@ -66,10 +69,6 @@
private HibernateExtension3_5 hibernateExtension;
public ConsoleExtension3_5(){}
-
- public void setHibernateException(HibernateExtension hibernateExtension){
- this.hibernateExtension = (HibernateExtension3_5) hibernateExtension;
- }
@Override
public CompletionProposalsResult hqlCodeComplete(String query, int startPosition, int currentOffset) {
@@ -292,4 +291,23 @@
}
}
+ @Override
+ public void setHibernateExtention(HibernateExtension hibernateExtension) {
+ this.hibernateExtension = (HibernateExtension3_5) hibernateExtension;
+ }
+
+ @Override
+ public IPropertySource getPropertySource(Object object,
+ QueryPage selectedQueryPage) {
+ Session currentSession = selectedQueryPage.getSession();
+ if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
+ return new EntityPropertySource(object, selectedQueryPage.getSession(), hibernateExtension);
+ }
+ return null;
+ }
+
+ private boolean hasMetaData(Object object, Session currentSession) {
+ return currentSession.getSessionFactory().getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(object))!=null;
+ }
+
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EntityPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EntityPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EntityPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_5.console;
+
+import java.util.Collection;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource2;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.persister.entity.AbstractEntityPersister;
+import org.hibernate.proxy.HibernateProxyHelper;
+import org.hibernate.tuple.entity.EntityMetamodel;
+
+
+
+public class EntityPropertySource implements IPropertySource2
+{
+ private Object reflectedObject;
+ private IPropertyDescriptor[] propertyDescriptors;
+
+ private final HibernateExtension extension;
+ private final Session currentSession;
+ private ClassMetadata classMetadata;
+
+ public EntityPropertySource(final Object object, final Session currentSession, HibernateExtension extension)
+ {
+ this.currentSession = currentSession;
+ this.extension = extension;
+ reflectedObject = object;
+ if(currentSession.isOpen()) {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( currentSession.getEntityName(reflectedObject) );
+ } else {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( HibernateProxyHelper.getClassWithoutInitializingProxy(reflectedObject));
+ }
+
+ }
+
+
+ public Object getEditableValue() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (propertyDescriptors == null) {
+ if (extension != null) {
+ if (!extension.hasExecutionContext()) {
+ extension.build();
+ }
+ extension.execute(new Command() {
+ public Object execute() {
+ propertyDescriptors = initializePropertyDescriptors(classMetadata);
+ return null;
+ }
+ });
+ }
+ }
+ return propertyDescriptors;
+ }
+
+ static protected IPropertyDescriptor[] initializePropertyDescriptors(ClassMetadata classMetadata) {
+
+ String[] propertyNames = classMetadata.getPropertyNames();
+ int length = propertyNames.length;
+
+ PropertyDescriptor identifier = null;
+
+ if(classMetadata.hasIdentifierProperty() ) {
+ identifier = new PropertyDescriptor(classMetadata.getIdentifierPropertyName(), classMetadata.getIdentifierPropertyName());
+ identifier.setCategory(HibernateConsoleMessages.EntityPropertySource_identifier);
+ length++;
+ }
+
+ PropertyDescriptor[] properties = new PropertyDescriptor[length];
+
+ int idx = 0;
+ if(identifier!=null) {
+ properties[idx++] = identifier;
+ }
+
+ for (int i = 0; i < propertyNames.length; i++) {
+ PropertyDescriptor prop = new PropertyDescriptor(propertyNames[i],propertyNames[i]);
+ prop.setCategory(HibernateConsoleMessages.EntityPropertySource_properties);
+ properties[i+idx] = prop;
+ }
+
+ return properties;
+ }
+
+
+ public Object getPropertyValue(Object id) {
+ Object propertyValue;
+
+ if(id.equals(classMetadata.getIdentifierPropertyName())) {
+ propertyValue = classMetadata.getIdentifier(reflectedObject, EntityMode.POJO);
+ } else {
+ try {
+ propertyValue = classMetadata.getPropertyValue(reflectedObject, (String)id, EntityMode.POJO);
+ } catch (HibernateException he) {
+ propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
+ if (classMetadata instanceof AbstractEntityPersister) {
+ AbstractEntityPersister aep = (AbstractEntityPersister)classMetadata;
+ EntityMetamodel emm = aep.getEntityMetamodel();
+ if (emm != null) {
+ Integer idx = emm.getPropertyIndexOrNull((String)id);
+ if (idx != null) {
+ propertyValue = emm.getTuplizer(EntityMode.POJO).getPropertyValue(reflectedObject, idx);
+ }
+ }
+ }
+ }
+ }
+
+ if (propertyValue instanceof Collection<?>) {
+ CollectionMetadata collectionMetadata = currentSession.getSessionFactory().getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
+ if(collectionMetadata!=null) {
+ propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
+ }
+ }
+ return propertyValue;
+ }
+
+ public boolean isPropertySet(Object id) {
+ return false; // we can not decide this at the given point.
+ }
+
+ public void resetPropertyValue(Object id) {
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ // lets not support editing in the raw properties view - to flakey ui.
+ //classMetadata.setPropertyValue(reflectedObject, (String) id, value, EntityMode.POJO);
+ }
+
+ public boolean isPropertyResettable(Object id) {
+ return false;
+ }
+
+}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/META-INF/MANIFEST.MF 2012-03-28 15:06:44 UTC (rev 39892)
@@ -13,7 +13,8 @@
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"
+ org.eclipse.jdt.core;bundle-version="3.7.0",
+ org.eclipse.ui.views;bundle-version="3.6.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: lib/required/antlr-2.7.6.jar,
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HQLQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HQLQueryPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HQLQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+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 org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.type.Type;
+
+
+public class HQLQueryPage extends AbstractQueryPage {
+
+ private Query query;
+ private String queryString;
+
+ public List<Object> getList() {
+ if (query==null) return Collections.emptyList();
+ if (list == null) {
+ try {
+
+ //list = query.list();
+ list = new ArrayList<Object>();
+ setupParameters(query, model);
+ long startTime = System.currentTimeMillis();
+ 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);
+ }
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ } catch (IllegalArgumentException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ }
+ return list;
+ }
+
+
+ private 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];
+
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), parameter.getType());
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
+ }
+ }
+ }
+ }
+
+ private Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+ /**
+ * @param session
+ * @param string
+ * @param queryParameters
+ */
+ public HQLQueryPage(HibernateExtension extension, String string, QueryInputModel model) {
+ super(extension, model);
+ queryString = string;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ query = this.getSession().createQuery(getQueryString());
+ } catch (HibernateException e) {
+ addException(e);
+ } catch (Exception e) {
+ addException( e );
+ }
+ }
+
+ /**
+ * @return
+ */
+ public String getQueryString() {
+ return queryString; // cannot use query since it might be null because of an error!
+ }
+
+ public void setQueryString(String queryString) {
+ this.queryString = queryString;
+ list = null;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = Collections.emptyList();
+
+ try {
+ 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]);
+ }
+ }
+ } catch (HibernateException he) {
+ addException(he);
+ }
+
+ return l;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: 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 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/HibernateExtension3_6.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -27,13 +27,12 @@
import org.hibernate.console.ConsoleConfigClassLoader;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.QueryPage;
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;
@@ -65,58 +64,29 @@
}
@Override
- public QueryResult executeHQLQuery(String hql,
- QueryInputModel queryParameters) {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.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);
+ public QueryPage executeHQLQuery(final String hql,
+ final QueryInputModel queryParameters) {
+ return (QueryPage)execute(new Command() {
+ public Object execute() {
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new HQLQueryPage(HibernateExtension3_6.this, hql,queryParameters);
+ qp.setSession(session);
+ return qp;
}
- } finally {
- if (session != null && session.isOpen()){
- try {
- session.close();
- } catch (HibernateException e) {
- return new QueryResultImpl(e);
- }
- }
- }
+ });
}
@Override
- public QueryResult executeCriteriaQuery(final String criteriaCode,
+ public QueryPage executeCriteriaQuery(final String criteriaCode,
final QueryInputModel model) {
- return (QueryResult) execute(new Command() {
+ return (QueryPage)execute(new Command() {
public Object execute() {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.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);
- }
- }
- }
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new JavaPage(HibernateExtension3_6.this,criteriaCode,model);
+ qp.setSession(session);
+ return qp;
}
});
-
}
/**
@@ -341,4 +311,14 @@
}
});
}
+
+ @Override
+ public boolean hasExecutionContext() {
+ return executionContext != null;
+ }
+
+ @Override
+ public String getConsoleConfigurationName() {
+ return prefs.getName();
+ }
}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/JavaPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/JavaPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/JavaPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_6;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.engine.SessionImplementor;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author MAX
+ *
+ *
+ */
+public class JavaPage extends AbstractQueryPage {
+
+ private String criteriaCode;
+
+ Criteria criteria = null;
+
+ private Interpreter ip;
+
+ /**
+ * @param model
+ * @param session2
+ */
+ public JavaPage(HibernateExtension extension, String criteriaCode, QueryInputModel model) {
+ super(extension, model);
+ this.criteriaCode = criteriaCode;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ if(criteriaCode.indexOf( "System.exit" )>=0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
+ list = Collections.emptyList();
+ addException( new IllegalArgumentException(ConsoleMessages.JavaPage_not_allowed) );
+ return;
+ }
+ ip = setupInterpreter(getSession() );
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if(o instanceof Criteria) {
+ criteria = (Criteria) o;
+ if(model.getMaxResults()!=null) {
+ criteria.setMaxResults( model.getMaxResults().intValue() );
+ }
+ } 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);
+ }
+ }
+ catch (EvalError e) {
+ addException(e);
+ }
+ catch (HibernateException e) {
+ addException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private 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;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Object> getList() {
+ if(list!=null) return list;
+ try {
+ if(criteria!=null) {
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ }
+ else {
+ return Collections.emptyList();
+ }
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ return list;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = new ArrayList<String>();
+ l.add(ConsoleMessages.JavaPage_no_info);
+ return l;
+ }
+
+ public String getQueryString() {
+ return criteriaCode;
+ }
+ public void setQueryString(String queryString) {
+ this.criteriaCode = queryString;
+ list = null;
+ ip = null;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryHelper.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryHelper.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/QueryHelper.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Red Hat, Inc.
+ * Copyright (c) 2011 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,
@@ -10,231 +10,27 @@
******************************************************************************/
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.SessionFactory;
-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;
-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.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.QLFormatHelper;
-import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.HQLQueryPlan;
import org.hibernate.hql.QueryTranslator;
import org.hibernate.impl.SessionFactoryImpl;
import org.hibernate.type.Type;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.util.xpl.StringHelper;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author Dmitry Geraskov
*
*/
public class QueryHelper {
- 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;
- }
-
static String generateSQL(ExecutionContext executionContext, final SessionFactory sessionFactory, final String query) {
if(StringHelper.isEmpty(query)) return ""; //$NON-NLS-1$
@@ -298,5 +94,4 @@
return result;
}
-
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CollectionPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CollectionPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/CollectionPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class CollectionPropertySource implements IPropertySource {
+
+ private Collection<?> collection;
+
+ IPropertyDescriptor[] descriptors = null;
+
+ Map<Object, Object> values = new WeakHashMap<Object, Object>();
+
+ public CollectionPropertySource(Collection<?> propertyValue) {
+ collection = propertyValue;
+ }
+
+ public Object getEditableValue() {
+ return null;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if(descriptors==null) {
+ PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
+ for (int i = 0; i < properties.length; i++) {
+ properties[i] = new PropertyDescriptor(Integer.valueOf(i),"#" + i); //$NON-NLS-1$
+ }
+ descriptors = properties;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ Object value = values.get(id);
+ if(value==null) {
+ Integer i = (Integer) id;
+ Iterator<?> iterator = collection.iterator();
+ int base = 0;
+
+ while(iterator.hasNext()) {
+
+ value = iterator.next();
+
+ if(base==i.intValue()) {
+ values.put(id, value);
+ return value;
+ } else {
+ value=null;
+ }
+ base++;
+ }
+ }
+
+ return value;
+ }
+
+ public boolean isPropertySet(Object id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void resetPropertyValue(Object id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+
+
+ }
+
+}
Modified: 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 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/ConsoleExtension3_6.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -29,6 +29,8 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.hibernate.Session;
import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
@@ -39,6 +41,7 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.QueryPage;
import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
@@ -50,6 +53,7 @@
import org.hibernate.eclipse.launch.CodeGenerationStrings;
import org.hibernate.eclipse.launch.CodeGenerationUtils;
import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.proxy.HibernateProxyHelper;
import org.hibernate.tool.hbm2x.ArtifactCollector;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
@@ -66,7 +70,8 @@
public ConsoleExtension3_6(){}
- public void setHibernateException(HibernateExtension hibernateExtension){
+ @Override
+ public void setHibernateExtention(HibernateExtension hibernateExtension){
this.hibernateExtension = (HibernateExtension3_6) hibernateExtension;
}
@@ -309,5 +314,19 @@
throw new HibernateConsoleRuntimeException(out, e);
}
}
+
+ @Override
+ public IPropertySource getPropertySource(Object object,
+ QueryPage selectedQueryPage) {
+ Session currentSession = selectedQueryPage.getSession();
+ if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
+ return new EntityPropertySource(object, selectedQueryPage.getSession(), hibernateExtension);
+ }
+ return null;
+ }
+
+ private boolean hasMetaData(Object object, Session currentSession) {
+ return currentSession.getSessionFactory().getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(object))!=null;
+ }
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EntityPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EntityPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate3_6/src/org/jboss/tools/hibernate3_6/console/EntityPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate3_6.console;
+
+import java.util.Collection;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource2;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.persister.entity.AbstractEntityPersister;
+import org.hibernate.proxy.HibernateProxyHelper;
+import org.hibernate.tuple.entity.EntityMetamodel;
+
+
+
+public class EntityPropertySource implements IPropertySource2
+{
+ private Object reflectedObject;
+ private IPropertyDescriptor[] propertyDescriptors;
+
+ private final HibernateExtension extension;
+ private final Session currentSession;
+ private ClassMetadata classMetadata;
+
+ public EntityPropertySource(final Object object, final Session currentSession, HibernateExtension extension)
+ {
+ this.currentSession = currentSession;
+ this.extension = extension;
+ reflectedObject = object;
+ if(currentSession.isOpen()) {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( currentSession.getEntityName(reflectedObject) );
+ } else {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( HibernateProxyHelper.getClassWithoutInitializingProxy(reflectedObject));
+ }
+
+ }
+
+
+ public Object getEditableValue() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (propertyDescriptors == null) {
+ if (extension != null) {
+ if (!extension.hasExecutionContext()) {
+ extension.build();
+ }
+ extension.execute(new Command() {
+ public Object execute() {
+ propertyDescriptors = initializePropertyDescriptors(classMetadata);
+ return null;
+ }
+ });
+ }
+ }
+ return propertyDescriptors;
+ }
+
+ static protected IPropertyDescriptor[] initializePropertyDescriptors(ClassMetadata classMetadata) {
+
+ String[] propertyNames = classMetadata.getPropertyNames();
+ int length = propertyNames.length;
+
+ PropertyDescriptor identifier = null;
+
+ if(classMetadata.hasIdentifierProperty() ) {
+ identifier = new PropertyDescriptor(classMetadata.getIdentifierPropertyName(), classMetadata.getIdentifierPropertyName());
+ identifier.setCategory(HibernateConsoleMessages.EntityPropertySource_identifier);
+ length++;
+ }
+
+ PropertyDescriptor[] properties = new PropertyDescriptor[length];
+
+ int idx = 0;
+ if(identifier!=null) {
+ properties[idx++] = identifier;
+ }
+
+ for (int i = 0; i < propertyNames.length; i++) {
+ PropertyDescriptor prop = new PropertyDescriptor(propertyNames[i],propertyNames[i]);
+ prop.setCategory(HibernateConsoleMessages.EntityPropertySource_properties);
+ properties[i+idx] = prop;
+ }
+
+ return properties;
+ }
+
+
+ public Object getPropertyValue(Object id) {
+ Object propertyValue;
+
+ if(id.equals(classMetadata.getIdentifierPropertyName())) {
+ propertyValue = classMetadata.getIdentifier(reflectedObject, EntityMode.POJO);
+ } else {
+ try {
+ propertyValue = classMetadata.getPropertyValue(reflectedObject, (String)id, EntityMode.POJO);
+ } catch (HibernateException he) {
+ propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
+ if (classMetadata instanceof AbstractEntityPersister) {
+ AbstractEntityPersister aep = (AbstractEntityPersister)classMetadata;
+ EntityMetamodel emm = aep.getEntityMetamodel();
+ if (emm != null) {
+ Integer idx = emm.getPropertyIndexOrNull((String)id);
+ if (idx != null) {
+ propertyValue = emm.getTuplizer(EntityMode.POJO).getPropertyValue(reflectedObject, idx);
+ }
+ }
+ }
+ }
+ }
+
+ if (propertyValue instanceof Collection<?>) {
+ CollectionMetadata collectionMetadata = currentSession.getSessionFactory().getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
+ if(collectionMetadata!=null) {
+ propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
+ }
+ }
+ return propertyValue;
+ }
+
+ public boolean isPropertySet(Object id) {
+ return false; // we can not decide this at the given point.
+ }
+
+ public void resetPropertyValue(Object id) {
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ // lets not support editing in the raw properties view - to flakey ui.
+ //classMetadata.setPropertyValue(reflectedObject, (String) id, value, EntityMode.POJO);
+ }
+
+ public boolean isPropertyResettable(Object id) {
+ return false;
+ }
+
+}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath 2012-03-28 15:06:44 UTC (rev 39892)
@@ -14,7 +14,7 @@
<classpathentry exported="true" kind="lib" path="lib/required/jboss-logging-3.1.0.CR1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/required/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
<classpathentry exported="true" kind="lib" path="lib/tools/freemarker.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/tools/hibernate-tools-3.5.0.Beta.jar" sourcepath="C:/dev/workspaces/RedHat/_Git/dgeraskov2/hibernate-tools/src"/>
+ <classpathentry exported="true" kind="lib" path="lib/tools/hibernate-tools-3.5.0.Beta.jar" sourcepath="C:/dev/workspaces/RedHat/_Git/dgeraskov/tools4.0/hibernate-tools/src"/>
<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"/>
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2012-03-28 15:06:44 UTC (rev 39892)
@@ -13,7 +13,8 @@
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"
+ org.eclipse.jdt.core;bundle-version="3.7.0",
+ org.eclipse.ui.views;bundle-version="3.6.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: lib/jpa/hibernate-entitymanager-4.0.0.CR6.jar,
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HQLQueryPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HQLQueryPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HQLQueryPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate4_0;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.type.Type;
+
+
+public class HQLQueryPage extends AbstractQueryPage {
+
+ private Query query;
+ private String queryString;
+
+ public List<Object> getList() {
+ if (query==null) return Collections.emptyList();
+ if (list == null) {
+ try {
+
+ //list = query.list();
+ list = new ArrayList<Object>();
+ setupParameters(query, model);
+ long startTime = System.currentTimeMillis();
+ 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);
+ }
+ pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ } catch (IllegalArgumentException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ }
+ return list;
+ }
+
+
+ private 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];
+
+ try {
+ int pos = Integer.parseInt(parameter.getName());
+ //FIXME no method to set positioned list value
+ query2.setParameter(pos, calcValue( parameter ), parameter.getType());
+ } catch(NumberFormatException nfe) {
+ Object value = parameter.getValue();
+ if (value != null && value.getClass().isArray()){
+ Object[] values = (Object[])value;
+ query2.setParameterList(parameter.getName(), Arrays.asList(values), parameter.getType());
+ } else {
+ query2.setParameter(parameter.getName(), calcValue( parameter ), parameter.getType());
+ }
+ }
+ }
+ }
+
+ private Object calcValue(ConsoleQueryParameter parameter) {
+ return parameter.getValueForQuery();
+ }
+
+ /**
+ * @param session
+ * @param string
+ * @param queryParameters
+ */
+ public HQLQueryPage(HibernateExtension extension, String string, QueryInputModel model) {
+ super(extension, model);
+ queryString = string;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ query = this.getSession().createQuery(getQueryString());
+ } catch (HibernateException e) {
+ addException(e);
+ } catch (Exception e) {
+ addException( e );
+ }
+ }
+
+ /**
+ * @return
+ */
+ public String getQueryString() {
+ return queryString; // cannot use query since it might be null because of an error!
+ }
+
+ public void setQueryString(String queryString) {
+ this.queryString = queryString;
+ list = null;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = Collections.emptyList();
+
+ try {
+ 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]);
+ }
+ }
+ } catch (HibernateException he) {
+ addException(he);
+ }
+
+ return l;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -27,13 +27,12 @@
import org.hibernate.console.ConsoleConfigClassLoader;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.QueryPage;
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;
import org.hibernate.service.ServiceRegistry;
@@ -70,58 +69,29 @@
}
@Override
- public QueryResult executeHQLQuery(String hql,
- QueryInputModel queryParameters) {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.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);
+ public QueryPage executeHQLQuery(final String hql,
+ final QueryInputModel queryParameters) {
+ return (QueryPage)execute(new Command() {
+ public Object execute() {
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new HQLQueryPage(HibernateExtension4_0.this, hql,queryParameters);
+ qp.setSession(session);
+ return qp;
}
- } finally {
- if (session != null && session.isOpen()){
- try {
- session.close();
- } catch (HibernateException e) {
- return new QueryResultImpl(e);
- }
- }
- }
+ });
}
@Override
- public QueryResult executeCriteriaQuery(final String criteriaCode,
+ public QueryPage executeCriteriaQuery(final String criteriaCode,
final QueryInputModel model) {
- return (QueryResult) execute(new Command() {
+ return (QueryPage)execute(new Command() {
public Object execute() {
- Session session = null;
- try {
- try {
- session = sessionFactory.openSession();
- return QueryHelper.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);
- }
- }
- }
+ Session session = sessionFactory.openSession();
+ QueryPage qp = new JavaPage(HibernateExtension4_0.this,criteriaCode,model);
+ qp.setSession(session);
+ return qp;
}
});
-
}
/**
@@ -351,4 +321,14 @@
}
});
}
+
+ @Override
+ public boolean hasExecutionContext() {
+ return executionContext != null;
+ }
+
+ @Override
+ public String getConsoleConfigurationName() {
+ return prefs.getName();
+ }
}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/JavaPage.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/JavaPage.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/JavaPage.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate4_0;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.AbstractQueryPage;
+import org.hibernate.console.ConsoleMessages;
+import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.engine.spi.SessionImplementor;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * @author MAX
+ *
+ *
+ */
+public class JavaPage extends AbstractQueryPage {
+
+ private String criteriaCode;
+
+ Criteria criteria = null;
+
+ private Interpreter ip;
+
+ /**
+ * @param model
+ * @param session2
+ */
+ public JavaPage(HibernateExtension extension, String criteriaCode, QueryInputModel model) {
+ super(extension, model);
+ this.criteriaCode = criteriaCode;
+ setTabName(getQueryString().replace('\n', ' ').replace('\r', ' '));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setSession(Session s) {
+ super.setSession(s);
+ try {
+ if(criteriaCode.indexOf( "System.exit" )>=0) { // TODO: externalize run so we don't need this bogus check! //$NON-NLS-1$
+ list = Collections.emptyList();
+ addException( new IllegalArgumentException(ConsoleMessages.JavaPage_not_allowed) );
+ return;
+ }
+ ip = setupInterpreter(getSession() );
+ Object o = ip.eval(criteriaCode);
+ // ugly! TODO: make un-ugly!
+ if(o instanceof Criteria) {
+ criteria = (Criteria) o;
+ if(model.getMaxResults()!=null) {
+ criteria.setMaxResults( model.getMaxResults().intValue() );
+ }
+ } 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);
+ }
+ }
+ catch (EvalError e) {
+ addException(e);
+ }
+ catch (HibernateException e) {
+ addException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private 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;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Object> getList() {
+ if(list!=null) return list;
+ try {
+ if(criteria!=null) {
+ long startTime = System.currentTimeMillis();
+ list = criteria.list();
+ queryTime = System.currentTimeMillis() - startTime;
+ }
+ else {
+ return Collections.emptyList();
+ }
+ }
+ catch (HibernateException e) {
+ list = Collections.emptyList();
+ addException(e);
+ }
+ return list;
+ }
+
+ public List<String> getPathNames() {
+ List<String> l = new ArrayList<String>();
+ l.add(ConsoleMessages.JavaPage_no_info);
+ return l;
+ }
+
+ public String getQueryString() {
+ return criteriaCode;
+ }
+ public void setQueryString(String queryString) {
+ this.criteriaCode = queryString;
+ list = null;
+ ip = null;
+ }
+
+ public void release() {
+ if (getSession().isOpen() ) {
+ try {
+ getSession().close();
+ }
+ catch (HibernateException e) {
+ exceptions.add(e);
+ }
+ }
+ }
+}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryHelper.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryHelper.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryHelper.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -10,231 +10,27 @@
******************************************************************************/
package org.jboss.tools.hibernate4_0;
-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.SessionFactory;
-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;
-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.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.QLFormatHelper;
import org.hibernate.engine.query.spi.HQLQueryPlan;
-import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.internal.SessionFactoryImpl;
-import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.type.Type;
import org.hibernate.util.xpl.StringHelper;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author Dmitry Geraskov
*
*/
public class QueryHelper {
- 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 Hibernate4 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;
- }
-
static String generateSQL(ExecutionContext executionContext, final SessionFactory sessionFactory, final String query) {
if(StringHelper.isEmpty(query)) return ""; //$NON-NLS-1$
@@ -298,5 +94,4 @@
return result;
}
-
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CollectionPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CollectionPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CollectionPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate4_0.console;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+public class CollectionPropertySource implements IPropertySource {
+
+ private Collection<?> collection;
+
+ IPropertyDescriptor[] descriptors = null;
+
+ Map<Object, Object> values = new WeakHashMap<Object, Object>();
+
+ public CollectionPropertySource(Collection<?> propertyValue) {
+ collection = propertyValue;
+ }
+
+ public Object getEditableValue() {
+ return null;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if(descriptors==null) {
+ PropertyDescriptor[] properties = new PropertyDescriptor[collection.size()];
+ for (int i = 0; i < properties.length; i++) {
+ properties[i] = new PropertyDescriptor(Integer.valueOf(i),"#" + i); //$NON-NLS-1$
+ }
+ descriptors = properties;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ Object value = values.get(id);
+ if(value==null) {
+ Integer i = (Integer) id;
+ Iterator<?> iterator = collection.iterator();
+ int base = 0;
+
+ while(iterator.hasNext()) {
+
+ value = iterator.next();
+
+ if(base==i.intValue()) {
+ values.put(id, value);
+ return value;
+ } else {
+ value=null;
+ }
+ base++;
+ }
+ }
+
+ return value;
+ }
+
+ public boolean isPropertySet(Object id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void resetPropertyValue(Object id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+
+
+ }
+
+}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2012-03-28 14:41:57 UTC (rev 39891)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -29,6 +29,8 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.hibernate.Session;
import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
@@ -39,6 +41,7 @@
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.QueryPage;
import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
@@ -50,6 +53,7 @@
import org.hibernate.eclipse.launch.CodeGenerationStrings;
import org.hibernate.eclipse.launch.CodeGenerationUtils;
import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.proxy.HibernateProxyHelper;
import org.hibernate.tool.hbm2x.ArtifactCollector;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
@@ -66,7 +70,8 @@
public ConsoleExtension4_0(){}
- public void setHibernateException(HibernateExtension hibernateExtension){
+ @Override
+ public void setHibernateExtention(HibernateExtension hibernateExtension){
this.hibernateExtension = (HibernateExtension4_0) hibernateExtension;
}
@@ -307,5 +312,19 @@
throw new HibernateConsoleRuntimeException(out, e);
}
}
+
+ @Override
+ public IPropertySource getPropertySource(Object object,
+ QueryPage selectedQueryPage) {
+ Session currentSession = selectedQueryPage.getSession();
+ if((currentSession.isOpen() && currentSession.contains(object)) || hasMetaData( object, currentSession) ) {
+ return new EntityPropertySource(object, selectedQueryPage.getSession(), hibernateExtension);
+ }
+ return null;
+ }
+
+ private boolean hasMetaData(Object object, Session currentSession) {
+ return currentSession.getSessionFactory().getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(object))!=null;
+ }
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EntityPropertySource.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EntityPropertySource.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EntityPropertySource.java 2012-03-28 15:06:44 UTC (rev 39892)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tools.hibernate4_0.console;
+
+import java.util.Collection;
+
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource2;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.persister.entity.AbstractEntityPersister;
+import org.hibernate.proxy.HibernateProxyHelper;
+import org.hibernate.tuple.entity.EntityMetamodel;
+
+
+
+public class EntityPropertySource implements IPropertySource2
+{
+ private Object reflectedObject;
+ private IPropertyDescriptor[] propertyDescriptors;
+
+ private final HibernateExtension extension;
+ private final Session currentSession;
+ private ClassMetadata classMetadata;
+
+ public EntityPropertySource(final Object object, final Session currentSession, HibernateExtension extension)
+ {
+ this.currentSession = currentSession;
+ this.extension = extension;
+ reflectedObject = object;
+ if(currentSession.isOpen()) {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( currentSession.getEntityName(reflectedObject) );
+ } else {
+ classMetadata = currentSession.getSessionFactory().getClassMetadata( HibernateProxyHelper.getClassWithoutInitializingProxy(reflectedObject));
+ }
+
+ }
+
+
+ public Object getEditableValue() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (propertyDescriptors == null) {
+ if (extension != null) {
+ if (!extension.hasExecutionContext()) {
+ extension.build();
+ }
+ extension.execute(new Command() {
+ public Object execute() {
+ propertyDescriptors = initializePropertyDescriptors(classMetadata);
+ return null;
+ }
+ });
+ }
+ }
+ return propertyDescriptors;
+ }
+
+ static protected IPropertyDescriptor[] initializePropertyDescriptors(ClassMetadata classMetadata) {
+
+ String[] propertyNames = classMetadata.getPropertyNames();
+ int length = propertyNames.length;
+
+ PropertyDescriptor identifier = null;
+
+ if(classMetadata.hasIdentifierProperty() ) {
+ identifier = new PropertyDescriptor(classMetadata.getIdentifierPropertyName(), classMetadata.getIdentifierPropertyName());
+ identifier.setCategory(HibernateConsoleMessages.EntityPropertySource_identifier);
+ length++;
+ }
+
+ PropertyDescriptor[] properties = new PropertyDescriptor[length];
+
+ int idx = 0;
+ if(identifier!=null) {
+ properties[idx++] = identifier;
+ }
+
+ for (int i = 0; i < propertyNames.length; i++) {
+ PropertyDescriptor prop = new PropertyDescriptor(propertyNames[i],propertyNames[i]);
+ prop.setCategory(HibernateConsoleMessages.EntityPropertySource_properties);
+ properties[i+idx] = prop;
+ }
+
+ return properties;
+ }
+
+
+ public Object getPropertyValue(Object id) {
+ Object propertyValue;
+
+ if(id.equals(classMetadata.getIdentifierPropertyName())) {
+ propertyValue = classMetadata.getIdentifier(reflectedObject, (SessionImplementor) currentSession);
+ } else {
+ try {
+ propertyValue = classMetadata.getPropertyValue(reflectedObject, (String)id);
+ } catch (HibernateException he) {
+ propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
+ if (classMetadata instanceof AbstractEntityPersister) {
+ AbstractEntityPersister aep = (AbstractEntityPersister)classMetadata;
+ EntityMetamodel emm = aep.getEntityMetamodel();
+ if (emm != null) {
+ Integer idx = emm.getPropertyIndexOrNull((String)id);
+ if (idx != null) {
+ propertyValue = emm.getTuplizer().getPropertyValue(reflectedObject, idx);
+ }
+ }
+ }
+ }
+ }
+
+ if (propertyValue instanceof Collection<?>) {
+ CollectionMetadata collectionMetadata = currentSession.getSessionFactory().getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
+ if(collectionMetadata!=null) {
+ propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
+ }
+ }
+ return propertyValue;
+ }
+
+ public boolean isPropertySet(Object id) {
+ return false; // we can not decide this at the given point.
+ }
+
+ public void resetPropertyValue(Object id) {
+
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ // lets not support editing in the raw properties view - to flakey ui.
+ //classMetadata.setPropertyValue(reflectedObject, (String) id, value, EntityMode.POJO);
+ }
+
+ public boolean isPropertyResettable(Object id) {
+ return false;
+ }
+
+}
\ No newline at end of file
12 years, 1 month
JBoss Tools SVN: r39891 - in trunk/forge/tests: org.jboss.tools.forge.ui.test and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2012-03-28 10:41:57 -0400 (Wed, 28 Mar 2012)
New Revision: 39891
Modified:
trunk/forge/tests/org.jboss.tools.forge.core.test/pom.xml
trunk/forge/tests/org.jboss.tools.forge.ui.test/pom.xml
Log:
make org.jboss.tools.forge.core.test packaging type = eclipse-test-plugin so that the tests will actually run (and fail). put TODO in org.jboss.tools.forge.ui.test so that classes to run will be added. Currently, no source
Modified: trunk/forge/tests/org.jboss.tools.forge.core.test/pom.xml
===================================================================
--- trunk/forge/tests/org.jboss.tools.forge.core.test/pom.xml 2012-03-28 13:31:11 UTC (rev 39890)
+++ trunk/forge/tests/org.jboss.tools.forge.core.test/pom.xml 2012-03-28 14:41:57 UTC (rev 39891)
@@ -9,7 +9,7 @@
<groupId>org.jboss.tools.forge.tests</groupId>
<artifactId>org.jboss.tools.forge.core.test</artifactId>
- <packaging>eclipse-plugin</packaging>
+ <packaging>eclipse-test-plugin</packaging>
<properties>
<coverage.filter>org.jboss.tools.forge.core*</coverage.filter>
Modified: trunk/forge/tests/org.jboss.tools.forge.ui.test/pom.xml
===================================================================
--- trunk/forge/tests/org.jboss.tools.forge.ui.test/pom.xml 2012-03-28 13:31:11 UTC (rev 39890)
+++ trunk/forge/tests/org.jboss.tools.forge.ui.test/pom.xml 2012-03-28 14:41:57 UTC (rev 39891)
@@ -8,6 +8,7 @@
</parent>
<groupId>org.jboss.tools.forge.tests</groupId>
<artifactId>org.jboss.tools.forge.ui.test</artifactId>
-
+
+ <!-- TODO: this is a test plugin. It needs test classes. -->
<packaging>eclipse-plugin</packaging>
</project>
12 years, 1 month
JBoss Tools SVN: r39890 - in trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org: packageinfo and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: jpeterka
Date: 2012-03-28 09:31:11 -0400 (Wed, 28 Mar 2012)
New Revision: 39890
Added:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/Table.java
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/package-info.java
Log:
HB ui bot test package-info test project parts added
Added: trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/Table.java
===================================================================
--- trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/Table.java (rev 0)
+++ trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/Table.java 2012-03-28 13:31:11 UTC (rev 39890)
@@ -0,0 +1,23 @@
+package org.packageinfo;
+
+import java.io.Serializable;
+import javax.persistence.*;
+
+/**
+ * Entity implementation class for Entity: Dog
+ *
+ */
+@Entity
+public class Table implements Serializable {
+
+ @Id
+ @GeneratedValue(generator="myuuidgen")
+ long id;
+
+ private static final long serialVersionUID = 1L;
+
+ public Table() {
+ super();
+ }
+
+}
Property changes on: trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/Table.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/package-info.java
===================================================================
--- trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/package-info.java (rev 0)
+++ trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/package-info.java 2012-03-28 13:31:11 UTC (rev 39890)
@@ -0,0 +1,4 @@
+@GenericGenerator(name="myuuidgen",strategy="uuid")
+
+package org.packageinfo;
+import org.hibernate.annotations.GenericGenerator;
\ No newline at end of file
Property changes on: trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test/resources/prj/jpatest40/src/org/packageinfo/package-info.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
12 years, 1 month