Author: steve.ebersole(a)jboss.com
Date: 2006-11-16 11:56:35 -0500 (Thu, 16 Nov 2006)
New Revision: 10820
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java
Log:
general cleanup
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2006-11-16
05:12:20 UTC (rev 10819)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2006-11-16
16:56:35 UTC (rev 10820)
@@ -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) {
Show replies by date