[hibernate-commits] Hibernate SVN: r10821 - trunk/Hibernate3/src/org/hibernate/hql/ast/util

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Nov 16 11:56:50 EST 2006


Author: steve.ebersole at jboss.com
Date: 2006-11-16 11:56:49 -0500 (Thu, 16 Nov 2006)
New Revision: 10821

Modified:
   trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java
Log:
general cleanup

Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java	2006-11-16 16:56:35 UTC (rev 10820)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java	2006-11-16 16:56:49 UTC (rev 10821)
@@ -29,11 +29,13 @@
 import antlr.collections.AST;
 
 /**
- * Wraps SessionFactoryImpl, adding more lookup behaviors and encapsulating some of the error handling.
+ * Helper for performing common and/or complex operations with the
+ * {@link SessionFactoryImplementor} during translation of an HQL query.
  *
- * @author josh Jul 24, 2004 6:44:00 PM
+ * @author Joshua Davis
  */
 public class SessionFactoryHelper {
+
 	private SessionFactoryImplementor sfi;
 	private Map collectionPropertyMappingByRole;
 
@@ -92,18 +94,18 @@
 	 * @return The defined persister for this class, or null if none found.
 	 */
 	public Queryable findQueryableUsingImports(String className) {
-		return SessionFactoryHelper.findQueryableUsingImports(sfi,className);
+		return findQueryableUsingImports( sfi, className );
 	}
 
 
 	/**
-	 * Given a (potentially unqualified) class name, locate its persister. (static version)
+	 * Given a (potentially unqualified) class name, locate its persister.
+	 *
 	 * @param sfi The session factory implementor.
 	 * @param className The (potentially unqualified) class name.
 	 * @return The defined persister for this class, or null if none found.
 	 */
-	public static Queryable findQueryableUsingImports(SessionFactoryImplementor sfi,String className)
-	{
+	public static Queryable findQueryableUsingImports(SessionFactoryImplementor sfi, String className) {
 		final String importedClassName = sfi.getImportedClassName( className );
 		if ( importedClassName == null ) {
 			return null;
@@ -124,7 +126,7 @@
 	 * @throws MappingException
 	 */
 	private EntityPersister findEntityPersisterByName(String name) throws MappingException {
-		// First, try to get the persister using the class name directly.
+		// First, try to get the persister using the given name directly.
 		try {
 			return sfi.getEntityPersister( name );
 		}
@@ -153,8 +155,6 @@
 		try {
 			cp = findEntityPersisterByName( name );
 			if ( cp == null ) {
-//				throw new SemanticException( name + " is not mapped." );
-//				throw new QuerySyntaxException( new SemanticException( name + " is not mapped." ) );
 				throw new QuerySyntaxException( name + " is not mapped" );
 			}
 		}
@@ -365,15 +365,26 @@
 	 * @return the function return type given the function name and the first argument expression node.
 	 */
 	public Type findFunctionReturnType(String functionName, AST first) {
+		// locate the registered function by the given name
+		SQLFunction sqlFunction = requireSQLFunction( functionName );
+
+		// determine the type of the first argument...
 		Type argumentType = null;
-		if ( "cast".equals(functionName) ) {
-			argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() );
+		if ( first != null ) {
+			if ( "cast".equals(functionName) ) {
+				argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() );
+			}
+			else if ( first instanceof SqlNode ) {
+				argumentType = ( (SqlNode) first ).getDataType();
+			}
 		}
-		else if ( first != null && first instanceof SqlNode ) {
-			argumentType = ( (SqlNode) first ).getDataType();
+
+		Type rtnType = sqlFunction.getReturnType( argumentType, sfi );
+		if ( rtnType == null ) {
+			throw new QueryException( "unable to determine function return type [" + functionName + "]" );
 		}
-		// This implementation is a bit strange, but then that's why this helper exists.
-		return requireSQLFunction( functionName ).getReturnType( argumentType, sfi );
+
+		return rtnType;
 	}
 
 	public String[][] generateColumnNames(Type[] sqlResultTypes) {




More information about the hibernate-commits mailing list