Hibernate SVN: r20103 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-08-03 08:23:30 -0400 (Tue, 03 Aug 2010)
New Revision: 20103
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
Log:
HHH-5355 org.hibernate.test.id.uuid.sqlrep.sqlchar.UUIDCharTest errors with IngresDialect
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-08-03 12:19:59 UTC (rev 20102)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-08-03 12:23:30 UTC (rev 20103)
@@ -65,7 +65,7 @@
registerColumnType( Types.VARBINARY, 32000, "varbyte($l)" );
registerColumnType( Types.VARBINARY, "long byte" );
registerColumnType( Types.LONGVARBINARY, "long byte" );
- registerColumnType( Types.CHAR, "char(1)" );
+ registerColumnType( Types.CHAR, 32000, "char($l)" );
registerColumnType( Types.VARCHAR, 32000, "varchar($l)" );
registerColumnType( Types.VARCHAR, "long varchar" );
registerColumnType( Types.LONGVARCHAR, "long varchar" );
@@ -160,8 +160,13 @@
// substitions of true and false.
getDefaultProperties().setProperty(Environment.QUERY_SUBSTITUTIONS, "true=1,false=0");
}
-
/**
+ * Expression for created UUID string
+ */
+ public String getSelectGUIDString() {
+ return "select uuid_to_char(uuid_create())";
+ }
+ /**
* Do we need to drop constraints before dropping tables in this dialect?
*
* @return boolean
14 years, 1 month
Hibernate SVN: r20102 - core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-08-03 08:19:59 -0400 (Tue, 03 Aug 2010)
New Revision: 20102
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/IngresDialect.java
Log:
HHH-5355 org.hibernate.test.id.uuid.sqlrep.sqlchar.UUIDCharTest errors with IngresDialect
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/IngresDialect.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-08-03 11:27:30 UTC (rev 20101)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2010-08-03 12:19:59 UTC (rev 20102)
@@ -65,7 +65,7 @@
registerColumnType( Types.VARBINARY, 32000, "varbyte($l)" );
registerColumnType( Types.VARBINARY, "long byte" );
registerColumnType( Types.LONGVARBINARY, "long byte" );
- registerColumnType( Types.CHAR, "char(1)" );
+ registerColumnType( Types.CHAR, 32000, "char($l)" );
registerColumnType( Types.VARCHAR, 32000, "varchar($l)" );
registerColumnType( Types.VARCHAR, "long varchar" );
registerColumnType( Types.LONGVARCHAR, "long varchar" );
@@ -160,8 +160,14 @@
// substitions of true and false.
getDefaultProperties().setProperty(Environment.QUERY_SUBSTITUTIONS, "true=1,false=0");
}
-
+
/**
+ * Expression for created UUID string
+ */
+ public String getSelectGUIDString() {
+ return "select uuid_to_char(uuid_create())";
+ }
+ /**
* Do we need to drop constraints before dropping tables in this dialect?
*
* @return boolean
14 years, 1 month
Hibernate SVN: r20101 - core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util.
by hibernate-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2010-08-03 07:27:30 -0400 (Tue, 03 Aug 2010)
New Revision: 20101
Modified:
core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java
Log:
[HHH-5431] (Infinispan's CacheAdapterImpl.putAllowingTimeout not using silent flag) Added fail silently flag.
Modified: core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java
===================================================================
--- core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java 2010-08-03 11:27:04 UTC (rev 20100)
+++ core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java 2010-08-03 11:27:30 UTC (rev 20101)
@@ -82,7 +82,7 @@
public Object getAllowingTimeout(Object key) throws CacheException {
try {
- return cache.get(key);
+ return getFailSilentCache().get(key);
} catch (TimeoutException ignored) {
// ignore it
return null;
@@ -101,7 +101,7 @@
public Object putAllowingTimeout(Object key, Object value) throws CacheException {
try {
- return cache.put(key, value);
+ return getFailSilentCache().put(key, value);
} catch (TimeoutException allowed) {
// ignore it
return null;
@@ -202,4 +202,7 @@
return cache.getConfiguration();
}
+ private Cache getFailSilentCache() {
+ return cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY);
+ }
}
14 years, 1 month
Hibernate SVN: r20100 - core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util.
by hibernate-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2010-08-03 07:27:04 -0400 (Tue, 03 Aug 2010)
New Revision: 20100
Modified:
core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java
Log:
[HHH-5431] (Infinispan's CacheAdapterImpl.putAllowingTimeout not using silent flag) Added fail silently flag.
Modified: core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java
===================================================================
--- core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java 2010-08-02 21:58:18 UTC (rev 20099)
+++ core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java 2010-08-03 11:27:04 UTC (rev 20100)
@@ -82,7 +82,7 @@
public Object getAllowingTimeout(Object key) throws CacheException {
try {
- return cache.get(key);
+ return getFailSilentCache().get(key);
} catch (TimeoutException ignored) {
// ignore it
return null;
@@ -101,7 +101,7 @@
public Object putAllowingTimeout(Object key, Object value) throws CacheException {
try {
- return cache.put(key, value);
+ return getFailSilentCache().put(key, value);
} catch (TimeoutException allowed) {
// ignore it
return null;
@@ -202,4 +202,7 @@
return cache.getConfiguration();
}
+ private Cache getFailSilentCache() {
+ return cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY);
+ }
}
14 years, 1 month
Hibernate SVN: r20099 - in core/branches/Branch_3_5: documentation/manual/src/main/docbook/en-US/content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-08-02 17:58:18 -0400 (Mon, 02 Aug 2010)
New Revision: 20099
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java
core/branches/Branch_3_5/documentation/manual/src/main/docbook/en-US/content/configuration.xml
Log:
HHH-5259 Invalid reflection optimization configuration property name in Hibernate documentation (branch 3.5.x)
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java 2010-08-02 21:19:55 UTC (rev 20098)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java 2010-08-02 21:58:18 UTC (rev 20099)
@@ -33,8 +33,8 @@
* Bytecode requirements break down into basically 3 areas<ol>
* <li>proxy generation (both for runtime-lazy-loading and basic proxy generation)
* {@link #getProxyFactoryFactory()}
- * <li>bean relection optimization {@link #getReflectionOptimizer}
- * <li>field-access instumentation {@link #getTransformer}
+ * <li>bean reflection optimization {@link #getReflectionOptimizer}
+ * <li>field-access instrumentation {@link #getTransformer}
* </ol>
*
* @author Steve Ebersole
@@ -44,7 +44,7 @@
* Retrieve the specific factory for this provider capable of
* generating run-time proxies for lazy-loading purposes.
*
- * @return The provider specifc factory.
+ * @return The provider specific factory.
*/
public ProxyFactoryFactory getProxyFactoryFactory();
Modified: core/branches/Branch_3_5/documentation/manual/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/branches/Branch_3_5/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2010-08-02 21:19:55 UTC (rev 20098)
+++ core/branches/Branch_3_5/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2010-08-02 21:58:18 UTC (rev 20099)
@@ -955,7 +955,7 @@
</tgroup>
</table>
- <table frame="topbot" id="configuration-misc-properties" revision="10">
+ <table frame="topbot" id="configuration-misc-properties" revision="11">
<title>Miscellaneous Properties</title>
<tgroup cols="2">
<colspec colname="c1" colwidth="1*"/>
@@ -1028,19 +1028,29 @@
</row>
<row>
<entry>
- <literal>hibernate.cglib.use_reflection_optimizer</literal>
+ <literal>hibernate.bytecode.use_reflection_optimizer</literal>
</entry>
<entry>
- Enables the use of CGLIB instead of runtime reflection (System-level
- property). Reflection can sometimes be useful when troubleshooting.
- Hibernate always requires CGLIB even if you turn off the
- optimizer. You cannot set this property in <literal>hibernate.cfg.xml</literal>.
- <para>
- <emphasis role="strong">e.g.</emphasis>
- <literal>true</literal> | <literal>false</literal>
- </para>
+ <para>Enables the use of bytecode manipulation instead of
+ runtime reflection. This is a System-level property and cannot be set
+ in <literal>hibernate.cfg.xml</literal>.
+ Reflection can sometimes be useful when troubleshooting.
+ Hibernate always requires either CGLIB or javassist even
+ if you turn off the optimizer.</para><para> <emphasis
+ role="strong">e.g.</emphasis> <literal>true</literal> |
+ <literal>false</literal> </para>
</entry>
</row>
+ <row>
+ <entry>
+ <literal>hibernate.bytecode.provider</literal>
+ </entry>
+ <entry><para>Both javassist or cglib can be used as byte manipulation
+ engines; the default is <literal>javassist</literal>.</para><para> <emphasis
+ role="strong">e.g.</emphasis> <literal>javassist</literal> |
+ <literal>cglib</literal> </para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</table>
14 years, 1 month
Hibernate SVN: r20098 - in core/trunk: documentation/manual/src/main/docbook/en-US/content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-08-02 17:19:55 -0400 (Mon, 02 Aug 2010)
New Revision: 20098
Modified:
core/trunk/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java
core/trunk/documentation/manual/src/main/docbook/en-US/content/configuration.xml
Log:
HHH-5259 Invalid reflection optimization configuration property name in Hibernate documentation
Modified: core/trunk/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java 2010-08-02 18:51:45 UTC (rev 20097)
+++ core/trunk/core/src/main/java/org/hibernate/bytecode/BytecodeProvider.java 2010-08-02 21:19:55 UTC (rev 20098)
@@ -33,8 +33,8 @@
* Bytecode requirements break down into basically 3 areas<ol>
* <li>proxy generation (both for runtime-lazy-loading and basic proxy generation)
* {@link #getProxyFactoryFactory()}
- * <li>bean relection optimization {@link #getReflectionOptimizer}
- * <li>field-access instumentation {@link #getTransformer}
+ * <li>bean reflection optimization {@link #getReflectionOptimizer}
+ * <li>field-access instrumentation {@link #getTransformer}
* </ol>
*
* @author Steve Ebersole
@@ -44,7 +44,7 @@
* Retrieve the specific factory for this provider capable of
* generating run-time proxies for lazy-loading purposes.
*
- * @return The provider specifc factory.
+ * @return The provider specific factory.
*/
public ProxyFactoryFactory getProxyFactoryFactory();
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2010-08-02 18:51:45 UTC (rev 20097)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/configuration.xml 2010-08-02 21:19:55 UTC (rev 20098)
@@ -835,7 +835,7 @@
</tgroup>
</table>
- <table frame="topbot" id="configuration-misc-properties" revision="10">
+ <table frame="topbot" id="configuration-misc-properties" revision="11">
<title>Miscellaneous Properties</title>
<tgroup cols="2">
@@ -917,16 +917,26 @@
</row>
<row>
- <entry><literal>hibernate.cglib.use_reflection_optimizer</literal></entry>
-
- <entry>Enables the use of CGLIB instead of runtime reflection
- (System-level property). Reflection can sometimes be useful when
- troubleshooting. Hibernate always requires CGLIB even if you turn
- off the optimizer. You cannot set this property in
- <literal>hibernate.cfg.xml</literal>. <para> <emphasis
+ <entry><literal>hibernate.bytecode.use_reflection_optimizer</literal></entry>
+
+ <entry><para>Enables the use of bytecode manipulation instead of
+ runtime reflection. This is a System-level property and cannot be set
+ in <literal>hibernate.cfg.xml</literal>.
+ Reflection can sometimes be useful when troubleshooting.
+ Hibernate always requires either CGLIB or javassist even
+ if you turn off the optimizer.</para><para> <emphasis
role="strong">e.g.</emphasis> <literal>true</literal> |
<literal>false</literal> </para></entry>
</row>
+
+ <row>
+ <entry><literal>hibernate.bytecode.provider</literal></entry>
+
+ <entry><para>Both javassist or cglib can be used as byte manipulation
+ engines; the default is <literal>javassist</literal>.</para><para> <emphasis
+ role="strong">e.g.</emphasis> <literal>javassist</literal> |
+ <literal>cglib</literal> </para></entry>
+ </row>
</tbody>
</tgroup>
</table>
14 years, 1 month
Hibernate SVN: r20097 - in core/trunk: core/src/main/java/org/hibernate/dialect and 10 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-08-02 14:51:45 -0400 (Mon, 02 Aug 2010)
New Revision: 20097
Added:
core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardAnsiSqlAggregationFunctions.java
Removed:
core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgFunction.java
Modified:
core/trunk/core/src/main/java/org/hibernate/criterion/AggregateProjection.java
core/trunk/core/src/main/java/org/hibernate/criterion/RowCountProjection.java
core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgWithArgumentCastFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/CharIndexFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/ConvertFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/NoArgSQLFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/NvlFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/PositionSubstringFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunctionTemplate.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardJDBCEscapeFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/VarArgsSQLFunction.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/AggregateNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FunctionNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
core/trunk/core/src/main/java/org/hibernate/hql/classic/SelectParser.java
core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/function/AnsiTrimEmulationFunctionTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
Log:
HHH-5212 - Alter SQLFunction contract to be more flexible
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/AggregateProjection.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/AggregateProjection.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/AggregateProjection.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -72,9 +72,9 @@
/**
* {@inheritDoc}
*/
- public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery)
- throws HibernateException {
+ public String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery) throws HibernateException {
final String functionFragment = getFunction( criteriaQuery ).render(
+ criteriaQuery.getType( criteria, getPropertyName() ),
buildFunctionParameterList( criteria, criteriaQuery ),
criteriaQuery.getFactory()
);
Modified: core/trunk/core/src/main/java/org/hibernate/criterion/RowCountProjection.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/criterion/RowCountProjection.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/criterion/RowCountProjection.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.criterion;
@@ -50,7 +49,7 @@
}
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
- return getFunction( criteriaQuery ).render( ARGS, criteriaQuery.getFactory() )
+ return getFunction( criteriaQuery ).render( null, ARGS, criteriaQuery.getFactory() )
+ " as y" + position + '_';
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -32,26 +32,28 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.List;
-import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
-import org.hibernate.MappingException;
-import org.hibernate.QueryException;
import org.hibernate.LockOptions;
+import org.hibernate.MappingException;
import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.function.AvgFunction;
import org.hibernate.dialect.function.CastFunction;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
+import org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions;
import org.hibernate.dialect.function.StandardSQLFunction;
-import org.hibernate.dialect.lock.*;
-import org.hibernate.engine.Mapping;
-import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.dialect.lock.LockingStrategy;
+import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.OptimisticLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticReadSelectLockingStrategy;
+import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy;
+import org.hibernate.dialect.lock.SelectLockingStrategy;
import org.hibernate.exception.SQLExceptionConverter;
import org.hibernate.exception.SQLStateConverter;
import org.hibernate.exception.ViolatedConstraintNameExtracter;
@@ -63,9 +65,8 @@
import org.hibernate.sql.ANSICaseFragment;
import org.hibernate.sql.ANSIJoinFragment;
import org.hibernate.sql.CaseFragment;
-import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.ForUpdateFragment;
-import org.hibernate.type.Type;
+import org.hibernate.sql.JoinFragment;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
@@ -93,110 +94,11 @@
public static final String QUOTE = "`\"[";
public static final String CLOSED_QUOTE = "`\"]";
-
- // build the map of standard ANSI SQL aggregation functions ~~~~~~~~~~~~~~~
-
- private static final Map STANDARD_AGGREGATE_FUNCTIONS = new HashMap();
-
- static {
- STANDARD_AGGREGATE_FUNCTIONS.put(
- "count",
- new StandardSQLFunction("count") {
- public Type getReturnType(Type columnType, Mapping mapping) {
- return Hibernate.LONG;
- }
- public String render(List args, SessionFactoryImplementor factory) {
- if ( args.size() > 1 ) {
- if ( "distinct".equalsIgnoreCase( args.get( 0 ).toString() ) ) {
- return renderCountDistinct( args );
- }
- }
- return super.render( args, factory );
- }
- private String renderCountDistinct(List args) {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "count(distinct " );
- String sep = "";
- Iterator itr = args.iterator();
- itr.next(); // intentionally skip first
- while ( itr.hasNext() ) {
- buffer.append( sep )
- .append( itr.next() );
- sep = ", ";
- }
- return buffer.append( ")" ).toString();
- }
- }
- );
-
- STANDARD_AGGREGATE_FUNCTIONS.put( "avg", new AvgFunction() );
-
- STANDARD_AGGREGATE_FUNCTIONS.put( "max", new StandardSQLFunction("max") );
- STANDARD_AGGREGATE_FUNCTIONS.put( "min", new StandardSQLFunction("min") );
-
- STANDARD_AGGREGATE_FUNCTIONS.put(
- "sum",
- new StandardSQLFunction("sum") {
- public Type getReturnType(Type columnType, Mapping mapping) {
- //pre H3.2 behavior: super.getReturnType(ct, m);
- 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 sum()" );
- }
- int sqlType = sqlTypes[0];
-
- // First allow the actual type to control the return value; the underlying sqltype could
- // actually be different
- if ( columnType == Hibernate.BIG_INTEGER ) {
- return Hibernate.BIG_INTEGER;
- }
- else if ( columnType == Hibernate.BIG_DECIMAL ) {
- return Hibernate.BIG_DECIMAL;
- }
- else if ( columnType == Hibernate.LONG
- || columnType == Hibernate.SHORT
- || columnType == Hibernate.INTEGER ) {
- return Hibernate.LONG;
- }
- else if ( columnType == Hibernate.FLOAT || columnType == Hibernate.DOUBLE) {
- return Hibernate.DOUBLE;
- }
-
- // finally use the sqltype if == on Hibernate types did not find a match.
- if ( sqlType == Types.NUMERIC ) {
- return columnType; //because numeric can be anything
- }
- else if ( sqlType == Types.FLOAT
- || sqlType == Types.DOUBLE
- || sqlType == Types.DECIMAL
- || sqlType == Types.REAL) {
- return Hibernate.DOUBLE;
- }
- else if ( sqlType == Types.BIGINT
- || sqlType == Types.INTEGER
- || sqlType == Types.SMALLINT
- || sqlType == Types.TINYINT ) {
- return Hibernate.LONG;
- }
- else {
- return columnType;
- }
- }
- }
- );
- }
-
private final TypeNames typeNames = new TypeNames();
private final TypeNames hibernateTypeNames = new TypeNames();
private final Properties properties = new Properties();
- private final Map sqlFunctions = new HashMap();
+ private final Map<String, SQLFunction> sqlFunctions = new HashMap<String, SQLFunction>();
private final Set sqlKeywords = new HashSet();
@@ -204,7 +106,7 @@
protected Dialect() {
log.info( "Using dialect: " + this );
- sqlFunctions.putAll( STANDARD_AGGREGATE_FUNCTIONS );
+ StandardAnsiSqlAggregationFunctions.primeFunctionMap( sqlFunctions );
// standard sql92 functions (can be overridden by subclasses)
registerFunction( "substring", new SQLFunctionTemplate( Hibernate.STRING, "substring(?1, ?2, ?3)" ) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/AbstractAnsiTrimEmulationFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -44,13 +44,6 @@
*/
public abstract class AbstractAnsiTrimEmulationFunction implements SQLFunction {
/**
- * {@inheritDoc}
- */
- public final Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
- }
-
- /**
* {@inheritDoc}
*/
public final boolean hasArguments() {
@@ -65,9 +58,16 @@
}
/**
+ * {@inheritDoc}
+ */
+ public final Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ /**
* {@inheritDoc}
*/
- public final String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public final String render(Type argumentType, List args, SessionFactoryImplementor factory) throws QueryException {
// According to both the ANSI-SQL and JPA specs, trim takes a variable number of parameters between 1 and 4.
// at least one paramer (trimSource) is required. From the SQL spec:
//
@@ -87,12 +87,12 @@
if ( args.size() == 1 ) {
// we have the form: trim(trimSource)
// so we trim leading and trailing spaces
- return resolveBothSpaceTrimFunction().render( args, factory ); // EARLY EXIT!!!!
+ return resolveBothSpaceTrimFunction().render( argumentType, args, factory ); // EARLY EXIT!!!!
}
else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
// we have the form: trim(from trimSource).
// This is functionally equivalent to trim(trimSource)
- return resolveBothSpaceTrimFromFunction().render( args, factory ); // EARLY EXIT!!!!
+ return resolveBothSpaceTrimFromFunction().render( argumentType, args, factory ); // EARLY EXIT!!!!
}
else {
// otherwise, a trim-specification and/or a trim-character
@@ -145,24 +145,24 @@
if ( trimCharacter.equals( "' '" ) ) {
if ( leading && trailing ) {
- return resolveBothSpaceTrimFunction().render( argsToUse, factory );
+ return resolveBothSpaceTrimFunction().render( argumentType, argsToUse, factory );
}
else if ( leading ) {
- return resolveLeadingSpaceTrimFunction().render( argsToUse, factory );
+ return resolveLeadingSpaceTrimFunction().render( argumentType, argsToUse, factory );
}
else {
- return resolveTrailingSpaceTrimFunction().render( argsToUse, factory );
+ return resolveTrailingSpaceTrimFunction().render( argumentType, argsToUse, factory );
}
}
else {
if ( leading && trailing ) {
- return resolveBothTrimFunction().render( argsToUse, factory );
+ return resolveBothTrimFunction().render( argumentType, argsToUse, factory );
}
else if ( leading ) {
- return resolveLeadingTrimFunction().render( argsToUse, factory );
+ return resolveLeadingTrimFunction().render( argumentType, argsToUse, factory );
}
else {
- return resolveTrailingTrimFunction().render( argsToUse, factory );
+ return resolveTrailingTrimFunction().render( argumentType, argsToUse, factory );
}
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -26,7 +26,7 @@
import org.hibernate.engine.SessionFactoryImplementor;
/**
- * Defines support for rendering according to ANSI SQL <tt>TRIM<//tt> function specification.
+ * Defines support for rendering according to ANSI SQL <tt>TRIM</tt> function specification.
*
* @author Steve Ebersole
*/
Deleted: core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,71 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.dialect.function;
-
-import java.util.List;
-
-import org.hibernate.MappingException;
-import org.hibernate.QueryException;
-import org.hibernate.engine.Mapping;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.type.DoubleType;
-import org.hibernate.type.Type;
-
-/**
- * The basic JPA spec compliant definition po<tt>AVG</tt> aggregation function.
- *
- * @author Steve Ebersole
- */
-public class AvgFunction implements SQLFunction {
- public final 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( "multiple-column type in avg()" );
- }
- return DoubleType.INSTANCE;
- }
-
- public final boolean hasArguments() {
- return true;
- }
-
- public final boolean hasParenthesesIfNoArguments() {
- return true;
- }
-
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
- return "avg(" + args.get( 0 ) + ")";
- }
-
- @Override
- public final String toString() {
- return "avg";
- }
-}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgWithArgumentCastFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgWithArgumentCastFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/AvgWithArgumentCastFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -23,32 +23,29 @@
*/
package org.hibernate.dialect.function;
-import java.util.List;
+import java.sql.Types;
-import org.hibernate.QueryException;
-import org.hibernate.engine.SessionFactoryImplementor;
-
/**
* Some databases strictly return the type of the of the aggregation value for <tt>AVG</tt> which is
* problematic in the case of averaging integers because the decimals will be dropped. The usual workaround
* is to cast the integer argument as some form of double/decimal.
- * <p/>
- * A downside to this approach is that we always wrap the avg() argument in a cast even though we may not need or want
- * to. A more full-featured solution would be defining {@link SQLFunction} such that we render based on the first
- * argument; essentially have {@link SQLFunction} describe the basic metadata about the function and merge the
- * {@link SQLFunction#getReturnType} and {@link SQLFunction#render} methods into a
*
* @author Steve Ebersole
*/
-public class AvgWithArgumentCastFunction extends AvgFunction {
- private final TemplateRenderer renderer;
+public class AvgWithArgumentCastFunction extends StandardAnsiSqlAggregationFunctions.AvgFunction {
+ private final String castType;
public AvgWithArgumentCastFunction(String castType) {
- renderer = new TemplateRenderer( "avg(cast(?1 as " + castType + "))" );
+ this.castType = castType;
}
@Override
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
- return renderer.render( args, factory );
+ protected String renderArgument(String argument, int firstArgumentJdbcType) {
+ if ( firstArgumentJdbcType == Types.DOUBLE || firstArgumentJdbcType == Types.FLOAT ) {
+ return argument;
+ }
+ else {
+ return "cast(" + argument + " as " + castType + ")";
+ }
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -30,7 +29,6 @@
import org.hibernate.engine.Mapping;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.Type;
-import org.hibernate.type.TypeFactory;
/**
* ANSI-SQL style <tt>cast(foo as type)</tt> where the type is
@@ -38,11 +36,6 @@
* @author Gavin King
*/
public class CastFunction implements SQLFunction {
-
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return columnType; //note there is a wierd implementation in the client side
- }
-
public boolean hasArguments() {
return true;
}
@@ -51,7 +44,11 @@
return true;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return columnType; // this is really just a guess, unless the caller properly identifies the 'type' argument here
+ }
+
+ public String render(Type columnType, List args, SessionFactoryImplementor factory) throws QueryException {
if ( args.size()!=2 ) {
throw new QueryException("cast() requires two arguments");
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/CharIndexFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/CharIndexFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/CharIndexFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -37,11 +37,6 @@
* @author Nathan Moon
*/
public class CharIndexFunction implements SQLFunction {
-
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.INTEGER;
- }
-
public boolean hasArguments() {
return true;
}
@@ -50,7 +45,11 @@
return true;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return Hibernate.INTEGER;
+ }
+
+ public String render(Type columnType, List args, SessionFactoryImplementor factory) throws QueryException {
boolean threeArgs = args.size() > 2;
Object pattern = args.get(0);
Object string = args.get(1);
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/ConvertFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/ConvertFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/ConvertFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -39,10 +38,6 @@
*/
public class ConvertFunction implements SQLFunction {
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
- }
-
public boolean hasArguments() {
return true;
}
@@ -51,7 +46,11 @@
return true;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public String render(Type firstArgumentType, List args, SessionFactoryImplementor factory) throws QueryException {
if ( args.size() != 2 && args.size() != 3 ) {
throw new QueryException( "convert() requires two or three arguments" );
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/DerbyConcatFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -51,10 +51,10 @@
/**
* {@inheritDoc}
* <p/>
- * Here we always return {@link Hibernate#STRING}.
+ * Here we always return <tt>true</tt>
*/
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
+ public boolean hasArguments() {
+ return true;
}
/**
@@ -62,17 +62,17 @@
* <p/>
* Here we always return <tt>true</tt>
*/
- public boolean hasArguments() {
+ public boolean hasParenthesesIfNoArguments() {
return true;
}
/**
* {@inheritDoc}
* <p/>
- * Here we always return <tt>true</tt>
+ * Here we always return {@link Hibernate#STRING}.
*/
- public boolean hasParenthesesIfNoArguments() {
- return true;
+ public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
}
/**
@@ -82,10 +82,10 @@
* this method. The logic here says that if not all the incoming args are dynamic parameters
* (i.e. <tt>?</tt>) then we simply use the Derby concat operator (<tt>||</tt>) on the unchanged
* arg elements. However, if all the args are dynamic parameters, then we need to wrap the individual
- * arg elements in <tt>cast</tt> function calls, use the concantenation operator on the <tt>cast</tt>
+ * arg elements in <tt>cast</tt> function calls, use the concatenation operator on the <tt>cast</tt>
* returns, and then wrap that whole thing in a call to the Derby <tt>varchar</tt> function.
*/
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public String render(Type argumentType, List args, SessionFactoryImplementor factory) throws QueryException {
boolean areAllArgsParams = true;
Iterator itr = args.iterator();
while ( itr.hasNext() ) {
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/NoArgSQLFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/NoArgSQLFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/NoArgSQLFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -51,19 +51,19 @@
this.name = name;
}
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ public boolean hasArguments() {
+ return false;
+ }
+
+ public boolean hasParenthesesIfNoArguments() {
+ return hasParenthesesIfNoArguments;
+ }
+
+ public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
return returnType;
}
- public boolean hasArguments() {
- return false;
- }
-
- public boolean hasParenthesesIfNoArguments() {
- return hasParenthesesIfNoArguments;
- }
-
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public String render(Type argumentType, List args, SessionFactoryImplementor factory) throws QueryException {
if ( args.size()>0 ) {
throw new QueryException("function takes no arguments: " + name);
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/NvlFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/NvlFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/NvlFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -32,16 +32,11 @@
import org.hibernate.type.Type;
/**
- * Emulation of <tt>coalesce()</tt> on Oracle, using multiple
- * <tt>nvl()</tt> calls
+ * Emulation of <tt>coalesce()</tt> on Oracle, using multiple <tt>nvl()</tt> calls
+ *
* @author Gavin King
*/
public class NvlFunction implements SQLFunction {
-
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return columnType;
- }
-
public boolean hasArguments() {
return true;
}
@@ -50,14 +45,20 @@
return true;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
+ return argumentType;
+ }
+
+ public String render(Type argumentType, List args, SessionFactoryImplementor factory) throws QueryException {
int lastIndex = args.size()-1;
Object last = args.remove(lastIndex);
- if ( lastIndex==0 ) return last.toString();
+ if ( lastIndex==0 ) {
+ return last.toString();
+ }
Object secondLast = args.get(lastIndex-1);
String nvl = "nvl(" + secondLast + ", " + last + ")";
args.set(lastIndex-1, nvl);
- return render(args, factory);
+ return render( argumentType, args, factory );
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/PositionSubstringFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/PositionSubstringFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/PositionSubstringFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -37,11 +36,6 @@
* @author Gavin King
*/
public class PositionSubstringFunction implements SQLFunction {
-
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.INTEGER;
- }
-
public boolean hasArguments() {
return true;
}
@@ -50,7 +44,11 @@
return true;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
+ return Hibernate.INTEGER;
+ }
+
+ public String render(Type firstArgumentType, List args, SessionFactoryImplementor factory) throws QueryException {
boolean threeArgs = args.size() > 2;
Object pattern = args.get(0);
Object string = args.get(1);
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -40,6 +39,7 @@
* provide details required for processing of the function.
*
* @author David Channon
+ * @author Steve Ebersole
*/
public interface SQLFunction {
/**
@@ -50,40 +50,41 @@
public boolean hasArguments();
/**
- * If there are no arguments, are parens required?
+ * If there are no arguments, are parentheses required?
*
* @return True if a no-arg call of this function requires parentheses.
*/
public boolean hasParenthesesIfNoArguments();
/**
- * The return type of the function. May be either a concrete type which
- * is preset, or variable depending upon the type of the first function
- * argument.
+ * The return type of the function. May be either a concrete type which is preset, or variable depending upon
+ * the type of the first function argument.
+ * <p/>
+ * Note, the 'firstArgumentType' parameter should match the one passed into {@link #render}
*
- * @param columnType the type of the first argument
+ * @param firstArgumentType The type of the first argument
* @param mapping The mapping source.
*
* @return The type to be expected as a return.
*
* @throws org.hibernate.QueryException Indicates an issue resolving the return type.
- *
- * @deprecated See http://opensource.atlassian.com/projects/hibernate/browse/HHH-5212
*/
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException;
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException;
+
/**
* Render the function call as SQL fragment.
+ * <p/>
+ * Note, the 'firstArgumentType' parameter should match the one passed into {@link #getReturnType}
*
- * @param args The function arguments
+ * @param firstArgumentType The type of the first argument
+ * @param arguments The function arguments
* @param factory The SessionFactory
*
* @return The rendered function call
*
* @throws org.hibernate.QueryException Indicates a problem rendering the
* function call.
- *
- * @deprecated See http://opensource.atlassian.com/projects/hibernate/browse/HHH-5212
*/
- public String render(List args, SessionFactoryImplementor factory) throws QueryException;
+ public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) throws QueryException;
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunctionTemplate.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunctionTemplate.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/SQLFunctionTemplate.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -39,7 +39,6 @@
* parameters with '?' followed by parameter's index (first index is 1).
*
* @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
- * @version <tt>$Revision: 6608 $</tt>
*/
public class SQLFunctionTemplate implements SQLFunction {
private final Type type;
@@ -59,14 +58,14 @@
/**
* {@inheritDoc}
*/
- public String render(List args, SessionFactoryImplementor factory) {
+ public String render(Type argumentType, List args, SessionFactoryImplementor factory) {
return renderer.render( args, factory );
}
/**
* {@inheritDoc}
*/
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
return type;
}
Added: core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardAnsiSqlAggregationFunctions.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardAnsiSqlAggregationFunctions.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardAnsiSqlAggregationFunctions.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -0,0 +1,205 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.dialect.function;
+
+import java.sql.Types;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.Hibernate;
+import org.hibernate.MappingException;
+import org.hibernate.QueryException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StandardAnsiSqlAggregationFunctions {
+ /**
+ * Definition of a standard ANSI SQL compliant <tt>COUNT</tt> function
+ */
+ public static class CountFunction extends StandardSQLFunction {
+ public static final CountFunction INSTANCE = new CountFunction();
+
+ public CountFunction() {
+ super( "count", Hibernate.LONG );
+ }
+
+ @Override
+ public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) {
+ if ( arguments.size() > 1 ) {
+ if ( "distinct".equalsIgnoreCase( arguments.get( 0 ).toString() ) ) {
+ return renderCountDistinct( arguments );
+ }
+ }
+ return super.render( firstArgumentType, arguments, factory );
+ }
+
+ private String renderCountDistinct(List arguments) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "count(distinct " );
+ String sep = "";
+ Iterator itr = arguments.iterator();
+ itr.next(); // intentionally skip first
+ while ( itr.hasNext() ) {
+ buffer.append( sep )
+ .append( itr.next() );
+ sep = ", ";
+ }
+ return buffer.append( ")" ).toString();
+ }
+ }
+
+
+ /**
+ * Definition of a standard ANSI SQL compliant <tt>AVG</tt> function
+ */
+ public static class AvgFunction extends StandardSQLFunction {
+ public static final AvgFunction INSTANCE = new AvgFunction();
+
+ public AvgFunction() {
+ super( "avg", Hibernate.DOUBLE );
+ }
+
+ @Override
+ public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) throws QueryException {
+ int jdbcTypeCode = determineJdbcTypeCode( firstArgumentType, factory );
+ return render( jdbcTypeCode, arguments.get(0).toString(), factory );
+ }
+
+ protected final int determineJdbcTypeCode(Type firstArgumentType, SessionFactoryImplementor factory) throws QueryException {
+ try {
+ final int[] jdbcTypeCodes = firstArgumentType.sqlTypes( factory );
+ if ( jdbcTypeCodes.length != 1 ) {
+ throw new QueryException( "multiple-column type in avg()" );
+ }
+ return jdbcTypeCodes[0];
+ }
+ catch ( MappingException me ) {
+ throw new QueryException( me );
+ }
+ }
+
+ protected String render(int firstArgumentJdbcType, String argument, SessionFactoryImplementor factory) {
+ return "avg(" + renderArgument( argument, firstArgumentJdbcType ) + ")";
+ }
+
+ protected String renderArgument(String argument, int firstArgumentJdbcType) {
+ return argument;
+ }
+ }
+
+
+ public static class MaxFunction extends StandardSQLFunction {
+ public static final MaxFunction INSTANCE = new MaxFunction();
+
+ public MaxFunction() {
+ super( "max" );
+ }
+ }
+
+ public static class MinFunction extends StandardSQLFunction {
+ public static final MinFunction INSTANCE = new MinFunction();
+
+ public MinFunction() {
+ super( "min" );
+ }
+ }
+
+
+ public static class SumFunction extends StandardSQLFunction {
+ public static final SumFunction INSTANCE = new SumFunction();
+
+ public SumFunction() {
+ super( "sum" );
+ }
+
+ protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException {
+ try {
+ final int[] jdbcTypeCodes = type.sqlTypes( mapping );
+ if ( jdbcTypeCodes.length != 1 ) {
+ throw new QueryException( "multiple-column type in sum()" );
+ }
+ return jdbcTypeCodes[0];
+ }
+ catch ( MappingException me ) {
+ throw new QueryException( me );
+ }
+ }
+
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) {
+ final int jdbcType = determineJdbcTypeCode( firstArgumentType, mapping );
+
+ // First allow the actual type to control the return value; the underlying sqltype could
+ // actually be different
+ if ( firstArgumentType == Hibernate.BIG_INTEGER ) {
+ return Hibernate.BIG_INTEGER;
+ }
+ else if ( firstArgumentType == Hibernate.BIG_DECIMAL ) {
+ return Hibernate.BIG_DECIMAL;
+ }
+ else if ( firstArgumentType == Hibernate.LONG
+ || firstArgumentType == Hibernate.SHORT
+ || firstArgumentType == Hibernate.INTEGER ) {
+ return Hibernate.LONG;
+ }
+ else if ( firstArgumentType == Hibernate.FLOAT || firstArgumentType == Hibernate.DOUBLE) {
+ return Hibernate.DOUBLE;
+ }
+
+ // finally use the jdbcType if == on Hibernate types did not find a match.
+ //
+ // IMPL NOTE : we do not match on Types.NUMERIC because it could be either, so we fall-through to the
+ // first argument type
+ if ( jdbcType == Types.FLOAT
+ || jdbcType == Types.DOUBLE
+ || jdbcType == Types.DECIMAL
+ || jdbcType == Types.REAL) {
+ return Hibernate.DOUBLE;
+ }
+ else if ( jdbcType == Types.BIGINT
+ || jdbcType == Types.INTEGER
+ || jdbcType == Types.SMALLINT
+ || jdbcType == Types.TINYINT ) {
+ return Hibernate.LONG;
+ }
+
+ // as a last resort, return the type of the first argument
+ return firstArgumentType;
+ }
+ }
+
+ public static void primeFunctionMap(Map<String, SQLFunction> functionMap) {
+ functionMap.put( AvgFunction.INSTANCE.getName(), AvgFunction.INSTANCE );
+ functionMap.put( CountFunction.INSTANCE.getName(), CountFunction.INSTANCE );
+ functionMap.put( MaxFunction.INSTANCE.getName(), MaxFunction.INSTANCE );
+ functionMap.put( MinFunction.INSTANCE.getName(), MinFunction.INSTANCE );
+ functionMap.put( SumFunction.INSTANCE.getName(), SumFunction.INSTANCE );
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardJDBCEscapeFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardJDBCEscapeFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardJDBCEscapeFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -45,8 +45,8 @@
super( name, typeValue );
}
- public String render(List args, SessionFactoryImplementor factory) {
- return "{fn " + super.render( args, factory ) + "}";
+ public String render(Type argumentType, List args, SessionFactoryImplementor factory) {
+ return "{fn " + super.render( argumentType, args, factory ) + "}";
}
public String toString() {
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/StandardSQLFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -40,7 +39,7 @@
*/
public class StandardSQLFunction implements SQLFunction {
private final String name;
- private final Type type;
+ private final Type registeredType;
/**
* Construct a standard SQL function definition with a variable return type;
@@ -60,11 +59,11 @@
* Construct a standard SQL function definition with a static return type.
*
* @param name The name of the function.
- * @param type The static return type.
+ * @param registeredType The static return type.
*/
- public StandardSQLFunction(String name, Type type) {
+ public StandardSQLFunction(String name, Type registeredType) {
this.name = name;
- this.type = type;
+ this.registeredType = registeredType;
}
/**
@@ -83,41 +82,39 @@
* not static.
*/
public Type getType() {
- return type;
+ return registeredType;
}
/**
* {@inheritDoc}
*/
- public Type getReturnType(Type columnType, Mapping mapping) {
- // return the concrete type, or the underlying type if a concrete type
- // was not specified
- return type == null ? columnType : type;
+ public boolean hasArguments() {
+ return true;
}
/**
* {@inheritDoc}
*/
- public boolean hasArguments() {
+ public boolean hasParenthesesIfNoArguments() {
return true;
}
/**
* {@inheritDoc}
*/
- public boolean hasParenthesesIfNoArguments() {
- return true;
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) {
+ return registeredType == null ? firstArgumentType : registeredType;
}
/**
* {@inheritDoc}
*/
- public String render(List args, SessionFactoryImplementor factory) {
+ public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
StringBuffer buf = new StringBuffer();
buf.append( name ).append( '(' );
- for ( int i = 0; i < args.size(); i++ ) {
- buf.append( args.get( i ) );
- if ( i < args.size() - 1 ) {
+ for ( int i = 0; i < arguments.size(); i++ ) {
+ buf.append( arguments.get( i ) );
+ if ( i < arguments.size() - 1 ) {
buf.append( ", " );
}
}
@@ -127,4 +124,5 @@
public String toString() {
return name;
}
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -37,10 +37,6 @@
* @author Steve Ebersole
*/
public abstract class TrimFunctionTemplate implements SQLFunction {
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
- }
-
public boolean hasArguments() {
return true;
}
@@ -49,7 +45,11 @@
return false;
}
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type firstArgument, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public String render(Type firstArgument, List args, SessionFactoryImplementor factory) throws QueryException {
final Options options = new Options();
final String trimSource;
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/VarArgsSQLFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/VarArgsSQLFunction.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/VarArgsSQLFunction.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.dialect.function;
@@ -32,8 +31,7 @@
import org.hibernate.type.Type;
/**
- * Support for slightly more general templating than {@link StandardSQLFunction},
- * with an unlimited number of arguments.
+ * Support for slightly more general templating than {@link StandardSQLFunction}, with an unlimited number of arguments.
*
* @author Gavin King
*/
@@ -41,20 +39,20 @@
private final String begin;
private final String sep;
private final String end;
- private final Type type;
+ private final Type registeredType;
/**
* Constructs a VarArgsSQLFunction instance with a 'static' return type. An example of a 'static'
* return type would be something like an <tt>UPPER</tt> function which is always returning
* a SQL VARCHAR and thus a string type.
*
- * @param type The return type.
+ * @param registeredType The return type.
* @param begin The beginning of the function templating.
* @param sep The separator for each individual function argument.
* @param end The end of the function templating.
*/
- public VarArgsSQLFunction(Type type, String begin, String sep, String end) {
- this.type = type;
+ public VarArgsSQLFunction(Type registeredType, String begin, String sep, String end) {
+ this.registeredType = registeredType;
this.begin = begin;
this.sep = sep;
this.end = end;
@@ -70,7 +68,7 @@
* @param sep The separator for each individual function argument.
* @param end The end of the function templating.
*
- * @see #getReturnType Specifically, the 'columnType' argument is the 'dynamic' type.
+ * @see #getReturnType Specifically, the 'firstArgumentType' argument is the 'dynamic' type.
*/
public VarArgsSQLFunction(String begin, String sep, String end) {
this( null, begin, sep, end );
@@ -78,13 +76,6 @@
/**
* {@inheritDoc}
- */
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return type == null ? columnType : type;
- }
-
- /**
- * {@inheritDoc}
* <p/>
* Always returns true here.
*/
@@ -104,11 +95,15 @@
/**
* {@inheritDoc}
*/
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
+ return registeredType == null ? firstArgumentType : registeredType;
+ }
+
+ public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) {
StringBuffer buf = new StringBuffer().append( begin );
- for ( int i = 0; i < args.size(); i++ ) {
- buf.append( transformArgument( ( String ) args.get( i ) ) );
- if ( i < args.size() - 1 ) {
+ for ( int i = 0; i < arguments.size(); i++ ) {
+ buf.append( transformArgument( ( String ) arguments.get( i ) ) );
+ if ( i < arguments.size() - 1 ) {
buf.append( sep );
}
}
@@ -116,8 +111,8 @@
}
/**
- * Called from {@link #render} to allow applying a change or transformation to each individual
- * argument.
+ * Called from {@link #render} to allow applying a change or transformation
+ * to each individual argument.
*
* @param argument The argument being processed.
* @return The transformed argument; may be the same, though should never be null.
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -33,6 +33,8 @@
import antlr.collections.AST;
import org.hibernate.QueryException;
import org.hibernate.hql.ast.tree.FunctionNode;
+import org.hibernate.hql.ast.tree.SqlNode;
+import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
import org.hibernate.param.ParameterSpecification;
import org.hibernate.dialect.function.SQLFunction;
@@ -202,10 +204,11 @@
super.endFunctionTemplate( node );
}
else {
+ final Type functionType = functionNode.getFirstArgumentType();
// this function has a registered SQLFunction -> redirect output and catch the arguments
FunctionArguments functionArguments = ( FunctionArguments ) writer;
writer = outputStack.removeFirst();
- out( sqlFunction.render( functionArguments.getArgs(), sessionFactory ) );
+ out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/AggregateNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/AggregateNode.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/AggregateNode.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -29,6 +29,7 @@
import org.hibernate.type.Type;
import antlr.SemanticException;
+import antlr.collections.AST;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,6 +63,20 @@
return sqlFunction;
}
+ public Type getFirstArgumentType() {
+ AST argument = getFirstChild();
+ while ( argument != null ) {
+ if ( argument instanceof SqlNode ) {
+ final Type type = ( (SqlNode) argument ).getDataType();
+ if ( type != null ) {
+ return type;
+ }
+ argument = argument.getNextSibling();
+ }
+ }
+ return null;
+ }
+
public Type getDataType() {
// Get the function return value type, based on the type of the first argument.
return getSessionFactoryHelper().findFunctionReturnType( getText(), resolveFunction(), getFirstChild() );
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FunctionNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FunctionNode.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FunctionNode.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -24,6 +24,7 @@
package org.hibernate.hql.ast.tree;
import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.type.Type;
/**
* Identifies a node which models a SQL function.
@@ -32,4 +33,5 @@
*/
public interface FunctionNode {
public SQLFunction getSQLFunction();
+ public Type getFirstArgumentType();
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IdentNode.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -291,7 +291,10 @@
return fe.getDataType();
}
SQLFunction sf = getWalker().getSessionFactoryHelper().findSQLFunction( getText() );
- return sf == null ? null : sf.getReturnType( null, null );
+ if ( sf != null ) {
+ return sf.getReturnType( null, getWalker().getSessionFactoryHelper().getFactory() );
+ }
+ return null;
}
public void setScalarColumnText(int i) throws SemanticException {
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -96,6 +96,20 @@
return function;
}
+ public Type getFirstArgumentType() {
+ AST argument = getFirstChild();
+ while ( argument != null ) {
+ if ( argument instanceof SqlNode ) {
+ final Type type = ( (SqlNode) argument ).getDataType();
+ if ( type != null ) {
+ return type;
+ }
+ argument = argument.getNextSibling();
+ }
+ }
+ return null;
+ }
+
private void dialectFunction(AST exprList) {
function = getSessionFactoryHelper().findSQLFunction( methodName );
if ( function != null ) {
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -46,7 +46,6 @@
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
-import org.hibernate.type.TypeFactory;
import antlr.SemanticException;
import antlr.collections.AST;
Modified: core/trunk/core/src/main/java/org/hibernate/hql/classic/SelectParser.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/classic/SelectParser.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/hql/classic/SelectParser.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -142,9 +142,14 @@
}
}
else if ( COUNT_MODIFIERS.contains( lctoken ) ) {
- if ( !ready || !aggregate ) throw new QueryException( token + " only allowed inside aggregate function in SELECT" );
+ if ( !ready || !aggregate ) {
+ throw new QueryException( token + " only allowed inside aggregate function in SELECT" );
+ }
q.appendScalarSelectToken( token );
- if ( "*".equals( token ) ) q.addSelectScalar( getFunction( "count", q ).getReturnType( Hibernate.LONG, q.getFactory() ) ); //special case
+ if ( "*".equals( token ) ) {
+ // special case
+ q.addSelectScalar( getFunction( "count", q ).getReturnType( Hibernate.LONG, q.getFactory() ) );
+ }
}
else if ( getFunction( lctoken, q ) != null && token.equals( q.unalias( token ) ) ) {
// the name of an SQL function
Modified: core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/core/src/main/java/org/hibernate/sql/ordering/antlr/OrderByFragmentParser.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -137,7 +137,7 @@
expressions.add( child.getText() );
child = child.getNextSibling();
}
- final String text = function.render( expressions, context.getSessionFactory() );
+ final String text = function.render( null, expressions, context.getSessionFactory() );
return getASTFactory().create( OrderByTemplateTokenTypes.IDENT, text );
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -66,7 +66,7 @@
else {
List args = new ArrayList();
args.add( "dob" );
- f.setFormula( yearFunction.render( args, null ) );
+ f.setFormula( yearFunction.render( Hibernate.INTEGER, args, null ) );
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -5,6 +5,7 @@
import junit.framework.Test;
+import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Mappings;
@@ -40,7 +41,7 @@
if ( lengthFunction != null ) {
ArrayList args = new ArrayList();
args.add( "bio" );
- f.setFormula( lengthFunction.render( args, null ) );
+ f.setFormula( lengthFunction.render( Hibernate.INTEGER, args, null ) );
}
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/function/AnsiTrimEmulationFunctionTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/function/AnsiTrimEmulationFunctionTest.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/function/AnsiTrimEmulationFunctionTest.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -23,8 +23,8 @@
*/
package org.hibernate.test.dialect.function;
+import java.util.Arrays;
import java.util.List;
-import java.util.ArrayList;
import junit.framework.TestCase;
@@ -48,22 +48,22 @@
final String expectedPostTrimSuffix = ",' ','-'),'${space}$',' ')";
// -> trim(LEADING '-' FROM a.column)
- String rendered = function.render( argList( "LEADING", "'-'", "FROM", trimSource ), null );
+ String rendered = function.render( null, argList( "LEADING", "'-'", "FROM", trimSource ), null );
String expected = expectedPostTrimPrefix + "ltrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim(TRAILING '-' FROM a.column)
- rendered = function.render( argList( "TRAILING", "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "TRAILING", "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "rtrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim(BOTH '-' FROM a.column)
- rendered = function.render( argList( "BOTH", "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "BOTH", "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim('-' FROM a.column)
- rendered = function.render( argList( "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
}
@@ -82,88 +82,62 @@
final String expectedPostTrimSuffix = ",' ','-'),'${space}$',' ')";
// -> trim(LEADING '-' FROM a.column)
- String rendered = function.render( argList( "LEADING", "'-'", "FROM", trimSource ), null );
+ String rendered = function.render( null, argList( "LEADING", "'-'", "FROM", trimSource ), null );
String expected = expectedPostTrimPrefix + "ltrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim(TRAILING '-' FROM a.column)
- rendered = function.render( argList( "TRAILING", "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "TRAILING", "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "rtrim(" + expectedTrimPrep + ")" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim(BOTH '-' FROM a.column)
- rendered = function.render( argList( "BOTH", "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "BOTH", "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
// -> trim('-' FROM a.column)
- rendered = function.render( argList( "'-'", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "'-'", "FROM", trimSource ), null );
expected = expectedPostTrimPrefix + "ltrim(rtrim(" + expectedTrimPrep + "))" + expectedPostTrimSuffix;
assertEquals( expected, rendered );
}
private void performBasicSpaceTrimmingTests(AnsiTrimEmulationFunction function) {
// -> trim(a.column)
- String rendered = function.render( argList( trimSource ), null );
+ String rendered = function.render( null, argList( trimSource ), null );
assertEquals( "ltrim(rtrim(a.column))", rendered );
// -> trim(FROM a.column)
- rendered = function.render( argList( "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "FROM", trimSource ), null );
assertEquals( "ltrim(rtrim(a.column))", rendered );
// -> trim(BOTH FROM a.column)
- rendered = function.render( argList( "BOTH", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "BOTH", "FROM", trimSource ), null );
assertEquals( "ltrim(rtrim(a.column))", rendered );
// -> trim(BOTH ' ' FROM a.column)
- rendered = function.render( argList( "BOTH", "' '", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "BOTH", "' '", "FROM", trimSource ), null );
assertEquals( "ltrim(rtrim(a.column))", rendered );
// -> trim(LEADING FROM a.column)
- rendered = function.render( argList( "LEADING", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "LEADING", "FROM", trimSource ), null );
assertEquals( "ltrim(a.column)", rendered );
// -> trim(LEADING ' ' FROM a.column)
- rendered = function.render( argList( "LEADING", "' '", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "LEADING", "' '", "FROM", trimSource ), null );
assertEquals( "ltrim(a.column)", rendered );
// -> trim(TRAILING FROM a.column)
- rendered = function.render( argList( "TRAILING", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "TRAILING", "FROM", trimSource ), null );
assertEquals( "rtrim(a.column)", rendered );
// -> trim(TRAILING ' ' FROM a.column)
- rendered = function.render( argList( "TRAILING", "' '", "FROM", trimSource ), null );
+ rendered = function.render( null, argList( "TRAILING", "' '", "FROM", trimSource ), null );
assertEquals( "rtrim(a.column)", rendered );
}
- private List argList(String arg) {
- ArrayList args = new ArrayList();
- args.add( arg );
- return args;
+ private List argList(String... args) {
+ return Arrays.asList( args );
}
- private List argList(String arg1, String arg2) {
- ArrayList args = new ArrayList();
- args.add( arg1 );
- args.add( arg2 );
- return args;
- }
-
- private List argList(String arg1, String arg2, String arg3) {
- ArrayList args = new ArrayList();
- args.add( arg1 );
- args.add( arg2 );
- args.add( arg3 );
- return args;
- }
-
- private List argList(String arg1, String arg2, String arg3, String arg4) {
- ArrayList args = new ArrayList();
- args.add( arg1 );
- args.add( arg2 );
- args.add( arg3 );
- args.add( arg4 );
- return args;
- }
-
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2010-08-01 07:54:28 UTC (rev 20096)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2010-08-02 18:51:45 UTC (rev 20097)
@@ -682,7 +682,7 @@
assertTranslation( "from Animal an where an.bodyWeight > abs(3*5)" );
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()) );
+ assertTranslation( "from Animal an where an.description = " + concat.render(Hibernate.STRING, list, getSessionFactoryImplementor()) );
}
public void testNotOrWhereClause() {
14 years, 1 month
Hibernate SVN: r20096 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-01 03:54:28 -0400 (Sun, 01 Aug 2010)
New Revision: 20096
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationDescriptor.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
Log:
HV-355: Improved error logging in case of unknown parameters given by annotation descriptor
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationDescriptor.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationDescriptor.java 2010-08-01 07:39:43 UTC (rev 20095)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationDescriptor.java 2010-08-01 07:54:28 UTC (rev 20096)
@@ -32,6 +32,7 @@
* @author Paolo Perrotta
* @author Davide Marchignoli
* @author Hardy Ferentschik
+ * @author Gunnar Morling
*/
public class AnnotationDescriptor<T extends Annotation> {
@@ -41,36 +42,36 @@
/**
* Returns a new descriptor for the given annotation type.
- *
+ *
* @param <S> The type of the annotation.
* @param annotationType The annotation's class.
- *
+ *
* @return A new descriptor for the given annotation type.
*/
public static <S extends Annotation> AnnotationDescriptor<S> getInstance(Class<S> annotationType) {
- return new AnnotationDescriptor<S>(annotationType);
+ return new AnnotationDescriptor<S>( annotationType );
}
-
+
/**
* Returns a new descriptor for the given annotation type.
- *
+ *
* @param <S> The type of the annotation.
* @param annotationType The annotation's class.
* @param elements A map with attribute values for the annotation to be created.
- *
+ *
* @return A new descriptor for the given annotation type.
*/
public static <S extends Annotation> AnnotationDescriptor<S> getInstance(Class<S> annotationType, Map<String, Object> elements) {
- return new AnnotationDescriptor<S>(annotationType, elements);
+ return new AnnotationDescriptor<S>( annotationType, elements );
}
-
+
public AnnotationDescriptor(Class<T> annotationType) {
this.type = annotationType;
}
- public AnnotationDescriptor(Class<T> annotationType, Map<String, Object> elements) {
+ public AnnotationDescriptor(Class<T> annotationType, Map<String, Object> elements) {
this.type = annotationType;
- for (Map.Entry<String, Object> entry : elements.entrySet()) {
+ for ( Map.Entry<String, Object> entry : elements.entrySet() ) {
this.elements.put( entry.getKey(), entry.getValue() );
}
}
@@ -91,6 +92,16 @@
return elements.size();
}
+ /**
+ * Returns a map with the elements contained in this descriptor keyed by name. This map is a copy
+ * of the internally used map, so it can safely be modified without altering this descriptor.
+ *
+ * @return A map with this descriptor's elements.
+ */
+ public Map<String, Object> getElements() {
+ return new HashMap<String, Object>( elements );
+ }
+
public Class<T> type() {
return type;
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-08-01 07:39:43 UTC (rev 20095)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/util/annotationfactory/AnnotationProxy.java 2010-08-01 07:54:28 UTC (rev 20096)
@@ -23,6 +23,7 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -60,12 +61,12 @@
private final Map<String, Object> values;
- public AnnotationProxy(AnnotationDescriptor descriptor) {
+ public AnnotationProxy(AnnotationDescriptor<?> descriptor) {
this.annotationType = descriptor.type();
values = getAnnotationValues( descriptor );
}
- private Map<String, Object> getAnnotationValues(AnnotationDescriptor descriptor) {
+ private Map<String, Object> getAnnotationValues(AnnotationDescriptor<?> descriptor) {
Map<String, Object> result = new HashMap<String, Object>();
int processedValuesFromDescriptor = 0;
final Method[] declaredMethods = ReflectionHelper.getMethods( annotationType );
@@ -82,7 +83,11 @@
}
}
if ( processedValuesFromDescriptor != descriptor.numberOfElements() ) {
- throw new RuntimeException( "Trying to instantiate " + annotationType + " with unknown parameters." );
+
+ Set<String> unknownParameters = descriptor.getElements().keySet();
+ unknownParameters.removeAll( result.keySet() );
+
+ throw new RuntimeException( "Trying to instantiate " + annotationType + " with unknown parameter(s): " + unknownParameters );
}
return result;
}
14 years, 1 month
Hibernate SVN: r20095 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validator/test/cfg and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-08-01 03:39:43 -0400 (Sun, 01 Aug 2010)
New Revision: 20095
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/defs/RangeDef.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
Log:
HV-355: Fixed wrong parameter names in RangeDef
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/defs/RangeDef.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/defs/RangeDef.java 2010-07-30 21:29:10 UTC (rev 20094)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/cfg/defs/RangeDef.java 2010-08-01 07:39:43 UTC (rev 20095)
@@ -49,12 +49,12 @@
}
public RangeDef min(long min) {
- addParameter( "value", min );
+ addParameter( "min", min );
return this;
}
public RangeDef max(long max) {
- addParameter( "value", max );
+ addParameter( "max", max );
return this;
}
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-07-30 21:29:10 UTC (rev 20094)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/ConstraintMappingTest.java 2010-08-01 07:39:43 UTC (rev 20095)
@@ -37,6 +37,7 @@
import org.hibernate.validator.cfg.defs.MinDef;
import org.hibernate.validator.cfg.defs.NotEmptyDef;
import org.hibernate.validator.cfg.defs.NotNullDef;
+import org.hibernate.validator.cfg.defs.RangeDef;
import org.hibernate.validator.cfg.defs.SizeDef;
import org.hibernate.validator.test.util.TestUtil;
import org.hibernate.validator.util.LoggerFactory;
@@ -295,6 +296,32 @@
config.buildValidatorFactory();
}
+ /**
+ * HV-355 (parameter names of RangeDef wrong)
+ */
+ @Test
+ public void testRangeDef() {
+
+ HibernateValidatorConfiguration config = TestUtil.getConfiguration( HibernateValidator.class );
+
+ ConstraintMapping mapping = new ConstraintMapping();
+ mapping.type( Runner.class )
+ .property( "age", METHOD )
+ .constraint( RangeDef.class )
+ .min( 12 )
+ .max( 99 );
+
+
+ config.addMapping( mapping );
+
+ ValidatorFactory factory = config.buildValidatorFactory();
+ Validator validator = factory.getValidator();
+
+ Set<ConstraintViolation<Runner>> violations = validator.validate( new Runner() );
+ assertNumberOfViolations( violations, 1 );
+ assertConstraintViolation( violations.iterator().next(), "must be between 12 and 99" );
+ }
+
public interface Foo {
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-07-30 21:29:10 UTC (rev 20094)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Marathon.java 2010-08-01 07:39:43 UTC (rev 20095)
@@ -28,6 +28,10 @@
private String name;
+ /**
+ * Intentionally without a getter/setter to test adding a constraint programmatically using field access type
+ */
+ @SuppressWarnings("unused")
private long numberOfHelpers;
private Date tournamentDate;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java 2010-07-30 21:29:10 UTC (rev 20094)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/cfg/Runner.java 2010-08-01 07:39:43 UTC (rev 20095)
@@ -21,10 +21,13 @@
* @author Hardy Ferentschik
*/
public class Runner {
+
private String name;
private boolean paidEntryFee;
+ private int age;
+
public boolean isPaidEntryFee() {
return paidEntryFee;
}
@@ -40,6 +43,13 @@
public void setName(String name) {
this.name = name;
}
-}
+ public int getAge() {
+ return age;
+ }
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
14 years, 1 month