[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console ...

Max Rydahl Andersen mandersen at jboss.com
Fri Oct 27 09:35:27 EDT 2006


  User: mandersen
  Date: 06/10/27 09:35:27

  Modified:    hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console     
                        JavaPage.java HQLQueryPage.java
                        KnownConfigurations.java QueryInputModel.java
                        ConsoleConfiguration.java
  Log:
  HBX-792 exposing setMaxResult in UI
  
  Revision  Changes    Path
  1.6       +11 -3     jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JavaPage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/JavaPage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- JavaPage.java	10 Aug 2006 07:01:44 -0000	1.5
  +++ JavaPage.java	27 Oct 2006 13:35:27 -0000	1.6
  @@ -42,20 +42,22 @@
    */
   public class JavaPage extends AbstractQueryPage {
   
  -    
       private String criteriaCode;    
   
       Criteria criteria = null;
   
       private Interpreter ip;
   
  +	private QueryInputModel model;
  +
       /**
  -     * @param queryParameters 
  +     * @param model 
        * @param session2
        */
  -    public JavaPage(ConsoleConfiguration cfg, String criteriaCode, ConsoleQueryParameter[] queryParameters) {
  +    public JavaPage(ConsoleConfiguration cfg, String criteriaCode, QueryInputModel model) {
   		super(cfg);
           this.criteriaCode =  criteriaCode;
  +        this.model = model;
       }
   
       public void setSession(Session s) {
  @@ -71,8 +73,14 @@
               // 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) o;
  +                if(model.getMaxResults()!=null) {
  +                	list = list.subList( 0, Math.min( list.size(), model.getMaxResults().intValue() ) );
  +                }
               } else {
                   list = new ArrayList();
                   list.add(o);   
  
  
  
  1.9       +32 -11    jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HQLQueryPage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/HQLQueryPage.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- HQLQueryPage.java	21 Jul 2006 12:42:04 -0000	1.8
  +++ HQLQueryPage.java	27 Oct 2006 13:35:27 -0000	1.9
  @@ -36,7 +36,8 @@
   
   	private Query query;
   	private String queryString;
  -	private final ConsoleQueryParameter[] queryParameters;
  +	private QueryInputModel model;
  +	
   	public List getList() {
   		if (query==null) return Collections.EMPTY_LIST;
   		if (list == null) {
  @@ -44,7 +45,7 @@
   				
   				//list = query.list();
   				list = new ArrayList();
  -				setupParameters(query, queryParameters);
  +				setupParameters(query, model);
   				Iterator iter = query.list().iterator(); // need to be user-controllable to toggle between iterate, scroll etc.
   				while (iter.hasNext() ) {
   					Object element = iter.next();
  @@ -63,9 +64,15 @@
   		return list;
   	}
   
  -	private void setupParameters(Query query2, ConsoleQueryParameter[] queryParameters2) {
  -		for (int i = 0; i < queryParameters2.length; i++) {
  -			ConsoleQueryParameter parameter = queryParameters2[i];
  +	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());
   				query2.setParameter(pos, calcValue( parameter ), parameter.getType());
  @@ -84,10 +91,10 @@
   	 * @param string
   	 * @param queryParameters 
   	 */
  -	public HQLQueryPage(ConsoleConfiguration cfg, String string, ConsoleQueryParameter[] queryParameters) {
  +	public HQLQueryPage(ConsoleConfiguration cfg, String string, QueryInputModel model) {
   		super(cfg);
   		queryString = string;
  -		this.queryParameters = queryParameters;
  +		this.model = model;
   	}
   
   	public void setSession(Session s) {
  @@ -96,6 +103,8 @@
   			query = this.getSession().createQuery(queryString);
   		} catch (HibernateException e) {
   			addException(e);			
  +		} catch (Exception e) {
  +			addException( e );
   		}
   	}
   	
  @@ -111,8 +120,20 @@
       
       	try {
       		if(query==null) return l;
  -    		if(query.getReturnAliases()==null) {
  -    		Type[] t = query.getReturnTypes();
  +    		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(t.length);
       
       		for (int i = 0; i < t.length; i++) {
  @@ -124,7 +145,7 @@
       			}
       		}
       		} else {
  -    			String[] t = query.getReturnAliases();
  +    			String[] t = returnAliases;
           		l = new ArrayList(t.length);
           
           		for (int i = 0; i < t.length; i++) {
  
  
  
  1.7       +1 -0      jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: KnownConfigurations.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- KnownConfigurations.java	7 Jul 2006 13:50:57 -0000	1.6
  +++ KnownConfigurations.java	27 Oct 2006 13:35:27 -0000	1.7
  @@ -222,6 +222,7 @@
   
   	public ConsoleConfiguration find(String lastUsedName) {
   		if(configurations==null) return null;
  +		if(lastUsedName==null) return null;
   		return (ConsoleConfiguration) configurations.get(lastUsedName);
   	}
   	
  
  
  
  1.5       +22 -0     jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryInputModel.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: QueryInputModel.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/QueryInputModel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- QueryInputModel.java	7 Jul 2006 13:50:57 -0000	1.4
  +++ QueryInputModel.java	27 Oct 2006 13:35:27 -0000	1.5
  @@ -22,6 +22,7 @@
   package org.hibernate.console;
   
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
  @@ -43,6 +44,8 @@
   	List parameters;
   	boolean ignoreParameters = false;
   	
  +	private Integer maxResults;
  +	
   	public QueryInputModel() {
   		parameters = new ArrayList();
   	}
  @@ -69,6 +72,18 @@
   		return result;
   	}
   
  +	public QueryInputModel getCopyForQuery() {
  +		QueryInputModel result = new QueryInputModel();
  +		
  +		ConsoleQueryParameter[] queryParametersForQuery = getQueryParametersForQuery();
  +		result.parameters = Arrays.asList( queryParametersForQuery );
  +	
  +		result.maxResults = getMaxResults();
  +		result.ignoreParameters = ignoreParameters;
  +		
  +		return result;
  +	}
  +
   	public void addParameter(ConsoleQueryParameter cqp) {
   		parameters.add(cqp);
   		setChanged();
  @@ -149,4 +164,11 @@
   		notifyObservers("clear");		
   	}
   
  +	public void setMaxResults(Integer maxResults) {
  +		this.maxResults = maxResults;		
  +	}
  +
  +	public Integer getMaxResults() {
  +		return maxResults;
  +	}
   }
  
  
  
  1.11      +4 -4      jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConsoleConfiguration.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- ConsoleConfiguration.java	7 Jul 2006 13:50:57 -0000	1.10
  +++ ConsoleConfiguration.java	27 Oct 2006 13:35:27 -0000	1.11
  @@ -296,10 +296,10 @@
   	List consoleCfgListeners = new ArrayList();
   		
   	public QueryPage executeHQLQuery(final String hql) {
  -		return executeHQLQuery(hql, new ConsoleQueryParameter[0]);
  +		return executeHQLQuery(hql, new QueryInputModel());
   	}
   	
  -	public QueryPage executeHQLQuery(final String hql, final ConsoleQueryParameter[] queryParameters) {
  +	public QueryPage executeHQLQuery(final String hql, final QueryInputModel queryParameters) {
   		
   		return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
   			
  @@ -316,12 +316,12 @@
   		});		
   	}
   	
  -	public QueryPage executeBSHQuery(final String queryString, final ConsoleQueryParameter[] queryParameters) {
  +	public QueryPage executeBSHQuery(final String queryString, final QueryInputModel model) {
   		return (QueryPage) executionContext.execute(new ExecutionContext.Command() {
   			
   			public Object execute() {
   				Session session = getSessionFactory().openSession();
  -				QueryPage qp = new JavaPage(ConsoleConfiguration.this,queryString,queryParameters);
  +				QueryPage qp = new JavaPage(ConsoleConfiguration.this,queryString,model);
   				qp.setSession(session);
   				
   				qp.setId(++execcount);				
  
  
  



More information about the jboss-cvs-commits mailing list