Author: max...@jb... Date: 2006-05-08 16:59:20 -0400 (Mon, 08 May 2006) New Revision: 9908 Added: trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicAvgFunction.java trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicCountFunction.java trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicSumFunction.java trunk/Hibernate3/src/org/hibernate/dialect/function/SQLFunctionRegistry.java Modified: trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java trunk/Hibernate3/src/org/hibernate/criterion/AggregateProjection.java trunk/Hibernate3/src/org/hibernate/criterion/AvgProjection.java trunk/Hibernate3/src/org/hibernate/criterion/CountProjection.java trunk/Hibernate3/src/org/hibernate/criterion/RowCountProjection.java trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java trunk/Hibernate3/src/org/hibernate/engine/SessionFactoryImplementor.java trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java trunk/Hibernate3/src/org/hibernate/hql/classic/SelectParser.java trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java trunk/Hibernate3/src/org/hibernate/mapping/Column.java trunk/Hibernate3/src/org/hibernate/mapping/Formula.java trunk/Hibernate3/src/org/hibernate/mapping/Selectable.java trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java trunk/Hibernate3/src/org/hibernate/persister/entity/SingleTableEntityPersister.java trunk/Hibernate3/src/org/hibernate/sql/Template.java trunk/Hibernate3/src/org/hibernate/util/FilterHelper.java trunk/Hibernate3/test/org/hibernate/test/TestCase.java trunk/Hibernate3/test/org/hibernate/test/criteria/CriteriaQueryTest.java trunk/Hibernate3/test/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java trunk/Hibernate3/test/org/hibernate/test/immutable/ImmutableTest.java trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java trunk/Hibernate3/test/org/hibernate/test/ops/SaveOrUpdateTest.java Log: Revert HHH-1724 Criteria/HQL alignment Fixed HHH-1727 SQLFunctionRegistry instead. Modified: trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/cfg/Configuration.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -39,6 +39,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.MySQLDialect; +import org.hibernate.dialect.function.SQLFunction; import org.hibernate.engine.FilterDefinition; import org.hibernate.engine.Mapping; import org.hibernate.event.AutoFlushEventListener; @@ -121,6 +122,7 @@ protected Map collections; protected Map tables; protected List auxiliaryDatabaseObjects; + protected Map sqlFunctions; protected Map namedQueries; protected Map namedSqlQueries; /** @@ -171,10 +173,13 @@ tableNameBinding = new HashMap(); columnNameBindingPerTable = new HashMap(); namingStrategy = DefaultNamingStrategy.INSTANCE; + sqlFunctions = new HashMap(); } private transient Mapping mapping = buildMapping(); + + protected Configuration(SettingsFactory settingsFactory) { this.settingsFactory = settingsFactory; reset(); @@ -2011,4 +2016,12 @@ public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject object) { auxiliaryDatabaseObjects.add( object ); } + + public Map getSqlFunctions() { + return sqlFunctions; + } + + public void addSqlFunction(String functionName, SQLFunction function) { + sqlFunctions.put( functionName, function ); + } } Modified: trunk/Hibernate3/src/org/hibernate/criterion/AggregateProjection.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/criterion/AggregateProjection.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/criterion/AggregateProjection.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -3,8 +3,6 @@ import org.hibernate.Criteria; import org.hibernate.HibernateException; -import org.hibernate.dialect.function.SQLFunction; -import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.type.Type; /** @@ -27,22 +25,9 @@ public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { - SessionFactoryImplementor factory = criteriaQuery.getFactory(); - Type type = criteriaQuery.getType(criteria, propertyName); - - SQLFunction function = findSQLFunction( factory, aggregate ); - - if(function==null) { - return new Type[] { type }; - } else { - return new Type[] { function.getReturnType( type, factory ) }; - } + return new Type[] { criteriaQuery.getType(criteria, propertyName) }; } - protected SQLFunction findSQLFunction(SessionFactoryImplementor sfi, String functionName) { - return ( SQLFunction ) sfi.getDialect().getFunctions().get( functionName.toLowerCase() ); - } - public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException { return new StringBuffer() Modified: trunk/Hibernate3/src/org/hibernate/criterion/AvgProjection.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/criterion/AvgProjection.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/criterion/AvgProjection.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -1,6 +1,11 @@ //$Id$ package org.hibernate.criterion; +import org.hibernate.Criteria; +import org.hibernate.Hibernate; +import org.hibernate.HibernateException; +import org.hibernate.type.Type; + /** * @author Gavin King */ @@ -8,5 +13,10 @@ public AvgProjection(String propertyName) { super("avg", propertyName); - } + } + + public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) + throws HibernateException { + return new Type[] { Hibernate.DOUBLE }; + } } Modified: trunk/Hibernate3/src/org/hibernate/criterion/CountProjection.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/criterion/CountProjection.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/criterion/CountProjection.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -26,6 +26,11 @@ } } + public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) + throws HibernateException { + return new Type[] { Hibernate.LONG }; + } + public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { StringBuffer buf = new StringBuffer(); Modified: trunk/Hibernate3/src/org/hibernate/criterion/RowCountProjection.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/criterion/RowCountProjection.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/criterion/RowCountProjection.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -4,8 +4,6 @@ import org.hibernate.Criteria; import org.hibernate.Hibernate; import org.hibernate.HibernateException; -import org.hibernate.dialect.function.SQLFunction; -import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.type.Type; /** @@ -22,22 +20,9 @@ public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { - SessionFactoryImplementor factory = criteriaQuery.getFactory(); - - Type type = Hibernate.LONG; - SQLFunction function = findSQLFunction( factory, "count" ); - - if(function==null) { - return new Type[] { type }; - } else { - return new Type[] { function.getReturnType( type, factory ) }; - } + return new Type[] { Hibernate.INTEGER }; } - protected SQLFunction findSQLFunction(SessionFactoryImplementor sfi, String functionName) { - return ( SQLFunction ) sfi.getDialect().getFunctions().get( functionName.toLowerCase() ); - } - public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException { return new StringBuffer() Modified: trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -18,7 +18,6 @@ import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.QueryException; -import org.hibernate.persister.entity.Lockable; import org.hibernate.cfg.Environment; import org.hibernate.dialect.function.CastFunction; import org.hibernate.dialect.function.SQLFunction; @@ -34,6 +33,7 @@ import org.hibernate.id.SequenceGenerator; import org.hibernate.id.TableHiLoGenerator; import org.hibernate.mapping.Column; +import org.hibernate.persister.entity.Lockable; import org.hibernate.sql.ANSICaseFragment; import org.hibernate.sql.ANSIJoinFragment; import org.hibernate.sql.CaseFragment; @@ -61,35 +61,7 @@ static final String NO_BATCH = "0"; private static final Map STANDARD_AGGREGATE_FUNCTIONS = new HashMap(); - - private static SQLFunction classicCount = new StandardSQLFunction("count") { - public Type getReturnType(Type columnType, Mapping mapping) { - return Hibernate.INTEGER; - } - }; - private static SQLFunction classicAvg = new StandardSQLFunction("avg") { - public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { - int[] sqlTypes; - try { - sqlTypes = columnType.sqlTypes( mapping ); - } - catch ( MappingException me ) { - throw new QueryException( me ); - } - if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" ); - int sqlType = sqlTypes[0]; - if ( sqlType == Types.INTEGER || sqlType == Types.BIGINT || sqlType == Types.TINYINT ) { - return Hibernate.FLOAT; - } - else { - return columnType; - } - } - }; - - private static SQLFunction classicSum = new StandardSQLFunction("sum"); - static { STANDARD_AGGREGATE_FUNCTIONS.put( "count", new StandardSQLFunction("count") { public Type getReturnType(Type columnType, Mapping mapping) { @@ -213,16 +185,6 @@ return getClass().getName(); } - /** Registers the pre 3.2 return types for count, avg and sum. - * Call this method in the constructor of your dialect subclass if you need - * the old types for aggregations. - **/ - protected void registerClassicAggregationTypes() { - sqlFunctions.put( "sum", classicSum ); - sqlFunctions.put( "avg", classicAvg ); - sqlFunctions.put( "count", classicCount ); - } - /** * Characters used for quoting SQL identifiers */ Added: trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicAvgFunction.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicAvgFunction.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicAvgFunction.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -0,0 +1,42 @@ +/** + * + */ +package org.hibernate.dialect.function; + +import java.sql.Types; + +import org.hibernate.Hibernate; +import org.hibernate.MappingException; +import org.hibernate.QueryException; +import org.hibernate.engine.Mapping; +import org.hibernate.type.Type; + +/** + * Classic AVG sqlfunction that return types as it was done in Hibernate 3.1 + * + * @author Max Rydahl Andersen + * + */ +public class ClassicAvgFunction extends StandardSQLFunction { + public ClassicAvgFunction() { + super( "avg" ); + } + + public Type getReturnType(Type columnType, Mapping mapping) throws QueryException { + int[] sqlTypes; + try { + sqlTypes = columnType.sqlTypes( mapping ); + } + catch ( MappingException me ) { + throw new QueryException( me ); + } + if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" ); + int sqlType = sqlTypes[0]; + if ( sqlType == Types.INTEGER || sqlType == Types.BIGINT || sqlType == Types.TINYINT ) { + return Hibernate.FLOAT; + } + else { + return columnType; + } + } +} \ No newline at end of file Added: trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicCountFunction.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicCountFunction.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicCountFunction.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -0,0 +1,25 @@ +/** + * + */ +package org.hibernate.dialect.function; + +import org.hibernate.Hibernate; +import org.hibernate.engine.Mapping; +import org.hibernate.type.Type; + + +/** + * Classic COUNT sqlfunction that return types as it was done in Hibernate 3.1 + * + * @author Max Rydahl Andersen + * + */ +public class ClassicCountFunction extends StandardSQLFunction { + public ClassicCountFunction() { + super( "count" ); + } + + public Type getReturnType(Type columnType, Mapping mapping) { + return Hibernate.INTEGER; + } +} \ No newline at end of file Added: trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicSumFunction.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicSumFunction.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/dialect/function/ClassicSumFunction.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -0,0 +1,17 @@ +/** + * + */ +package org.hibernate.dialect.function; + + +/** + * Classic SUM sqlfunction that return types as it was done in Hibernate 3.1 + * + * @author Max Rydahl Andersen + * + */ +public class ClassicSumFunction extends StandardSQLFunction { + public ClassicSumFunction() { + super( "sum" ); + } +} \ No newline at end of file Added: trunk/Hibernate3/src/org/hibernate/dialect/function/SQLFunctionRegistry.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/dialect/function/SQLFunctionRegistry.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/dialect/function/SQLFunctionRegistry.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -0,0 +1,33 @@ +package org.hibernate.dialect.function; + +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.dialect.Dialect; + +public class SQLFunctionRegistry { + + private final Dialect dialect; + private final Map userFunctions; + + public SQLFunctionRegistry(Dialect dialect, Map userFunctions) { + this.dialect = dialect; + this.userFunctions = new HashMap(); + this.userFunctions.putAll( userFunctions ); + } + + public SQLFunction findSQLFunction(String functionName) { + String name = functionName.toLowerCase(); + SQLFunction userFunction = (SQLFunction) userFunctions.get( name ); + + return userFunction!=null?userFunction:(SQLFunction) dialect.getFunctions().get(name); // TODO: lowercasing done here. Was done "at random" before; maybe not needed at all ? + } + + public boolean hasFunction(String functionName) { + String name = functionName.toLowerCase(); + boolean hasUserFunction = userFunctions.containsKey ( name ); + + return hasUserFunction || dialect.getFunctions().containsKey ( name ); // TODO: toLowerCase was not done before. Only used in Template. + } + +} Modified: trunk/Hibernate3/src/org/hibernate/engine/SessionFactoryImplementor.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/engine/SessionFactoryImplementor.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/engine/SessionFactoryImplementor.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -165,5 +165,7 @@ public Set getCollectionRolesByEntityParticipant(String entityName); public EntityNotFoundDelegate getEntityNotFoundDelegate(); + + public SQLFunctionRegistry getSqlFunctionRegistry(); } Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -339,7 +339,7 @@ * @return The sql function, or null if not found. */ public SQLFunction findSQLFunction(String functionName) { - return ( SQLFunction ) sfi.getDialect().getFunctions().get( functionName.toLowerCase() ); + return sfi.getSqlFunctionRegistry().findSQLFunction( functionName.toLowerCase() ); } /** Modified: trunk/Hibernate3/src/org/hibernate/hql/classic/SelectParser.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/hql/classic/SelectParser.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/hql/classic/SelectParser.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -209,7 +209,7 @@ } private SQLFunction getFunction(String name, QueryTranslatorImpl q) { - return ( SQLFunction ) q.getFactory().getDialect().getFunctions().get( name ); + return q.getFactory().getSqlFunctionRegistry().findSQLFunction( name ); } public void start(QueryTranslatorImpl q) { Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -30,35 +30,35 @@ import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.MappingException; +import org.hibernate.ObjectNotFoundException; import org.hibernate.QueryException; import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; -import org.hibernate.ObjectNotFoundException; -import org.hibernate.proxy.EntityNotFoundDelegate; -import org.hibernate.context.CurrentSessionContext; -import org.hibernate.context.ThreadLocalSessionContext; -import org.hibernate.context.JTASessionContext; -import org.hibernate.context.ManagedSessionContext; import org.hibernate.cache.Cache; import org.hibernate.cache.CacheConcurrencyStrategy; import org.hibernate.cache.CacheFactory; import org.hibernate.cache.CacheKey; +import org.hibernate.cache.OptimisticCache; import org.hibernate.cache.QueryCache; import org.hibernate.cache.UpdateTimestampsCache; -import org.hibernate.cache.OptimisticCache; import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; import org.hibernate.cfg.Settings; -import org.hibernate.cfg.Environment; import org.hibernate.connection.ConnectionProvider; +import org.hibernate.context.CurrentSessionContext; +import org.hibernate.context.JTASessionContext; +import org.hibernate.context.ManagedSessionContext; +import org.hibernate.context.ThreadLocalSessionContext; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.engine.FilterDefinition; import org.hibernate.engine.Mapping; import org.hibernate.engine.NamedQueryDefinition; import org.hibernate.engine.NamedSQLQueryDefinition; import org.hibernate.engine.ResultSetMappingDefinition; import org.hibernate.engine.SessionFactoryImplementor; +import org.hibernate.engine.query.NativeSQLQuerySpecification; import org.hibernate.engine.query.QueryPlanCache; -import org.hibernate.engine.query.NativeSQLQuerySpecification; import org.hibernate.event.EventListeners; import org.hibernate.exception.SQLExceptionConverter; import org.hibernate.id.IdentifierGenerator; @@ -74,6 +74,7 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Queryable; import org.hibernate.pretty.MessageHelper; +import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.stat.Statistics; import org.hibernate.stat.StatisticsImpl; import org.hibernate.stat.StatisticsImplementor; @@ -85,7 +86,6 @@ import org.hibernate.type.Type; import org.hibernate.util.CollectionHelper; import org.hibernate.util.ReflectHelper; -import org.hibernate.util.SerializationHelper; /** @@ -140,10 +140,12 @@ private final transient EventListeners eventListeners; private final transient CurrentSessionContext currentSessionContext; private final transient EntityNotFoundDelegate entityNotFoundDelegate; - + private final transient SQLFunctionRegistry sqlFunctionRegistry; + private final QueryPlanCache queryPlanCache = new QueryPlanCache( this ); private transient boolean isClosed = false; + private static final IdentifierGenerator UUID_GENERATOR = new UUIDHexGenerator(); @@ -162,6 +164,7 @@ this.properties.putAll( cfg.getProperties() ); this.interceptor = cfg.getInterceptor(); this.settings = settings; + this.sqlFunctionRegistry = new SQLFunctionRegistry(settings.getDialect(), cfg.getSqlFunctions()); this.eventListeners = listeners; this.filters = new HashMap(); this.filters.putAll( cfg.getFilterDefinitions() ); @@ -1039,4 +1042,8 @@ } return ( SessionFactoryImpl ) result; } + + public SQLFunctionRegistry getSqlFunctionRegistry() { + return sqlFunctionRegistry; + } } Modified: trunk/Hibernate3/src/org/hibernate/mapping/Column.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/mapping/Column.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/mapping/Column.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -6,6 +6,7 @@ import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.engine.Mapping; import org.hibernate.util.StringHelper; @@ -235,7 +236,7 @@ return checkConstraint!=null; } - public String getTemplate(Dialect dialect) { + public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) { return getQuotedName(dialect); } Modified: trunk/Hibernate3/src/org/hibernate/mapping/Formula.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/mapping/Formula.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/mapping/Formula.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -4,6 +4,7 @@ import java.io.Serializable; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.sql.Template; /** @@ -20,8 +21,8 @@ uniqueInteger = formulaUniqueInteger++; } - public String getTemplate(Dialect dialect) { - return Template.renderWhereStringTemplate(formula, dialect); + public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) { + return Template.renderWhereStringTemplate(formula, dialect, functionRegistry); } public String getText(Dialect dialect) { return getFormula(); Modified: trunk/Hibernate3/src/org/hibernate/mapping/Selectable.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/mapping/Selectable.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/mapping/Selectable.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -2,12 +2,13 @@ package org.hibernate.mapping; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; public interface Selectable { public String getAlias(Dialect dialect); public String getAlias(Dialect dialect, Table table); public boolean isFormula(); - public String getTemplate(Dialect dialect); + public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry); public String getText(Dialect dialect); public String getText(); } Modified: trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -241,12 +241,12 @@ sqlOrderByString = collection.getOrderBy(); hasOrder = sqlOrderByString != null; sqlOrderByStringTemplate = hasOrder ? - Template.renderOrderByStringTemplate(sqlOrderByString, dialect) : + Template.renderOrderByStringTemplate(sqlOrderByString, dialect, factory.getSqlFunctionRegistry()) : null; sqlWhereString = collection.getWhere(); hasWhere = sqlWhereString != null; sqlWhereStringTemplate = hasWhere ? - Template.renderWhereStringTemplate(sqlWhereString, dialect) : + Template.renderWhereStringTemplate(sqlWhereString, dialect, factory.getSqlFunctionRegistry()) : null; hasOrphanDelete = collection.hasOrphanDelete(); @@ -310,7 +310,7 @@ elementColumnAliases[j] = selectable.getAlias(dialect); if ( selectable.isFormula() ) { Formula form = (Formula) selectable; - elementFormulaTemplates[j] = form.getTemplate(dialect); + elementFormulaTemplates[j] = form.getTemplate(dialect, factory.getSqlFunctionRegistry()); elementFormulas[j] = form.getFormula(); } else { @@ -356,7 +356,7 @@ indexColumnAliases[i] = s.getAlias(dialect); if ( s.isFormula() ) { Formula indexForm = (Formula) s; - indexFormulaTemplates[i] = indexForm.getTemplate(dialect); + indexFormulaTemplates[i] = indexForm.getTemplate(dialect, factory.getSqlFunctionRegistry()); indexFormulas[i] = indexForm.getFormula(); hasFormula = true; } @@ -497,18 +497,18 @@ } // Handle any filters applied to this collection - filterHelper = new FilterHelper( collection.getFilterMap(), dialect ); + filterHelper = new FilterHelper( collection.getFilterMap(), dialect, factory.getSqlFunctionRegistry() ); // Handle any filters applied to this collection for many-to-many - manyToManyFilterHelper = new FilterHelper( collection.getManyToManyFilterMap(), dialect ); + manyToManyFilterHelper = new FilterHelper( collection.getManyToManyFilterMap(), dialect, factory.getSqlFunctionRegistry() ); manyToManyWhereString = collection.getManyToManyWhere(); manyToManyWhereTemplate = manyToManyWhereString == null ? null : - Template.renderWhereStringTemplate( manyToManyWhereString, factory.getDialect() ); + Template.renderWhereStringTemplate( manyToManyWhereString, factory.getDialect(), factory.getSqlFunctionRegistry() ); manyToManyOrderByString = collection.getManyToManyOrdering(); manyToManyOrderByTemplate = manyToManyOrderByString == null ? null - : Template.renderOrderByStringTemplate( manyToManyOrderByString, factory.getDialect() ); + : Template.renderOrderByStringTemplate( manyToManyOrderByString, factory.getDialect(), factory.getSqlFunctionRegistry() ); initCollectionPropertyMap(); } Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -469,7 +469,7 @@ sqlWhereString = persistentClass.getWhere(); sqlWhereStringTemplate = sqlWhereString == null ? null : - Template.renderWhereStringTemplate( sqlWhereString, factory.getDialect() ); + Template.renderWhereStringTemplate( sqlWhereString, factory.getDialect(), factory.getSqlFunctionRegistry() ); // PROPERTIES @@ -513,10 +513,10 @@ colAliases[k] = thing.getAlias( factory.getDialect() , prop.getValue().getTable() ); if ( thing.isFormula() ) { foundFormula = true; - templates[k] = thing.getTemplate( factory.getDialect() ); + templates[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); } else { - colNames[k] = thing.getTemplate( factory.getDialect() ); + colNames[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); } k++; } @@ -590,7 +590,7 @@ while ( colIter.hasNext() ) { Selectable thing = ( Selectable ) colIter.next(); if ( thing.isFormula() ) { - String template = thing.getTemplate( factory.getDialect() ); + String template = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); formnos[l] = formulaTemplates.size(); colnos[l] = -1; formulaTemplates.add( template ); @@ -600,7 +600,7 @@ formulasLazy.add( lazy ); } else { - String colName = thing.getTemplate( factory.getDialect() ); + String colName = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); colnos[l] = columns.size(); //before add :-) formnos[l] = -1; columns.add( colName ); @@ -659,7 +659,7 @@ } // Handle any filters applied to the class level - filterHelper = new FilterHelper( persistentClass.getFilterMap(), factory.getDialect() ); + filterHelper = new FilterHelper( persistentClass.getFilterMap(), factory.getDialect(), factory.getSqlFunctionRegistry() ); temporaryIdTableName = persistentClass.getTemporaryIdTableName(); temporaryIdTableDDL = persistentClass.getTemporaryIdTableDDL(); @@ -2220,7 +2220,7 @@ final PreparedStatement update; if ( callable ) { CallableStatement callstatement = session.getBatcher().prepareCallableStatement( sql ); - callstatement.registerOutParameter( index++, Types.INTEGER ); // TODO: should we require users to return number of update rows ? + callstatement.registerOutParameter( index++, Types.NUMERIC ); // TODO: should we require users to return number of update rows ? (NUMERIC) update = callstatement; } else if ( useBatch ) { @@ -2267,13 +2267,11 @@ if ( useBatch ) { session.getBatcher().addToBatch( 1 ); return true; - } else if (!callable) { + } + else { return check( update.executeUpdate(), id, j ); - } else { - update.executeUpdate(); - CallableStatement cd = (CallableStatement)update; - return check( cd.getInt(1), id, j); } + } catch ( SQLException sqle ) { if ( useBatch ) { @@ -2338,7 +2336,7 @@ int index = 1; if ( callable ) { CallableStatement callstatement = session.getBatcher().prepareCallableStatement( sql ); - callstatement.registerOutParameter( index++, Types.INTEGER); // TODO: should we require users to return number of deleted rows ? + callstatement.registerOutParameter( index++, Types.NUMERIC ); // TODO: should we require users to return number of deleted rows ? delete = callstatement; } else if ( useBatch ) { @@ -2364,12 +2362,8 @@ if ( useBatch ) { session.getBatcher().addToBatch( 1 ); } - else if(!callable) { + else { check( delete.executeUpdate(), id, j ); - } else { - delete.executeUpdate(); - CallableStatement cd = (CallableStatement)delete; - check( cd.getInt(1), id, j); } } Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/SingleTableEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/SingleTableEntityPersister.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/SingleTableEntityPersister.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -248,7 +248,7 @@ if ( discrimValue.hasFormula() ) { Formula formula = (Formula) selectable; discriminatorFormula = formula.getFormula(); - discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect() ); + discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() ); discriminatorColumnName = null; discriminatorAlias = "clazz_"; } Modified: trunk/Hibernate3/src/org/hibernate/sql/Template.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/sql/Template.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/sql/Template.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -5,6 +5,7 @@ import java.util.StringTokenizer; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.util.StringHelper; /** @@ -66,8 +67,8 @@ private Template() {} - public static String renderWhereStringTemplate(String sqlWhereString, Dialect dialect) { - return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect); + public static String renderWhereStringTemplate(String sqlWhereString, Dialect dialect, SQLFunctionRegistry functionRegistry) { + return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect, functionRegistry); } /** @@ -75,7 +76,7 @@ * Handles subselects, quoted identifiers, quoted strings, expressions, SQL functions, * named parameters. */ - public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) { + public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect, SQLFunctionRegistry functionRegistry ) { //TODO: make this a bit nicer String symbols = new StringBuffer() .append("=><!+-*/()',|&`") @@ -160,7 +161,7 @@ } else if ( isIdentifier(token, dialect) && - !isFunctionOrKeyword(lcToken, nextToken, dialect) + !isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry) ) { result.append(placeholder) .append('.') @@ -193,7 +194,7 @@ * Takes order by clause provided in the mapping attribute and interpolates the alias. * Handles asc, desc, SQL functions, quoted identifiers. */ - public static String renderOrderByStringTemplate(String sqlOrderByString, Dialect dialect) { + public static String renderOrderByStringTemplate(String sqlOrderByString, Dialect dialect, SQLFunctionRegistry functionRegistry) { //TODO: make this a bit nicer String symbols = new StringBuffer() .append("=><!+-*/()',|&`") @@ -263,7 +264,7 @@ } else if ( isIdentifier(token, dialect) && - !isFunctionOrKeyword(lcToken, nextToken, dialect) + !isFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry) ) { result.append(TEMPLATE) .append('.') @@ -280,10 +281,10 @@ return token.startsWith(":"); } - private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect) { + private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) { return "(".equals(nextToken) || KEYWORDS.contains(lcToken) || - dialect.getFunctions().containsKey(lcToken) || + functionRegistry.hasFunction(lcToken) || dialect.getKeywords().contains(lcToken) || FUNCTION_KEYWORDS.contains(lcToken); } Modified: trunk/Hibernate3/src/org/hibernate/util/FilterHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/util/FilterHelper.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/src/org/hibernate/util/FilterHelper.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -4,6 +4,7 @@ import org.hibernate.sql.Template; import org.hibernate.impl.FilterImpl; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.function.SQLFunctionRegistry; import java.util.Map; import java.util.Iterator; @@ -25,8 +26,9 @@ * * @param filters The map of defined filters. * @param dialect The sql dialect + * @param functionRegistry The SQL function registry */ - public FilterHelper(Map filters, Dialect dialect) { + public FilterHelper(Map filters, Dialect dialect, SQLFunctionRegistry functionRegistry) { int filterCount = filters.size(); filterNames = new String[filterCount]; filterConditions = new String[filterCount]; @@ -38,7 +40,8 @@ filterConditions[filterCount] = Template.renderWhereStringTemplate( (String) entry.getValue(), FilterImpl.MARKER, - dialect + dialect, + functionRegistry ); filterConditions[filterCount] = StringHelper.replace( filterConditions[filterCount], ":", Modified: trunk/Hibernate3/test/org/hibernate/test/TestCase.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -68,11 +68,10 @@ cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop"); } - for (int i=0; i<files.length; i++) { - if ( !files[i].startsWith("net/") ) files[i] = getBaseForMappings() + files[i]; - getCfg().addResource( files[i], TestCase.class.getClassLoader() ); - } + Configuration cfg2 = getCfg(); + addMappings( files, cfg2 ); + configure(cfg); if ( getCacheConcurrencyStrategy()!=null ) { @@ -109,7 +108,7 @@ } - setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) ); + setSessions( cfg2.buildSessionFactory( /*new TestInterceptor()*/ ) ); afterSessionFactoryBuilt(); } @@ -119,6 +118,13 @@ } } + protected void addMappings(String[] files, Configuration cfg) { + for (int i=0; i<files.length; i++) { + if ( !files[i].startsWith("net/") ) files[i] = getBaseForMappings() + files[i]; + cfg.addResource( files[i], TestCase.class.getClassLoader() ); + } + } + protected void afterSessionFactoryBuilt() throws Exception { // for subclasses to override in order to perform extra "stuff" only // when SF (re)built... Modified: trunk/Hibernate3/test/org/hibernate/test/criteria/CriteriaQueryTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/criteria/CriteriaQueryTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/criteria/CriteriaQueryTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -319,10 +319,10 @@ //s.flush(); - Long count = (Long) s.createCriteria(Enrolment.class) + Integer count = (Integer) s.createCriteria(Enrolment.class) .setProjection( Projections.count("studentNumber").setDistinct() ) .uniqueResult(); - assertEquals(count, new Long(2)); + assertEquals(count, new Integer(2)); Object object = s.createCriteria(Enrolment.class) .setProjection( Projections.projectionList() @@ -334,7 +334,7 @@ .uniqueResult(); Object[] result = (Object[])object; - assertEquals(new Long(2),result[0]); + assertEquals(new Integer(2),result[0]); assertEquals(new Long(667),result[1]); assertEquals(new Long(101),result[2]); assertEquals( 384.0, ( (Double) result[3] ).doubleValue(), 0.01 ); @@ -493,10 +493,10 @@ s.flush(); - Long count = (Long) s.createCriteria(Enrolment.class) + Integer count = (Integer) s.createCriteria(Enrolment.class) .setProjection( Property.forName("studentNumber").count().setDistinct() ) .uniqueResult(); - assertEquals(count, new Long(2)); + assertEquals(count, new Integer(2)); Object object = s.createCriteria(Enrolment.class) .setProjection( Projections.projectionList() @@ -508,7 +508,7 @@ .uniqueResult(); Object[] result = (Object[])object; - assertEquals(new Long(2),result[0]); + assertEquals(new Integer(2),result[0]); assertEquals(new Long(667),result[1]); assertEquals(new Long(101),result[2]); assertEquals(384.0, ( (Double) result[3] ).doubleValue(), 0.01); Modified: trunk/Hibernate3/test/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/hql/CriteriaHQLAlignmentTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -1,41 +1,23 @@ //$Id: HQLTest.java 9873 2006-05-04 13:42:48Z max...@jb... $ package org.hibernate.test.hql; -import java.io.PrintWriter; -import java.io.StringWriter; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; import junit.framework.Test; import junit.framework.TestSuite; +import org.hibernate.Hibernate; +import org.hibernate.cfg.Configuration; import org.hibernate.classic.Session; import org.hibernate.criterion.Projections; -import org.hibernate.dialect.DB2Dialect; -import org.hibernate.dialect.HSQLDialect; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.Oracle9Dialect; -import org.hibernate.dialect.PostgreSQLDialect; -import org.hibernate.dialect.function.SQLFunction; -import org.hibernate.hql.ast.DetailedSemanticException; -import org.hibernate.hql.ast.QuerySyntaxException; -import org.hibernate.hql.ast.ASTQueryTranslatorFactory; +import org.hibernate.dialect.function.ClassicAvgFunction; +import org.hibernate.dialect.function.ClassicCountFunction; +import org.hibernate.dialect.function.ClassicSumFunction; +import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.hql.ast.QueryTranslatorImpl; -import org.hibernate.hql.ast.tree.ConstructorNode; -import org.hibernate.hql.ast.tree.DotNode; -import org.hibernate.hql.ast.tree.IndexNode; import org.hibernate.hql.ast.tree.SelectClause; -import org.hibernate.hql.QueryTranslatorFactory; -import org.hibernate.hql.QueryTranslator; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.engine.query.HQLQueryPlan; -import org.hibernate.engine.query.ReturnMetadata; -import org.hibernate.Criteria; -import org.hibernate.Hibernate; -import antlr.RecognitionException; - /** * Tests cases for ensuring alignment between HQL and Criteria behavior. * @@ -117,7 +99,8 @@ assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] ); } - public void testCriteriaAggregationReturnType() { + // HHH-1724 Align Criteria with HQL aggregation return types. + public void testCriteriaAggregationReturnTypeFailureExpected() { Session s = openSession(); Human human = new Human(); human.setBigIntegerValue( new BigInteger("42") ); @@ -174,6 +157,72 @@ s.close(); } + public void testClassicTypes() { + Configuration classicCfg = new Configuration(); + classicCfg.addSqlFunction( "count", new ClassicCountFunction()); + classicCfg.addSqlFunction( "avg", new ClassicAvgFunction()); + classicCfg.addSqlFunction( "sum", new ClassicSumFunction()); + + addMappings(getMappings(), classicCfg); + SessionFactoryImplementor factory = (SessionFactoryImplementor) classicCfg.buildSessionFactory(); + + // EJB3: COUNT returns Long + QueryTranslatorImpl translator = createNewQueryTranslator( "select count(*) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select count(h.height) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] ); + + // MAX, MIN return the type of the state-field to which they are applied. + translator = createNewQueryTranslator( "select max(h.height) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select max(h.id) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] ); + + // AVG returns Float integrals, and otherwise the field type. + translator = createNewQueryTranslator( "select avg(h.height) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select avg(h.id) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select avg(h.bigIntegerValue) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] ); + + // SUM returns underlying type sum + translator = createNewQueryTranslator( "select sum(h.id) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select sum(h.intValue) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.INTEGER, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select sum(h.height) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select sum(h.floatValue) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.FLOAT, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select sum(h.bigIntegerValue) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] ); + + translator = createNewQueryTranslator( "select sum(h.bigDecimalValue) from Human h", factory ); + assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); + assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] ); + } + public static Test suite() { return new TestSuite( CriteriaHQLAlignmentTest.class ); } Modified: trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -571,7 +571,7 @@ assertTranslation( "from Animal an where an.bodyWeight > abs(3/5)" ); assertTranslation( "from Animal an where an.bodyWeight > abs(3+5)" ); assertTranslation( "from Animal an where an.bodyWeight > abs(3*5)" ); - SQLFunction concat = (SQLFunction) getDialect().getFunctions().get("concat"); + SQLFunction concat = getSessionFactoryImplementor().getSqlFunctionRegistry().findSQLFunction( "concat"); List list = new ArrayList(); list.add("'fat'"); list.add("'skinny'"); assertTranslation( "from Animal an where an.description = " + concat.render(list, getSessionFactoryImplementor()) ); } Modified: trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -150,6 +150,10 @@ protected QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar) { SessionFactoryImplementor factory = getSessionFactoryImplementor(); + return createNewQueryTranslator( hql, replacements, scalar, factory ); + } + + private QueryTranslatorImpl createNewQueryTranslator(String hql, HashMap replacements, boolean scalar, SessionFactoryImplementor factory) { QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory ); newQueryTranslator.compile( replacements, scalar ); @@ -160,6 +164,10 @@ return createNewQueryTranslator( hql, new HashMap(), false ); } + protected QueryTranslatorImpl createNewQueryTranslator(String hql, SessionFactoryImplementor sfimpl) { + return createNewQueryTranslator( hql, new HashMap(), false, sfimpl ); + } + protected HQLQueryPlan createQueryPlan(String hql, boolean scalar) { return new HQLQueryPlan( hql, scalar, Collections.EMPTY_MAP, getSessionFactoryImplementor() ); } Modified: trunk/Hibernate3/test/org/hibernate/test/immutable/ImmutableTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/immutable/ImmutableTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/immutable/ImmutableTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -44,8 +44,8 @@ cv1 = (ContractVariation) c.getVariations().iterator().next(); assertEquals( cv1.getText(), "expensive" ); s.delete(c); - assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) ); - assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Long(0) ); + assertEquals( s.createCriteria(Contract.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); + assertEquals( s.createCriteria(ContractVariation.class).setProjection( Projections.rowCount() ).uniqueResult(), new Integer(0) ); t.commit(); s.close(); } Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/legacy/SQLFunctionsTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -29,6 +29,7 @@ import org.hibernate.dialect.SybaseDialect; import org.hibernate.dialect.TimesTenDialect; import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.engine.SessionFactoryImplementor; public class SQLFunctionsTest extends LegacyTestCase { Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -262,7 +262,7 @@ s.createCriteria(NumberedNode.class) .setProjection( Projections.rowCount() ) .uniqueResult(), - new Long(2) + new Integer(2) ); s.delete(root); s.delete(mergedChild); Modified: trunk/Hibernate3/test/org/hibernate/test/ops/SaveOrUpdateTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/ops/SaveOrUpdateTest.java 2006-05-08 17:41:21 UTC (rev 9907) +++ trunk/Hibernate3/test/org/hibernate/test/ops/SaveOrUpdateTest.java 2006-05-08 20:59:20 UTC (rev 9908) @@ -242,7 +242,7 @@ s.createCriteria( NumberedNode.class ) .setProjection( Projections.rowCount() ) .uniqueResult(), - new Long( 2 ) + new Integer( 2 ) ); s.delete( root ); s.delete( child ); @@ -299,7 +299,7 @@ s.createCriteria( NumberedNode.class ) .setProjection( Projections.rowCount() ) .uniqueResult(), - new Long( 2 ) + new Integer( 2 ) ); s.delete( root ); s.delete( child ); @@ -353,7 +353,7 @@ s.createCriteria( Node.class ) .setProjection( Projections.rowCount() ) .uniqueResult(), - new Long( 2 ) + new Integer( 2 ) ); s.delete( root ); s.delete( child ); |