Author: dgeraskov
Date: 2011-10-07 04:07:08 -0400 (Fri, 07 Oct 2011)
New Revision: 35464
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
Log:
Execute Criteria Query
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -327,12 +327,17 @@
public QueryPage executeBSHQuery(final String queryString, final QueryInputModel model)
{
return (QueryPage)execute(new Command() {
public Object execute() {
- Session session = getSessionFactory().openSession();
+ /*Session session = getSessionFactory().openSession();
QueryPage qp = new JavaPage(ConsoleConfiguration.this,queryString,model);
qp.setSession(session);
qp.setId(++execcount);
fireQueryPageCreated(qp);
+ return qp;*/
+
+ QueryPage qp = new
org.hibernate.console.ext.JavaPage(ConsoleConfiguration.this,queryString,model);
+ qp.setId(++execcount);
+ fireQueryPageCreated(qp);
return qp;
}
});
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -43,21 +43,24 @@
private void updateQueryResults(){
try {
list = new ArrayList<Object>();
- long startTime = System.currentTimeMillis();
queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
.executeHQLQuery(queryString, model);
- Iterator<?> iter = queryResult.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);
+ 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 (Exception e : queryResult.getExceptions()) {
+ addException(e);
+ }
}
- pcs.firePropertyChange("list", null, list); //$NON-NLS-1$
} catch (HibernateException e) {
- list = Collections.emptyList();
addException(e);
} catch (IllegalArgumentException e) {
- list = Collections.emptyList();
addException(e);
}
}
@@ -90,6 +93,7 @@
public void setQueryString(String queryString) {
this.queryString = queryString;
list = null;
+ queryResult = null;
}
}
\ No newline at end of file
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -28,7 +28,7 @@
public boolean closeSessionFactory();
public boolean reset();
-
+ //TODO do we really need this?
public String getHibernateVersion();
public QueryResult executeHQLQuery(final String hql, final QueryInputModel
queryParameters);
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -14,20 +14,13 @@
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.ConsoleConfiguration;
-import org.hibernate.console.ConsoleMessages;
import org.hibernate.console.QueryInputModel;
-import org.hibernate.engine.SessionImplementor;
-import bsh.EvalError;
-import bsh.Interpreter;
-
/**
* @author Dmitry Geraskov
*
@@ -37,10 +30,6 @@
private String criteriaCode;
private QueryResult queryResult;
- Criteria criteria = null;
-
- private Interpreter ip;
-
/**
* @param model
* @param session2
@@ -51,92 +40,42 @@
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.
- StringBuilder imports = new StringBuilder(35*(2+map.size()));
- while (iterator.hasNext() ) {
- String element = iterator.next();
- imports.append("import ").append(element).append(";\n");
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- imports.append("import org.hibernate.criterion.*;\n"); //$NON-NLS-1$
- imports.append("import org.hibernate.*;\n"); //$NON-NLS-1$
- // TODO: expose the parameters as values to be used in the code.
- interpreter.eval(imports.toString());
-
- return interpreter;
- }
-
- public List<Object> getList() {
+ public List<Object> getList() {
if (criteriaCode==null) return Collections.emptyList();
if (list == null) {
- try {
- list = new ArrayList<Object>();
- long startTime = System.currentTimeMillis();
- queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
- .executeCriteriaQuery(criteriaCode, model);
+ updateQueryResults();
+ }
+ return list;
+ }
+
+ private void updateQueryResults(){
+ try {
+ list = new ArrayList<Object>();
+ queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
+ .executeCriteriaQuery(criteriaCode, model);
+ if (!queryResult.hasExceptions()){
Iterator<?> iter = queryResult.list().iterator(); // need to be
user-controllable to toggle between iterate, scroll etc.
- queryTime = System.currentTimeMillis() - startTime;
+ queryTime = queryResult.getQueryTime();
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);
+ } else {
+ for (Exception e : queryResult.getExceptions()) {
+ addException(e);
+ }
}
+ } catch (HibernateException e) {
+ addException(e);
+ } catch (IllegalArgumentException e) {
+ addException(e);
}
- return list;
}
+
+ public void release() {
+ //session is not set, nothing to release
+ }
public List<String> getPathNames() {
try {
@@ -146,13 +85,21 @@
}
return null;
}
+
+ public void setSession(Session s) {
+ //do nothing
+ }
+
public String getQueryString() {
return criteriaCode;
}
- public void setQueryString(String queryString) {
- this.criteriaCode = queryString;
+
+ @Override
+ public void setQueryString(String criteriaCode) {
+ this.criteriaCode = criteriaCode;
list = null;
- ip = null;
+ queryResult = null;
}
+
}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResult.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -21,5 +21,13 @@
public List<Object> list();
public List<String> getPathNames();
+
+ public long getQueryTime();
+
+ public boolean hasExceptions();
+
+ public List<Exception> getExceptions();
+ public void setPathNames(List<String> pathNames);
+
}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2011-10-07
08:06:58 UTC (rev 35463)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/QueryResultImpl.java 2011-10-07
08:07:08 UTC (rev 35464)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.console.ext;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -19,12 +20,14 @@
*/
public class QueryResultImpl implements QueryResult {
- private List<Object> list;
+ private List<Object> list = new ArrayList<Object>();;
private List<String> pathNames = Collections.emptyList();
private long execTime;
+ private List<Exception> exceptions = new ArrayList<Exception>();
+
public QueryResultImpl(List<Object> list, long execTime){
this.list = list;
this.execTime = execTime;
@@ -34,6 +37,10 @@
this(list, execTime);
this.pathNames = pathNames;
}
+
+ public QueryResultImpl(Exception e){
+ exceptions.add(e);
+ }
@Override
public List<Object> list() {
@@ -44,9 +51,32 @@
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(Exception e){
+ exceptions.add(e);
+ }
+
+ public List<Exception> getExceptions(){
+ return this.exceptions;
+ }
+
+ @Override
+ public boolean hasExceptions() {
+ return getExceptions().size() > 0;
+ }
+
}