From: <hib...@li...> - 2006-06-02 19:47:54
|
Author: epbernard Date: 2006-06-02 15:47:51 -0400 (Fri, 02 Jun 2006) New Revision: 9982 Added: trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java Log: EJB-191 specialize exception when expected query operation does not match the called API Added: trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java 2006-06-02 19:16:45 UTC (rev 9981) +++ trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java 2006-06-02 19:47:51 UTC (rev 9982) @@ -0,0 +1,16 @@ +//$Id: $ +package org.hibernate.hql; + +import org.hibernate.QueryException; + +/** + * Expecting to execute an illegal operation regarding the query type + * + * @author Emmanuel Bernard + */ +public class QueryExecutionRequestException extends QueryException { + + public QueryExecutionRequestException(String message, String queryString) { + super( message, queryString ); + } +} Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-02 19:16:45 UTC (rev 9981) +++ trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-02 19:47:51 UTC (rev 9982) @@ -1,6 +1,13 @@ // $Id$ package org.hibernate.hql.ast; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + import antlr.ANTLRException; import antlr.RecognitionException; import antlr.TokenStreamException; @@ -11,13 +18,14 @@ import org.hibernate.MappingException; import org.hibernate.QueryException; import org.hibernate.ScrollableResults; -import org.hibernate.hql.ParameterTranslations; import org.hibernate.engine.QueryParameters; +import org.hibernate.engine.RowSelection; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionImplementor; -import org.hibernate.engine.RowSelection; import org.hibernate.event.EventSource; import org.hibernate.hql.FilterTranslator; +import org.hibernate.hql.QueryExecutionRequestException; +import org.hibernate.hql.ParameterTranslations; import org.hibernate.hql.antlr.HqlSqlTokenTypes; import org.hibernate.hql.antlr.HqlTokenTypes; import org.hibernate.hql.antlr.SqlTokenTypes; @@ -33,16 +41,9 @@ import org.hibernate.loader.hql.QueryLoader; import org.hibernate.persister.entity.Queryable; import org.hibernate.type.Type; +import org.hibernate.util.IdentitySet; import org.hibernate.util.StringHelper; -import org.hibernate.util.IdentitySet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.ArrayList; - /** * A QueryTranslator that uses an AST based parser. * <br>User: josh @@ -264,13 +265,13 @@ private void errorIfDML() throws HibernateException { if ( sqlAst.needsExecutor() ) { - throw new HibernateException( "Not supported for DML operations" ); + throw new QueryExecutionRequestException( "Not supported for DML operations", hql ); } } private void errorIfSelect() throws HibernateException { if ( !sqlAst.needsExecutor() ) { - throw new HibernateException( "Not supported for select queries" ); + throw new QueryExecutionRequestException( "Not supported for select queries", hql ); } } Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 19:16:45 UTC (rev 9981) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 19:47:51 UTC (rev 9982) @@ -15,8 +15,10 @@ import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.HibernateException; +import org.hibernate.QueryParameterException; import org.hibernate.SQLQuery; -import org.hibernate.QueryParameterException; +import org.hibernate.TypeMismatchException; +import org.hibernate.hql.QueryExecutionRequestException; /** * @author <a href="mailto:ga...@hi...">Gavin King</a> @@ -43,28 +45,32 @@ } return query.executeUpdate(); } + catch (QueryExecutionRequestException he) { + throw new IllegalStateException(he); + } + catch( TypeMismatchException e ) { + throw new IllegalArgumentException(e); + } catch (HibernateException he) { em.throwPersistenceException( he ); return 0; } - catch( ClassCastException cce ) { - //TODO fix that when the TypeMismatchException is used by the core - throw new IllegalArgumentException(cce); - } } public List getResultList() { try { return query.list(); } + catch (QueryExecutionRequestException he) { + throw new IllegalStateException(he); + } + catch( TypeMismatchException e ) { + throw new IllegalArgumentException(e); + } catch (HibernateException he) { em.throwPersistenceException( he ); return null; } - catch( ClassCastException cce ) { - //TODO fix that when the TypeMismatchException is used by the core - throw new IllegalArgumentException(cce); - } } public Object getSingleResult() { @@ -77,14 +83,16 @@ return result; } + catch (QueryExecutionRequestException he) { + throw new IllegalStateException(he); + } + catch( TypeMismatchException e ) { + throw new IllegalArgumentException(e); + } catch (HibernateException he) { em.throwPersistenceException( he ); return null; } - catch( ClassCastException cce ) { - //TODO fix that when the TypeMismatchException is used by the core - throw new IllegalArgumentException(cce); - } } public Query setMaxResults(int maxResult) { |