[jbosstools-commits] JBoss Tools SVN: r39892 - in trunk/hibernatetools/plugins: org.hibernate.eclipse/src/org/hibernate/console/ext and 18 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Mar 28 11:06:46 EDT 2012


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



More information about the jbosstools-commits mailing list