Author: dgeraskov
Date: 2011-12-22 09:07:21 -0500 (Thu, 22 Dec 2011)
New Revision: 37528
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath
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/QueryExecutor.java
Log:
https://issues.jboss.org/browse/JBIDE-10559
Load hibernate type in HibernateExtension classloader (in this case Type from Hibernate4
will be used )
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java 2011-12-22
14:05:03 UTC (rev 37527)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/QueryParametersPage.java 2011-12-22
14:07:21 UTC (rev 37528)
@@ -308,7 +308,7 @@
}
CellEditor[] editors = new CellEditor[columnProperties.length];
editors[0] = new TextCellEditor( queryParametersTable );
- editors[1] = new ComboBoxCellEditor( queryParametersTable, valueTypes );
+ editors[1] = new ComboBoxCellEditor( queryParametersTable, valueTypes, SWT.READ_ONLY
);
editors[2] = new StringArrayDialogCellEditor(queryParametersTable) {
private Button b;
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath 2011-12-22
14:05:03 UTC (rev 37527)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/.classpath 2011-12-22
14:07:21 UTC (rev 37528)
@@ -7,14 +7,14 @@
<classpathentry exported="true" kind="lib"
path="lib/required/commons-collections-3.2.1.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/required/dom4j-1.6.1.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/required/hibernate-commons-annotations-4.0.0.Final.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/required/hibernate-core-4.0.0.CR6.jar"
sourcepath="/home/eskimo/Downloads/hibernate-release-4.0.0.CR6/project"/>
+ <classpathentry exported="true" kind="lib"
path="lib/required/hibernate-core-4.0.0.CR6.jar"
sourcepath="C:/dev/Libs/hibernate-release-4.0.0.CR6/project"/>
<classpathentry exported="true" kind="lib"
path="lib/required/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/required/jandex-1.0.3.Final.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/required/javassist-3.12.1.GA.jar"/>
<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/dgeraskov/hibernate-tools/src"/>
+ <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/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/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 2011-12-22
14:05:03 UTC (rev 37527)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/HibernateExtension4_0.java 2011-12-22
14:07:21 UTC (rev 37528)
@@ -76,7 +76,7 @@
try {
try {
session = sessionFactory.openSession();
- return QueryExecutor.executeHQLQuery(session, hql, queryParameters);
+ return QueryExecutor.executeHQLQuery(this, session, hql, queryParameters);
} catch (Throwable e){
//Incompatible library versions could throw subclasses of Error, like
AbstractMethodError
//may be there is a sense to say to user that the reason is probably a wrong CC
version
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java 2011-12-22
14:05:03 UTC (rev 37527)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/QueryExecutor.java 2011-12-22
14:07:21 UTC (rev 37528)
@@ -22,11 +22,15 @@
import org.hibernate.Session;
import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.ConsoleQueryParameter;
+import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.QueryInputModel;
+import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
import org.hibernate.console.ext.QueryResult;
import org.hibernate.console.ext.QueryResultImpl;
import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.type.Type;
import bsh.EvalError;
@@ -38,15 +42,23 @@
*/
public class QueryExecutor {
- public static QueryResult executeHQLQuery(Session session, String hql,
- QueryInputModel queryParameters) {
+ public static QueryResult executeHQLQuery(HibernateExtension hibernateExtension, Session
session, String hql,
+ final QueryInputModel queryParameters) {
- Query query = session.createQuery(hql);
+ final Query query = session.createQuery(hql);
List<Object> list = Collections.emptyList();
long queryTime = 0;
list = new ArrayList<Object>();
- setupParameters(query, queryParameters);
+ hibernateExtension.execute(new Command() {
+
+ @Override
+ public Object execute() {
+ setupParameters(query, queryParameters);
+ return null;
+ }
+ });
+
long startTime = System.currentTimeMillis();
QueryResultImpl result = new QueryResultImpl(list,
queryTime);
@@ -155,22 +167,36 @@
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 ), parameter.getType());
+ 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),
parameter.getType());
+ query2.setParameterList(parameter.getName(), Arrays.asList(values),
convertToType(typeName));
} else {
- query2.setParameter(parameter.getName(), calcValue( parameter ),
parameter.getType());
+ 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();
}