Author: steve.ebersole(a)jboss.com
Date: 2008-10-08 19:02:47 -0400 (Wed, 08 Oct 2008)
New Revision: 15294
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/DB2Dialect.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/Dialect.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/HqlSqlWalker.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/hql/BulkManipulationTest.java
Log:
JBPAPP-949 : parameters in select clause
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/DB2Dialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/DB2Dialect.java 2008-10-08
22:59:59 UTC (rev 15293)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/DB2Dialect.java 2008-10-08
23:02:47 UTC (rev 15294)
@@ -351,12 +351,28 @@
return false;
}
+ /**
+ * {@inheritDoc}
+ * <p/>
+ * DB2 is know to support parameters in the <tt>SELECT</tt> clause, but only
in casted form
+ * (see {@link #requiresCastingOfParametersInSelectClause()}).
+ *
+ * @return True.
+ */
public boolean supportsParametersInInsertSelect() {
- // DB2 known to not support parameters within the select
- // clause of an SQL INSERT ... SELECT ... statement
- return false;
+ return true;
}
+ /**
+ * DB2 in fact does require that parameters appearing in the select clause be wrapped in
cast() calls
+ * to tell the DB parser the type of the select value.
+ *
+ * @return True.
+ */
+ public boolean requiresCastingOfParametersInSelectClause() {
+ return true;
+ }
+
public boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() {
return false;
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/Dialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/Dialect.java 2008-10-08
22:59:59 UTC (rev 15293)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/Dialect.java 2008-10-08
23:02:47 UTC (rev 15294)
@@ -1605,14 +1605,14 @@
}
/**
- * Does this dialect support casted parameters within the select clause of
- * INSERT ... SELECT ... cast( ? as <type> ) statements?
+ * Does this dialect require that parameters appearing in the
<tt>SELECT</tt> clause be wrapped in <tt>cast()</tt>
+ * calls to tell the db parser the expected type.
*
- * @return True if this is supported; false otherwise.
+ * @return True if select clause parameter must be cast()ed
* @since 3.2
*/
- public boolean supportsCastedParametersInInsertSelect() {
- return true;
+ public boolean requiresCastingOfParametersInSelectClause() {
+ return false;
}
/**
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
---
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/HqlSqlWalker.java 2008-10-08
22:59:59 UTC (rev 15293)
+++
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/HqlSqlWalker.java 2008-10-08
23:02:47 UTC (rev 15294)
@@ -651,38 +651,38 @@
AST versionValueNode = null;
if ( sessionFactoryHelper.getFactory().getDialect().supportsParametersInInsertSelect()
) {
- versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
- ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(
versionType );
- ( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
- parameters.add( 0, paramSpec );
- }
- else if (
sessionFactoryHelper.getFactory().getDialect().supportsCastedParametersInInsertSelect() )
{
int sqlTypes[] = versionType.sqlTypes( sessionFactoryHelper.getFactory() );
if ( sqlTypes == null || sqlTypes.length == 0 ) {
- throw new AssertionFailure( versionType.getClass() + "sqlTypes() returns null
or empty array" );
+ throw new IllegalStateException( versionType.getClass() + ".sqlTypes() returns
null or empty array" );
}
if ( sqlTypes.length > 1 ) {
- throw new UnsupportedOperationException( versionType.getClass() +
- ".sqlTypes() returns > 1 element; only single-valued versions are
allowed." );
+ throw new IllegalStateException(
+ versionType.getClass() +
+ ".sqlTypes() returns > 1 element; only single-valued versions are
allowed."
+ );
}
- MethodNode versionMethodNode = ( MethodNode ) getASTFactory().create(
HqlSqlTokenTypes.METHOD_CALL, "(" );
- AST methodIdentNode = getASTFactory().create( HqlSqlTokenTypes.IDENT,
"cast" );
- versionMethodNode.initializeMethodNode(methodIdentNode, true );
- versionMethodNode.addChild( methodIdentNode );
- AST castExprListNode = getASTFactory().create( HqlSqlTokenTypes.EXPR_LIST,
"exprList" );
- methodIdentNode.setNextSibling( castExprListNode );
- AST paramNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
+ versionValueNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(
versionType );
- ( ( ParameterNode ) paramNode ).setHqlParameterSpecification( paramSpec );
- castExprListNode.addChild( paramNode );
- paramNode.setNextSibling(
- getASTFactory().create(
- HqlSqlTokenTypes.IDENT,
- sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] ) )
- );
- processFunction( versionMethodNode, true );
- versionValueNode = versionMethodNode;
+ ( ( ParameterNode ) versionValueNode ).setHqlParameterSpecification( paramSpec );
parameters.add( 0, paramSpec );
+
+ if (
sessionFactoryHelper.getFactory().getDialect().requiresCastingOfParametersInSelectClause()
) {
+ // we need to wrtap the param in a cast()
+ MethodNode versionMethodNode = ( MethodNode ) getASTFactory().create(
HqlSqlTokenTypes.METHOD_CALL, "(" );
+ AST methodIdentNode = getASTFactory().create( HqlSqlTokenTypes.IDENT,
"cast" );
+ versionMethodNode.addChild( methodIdentNode );
+ versionMethodNode.initializeMethodNode(methodIdentNode, true );
+ AST castExprListNode = getASTFactory().create( HqlSqlTokenTypes.EXPR_LIST,
"exprList" );
+ methodIdentNode.setNextSibling( castExprListNode );
+ castExprListNode.addChild( versionValueNode );
+ versionValueNode.setNextSibling(
+ getASTFactory().create(
+ HqlSqlTokenTypes.IDENT,
+ sessionFactoryHelper.getFactory().getDialect().getTypeName( sqlTypes[0] ) )
+ );
+ processFunction( versionMethodNode, true );
+ versionValueNode = versionMethodNode;
+ }
}
else {
if ( isIntegral( versionType ) ) {
Modified:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
---
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/hql/BulkManipulationTest.java 2008-10-08
22:59:59 UTC (rev 15293)
+++
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/hql/BulkManipulationTest.java 2008-10-08
23:02:47 UTC (rev 15294)
@@ -416,9 +416,8 @@
// dialects which do not allow a parameter in the select portion of an INSERT ...
SELECT statement
// will also be problematic for this test because the timestamp here is vm-based as
opposed to
// db-based.
- if ( !getDialect().supportsParametersInInsertSelect() &&
- !getDialect().supportsCastedParametersInInsertSelect() ) {
- reportSkip( "dialect does not support parameter in INSERT ... SELECT",
+ if ( ! getDialect().supportsParametersInInsertSelect() ) {
+ reportSkip( "dialect does not support parameter in INSERT ... SELECT",
"test bulk inserts with generated id and generated timestamp");
return;
}
Show replies by date