Author: cbredesen
Date: 2009-01-12 13:58:17 -0500 (Mon, 12 Jan 2009)
New Revision: 15771
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/IndexNode.java
Log:
Additional fix for JBPAPP-1250, JBPAPP-1251
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/IndexNode.java
===================================================================
---
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-12
15:37:37 UTC (rev 15770)
+++
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-12
18:58:17 UTC (rev 15771)
@@ -1,10 +1,20 @@
// $Id$
package org.hibernate.hql.ast.tree;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hibernate.QueryException;
import org.hibernate.engine.JoinSequence;
+import org.hibernate.engine.QueryParameters;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.hql.ast.SqlGenerator;
import org.hibernate.hql.ast.util.SessionFactoryHelper;
+import org.hibernate.param.ParameterSpecification;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
@@ -13,8 +23,6 @@
import antlr.SemanticException;
import antlr.collections.AST;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Represents the [] operator and provides it's semantics.
@@ -124,10 +132,70 @@
}
String selectorExpression = gen.getSQL();
joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " =
" + selectorExpression );
+ List paramSpecs = gen.getCollectedParameters();
+ if ( paramSpecs != null ) {
+ switch ( paramSpecs.size() ) {
+ case 0 :
+ // nothing to do
+ break;
+ case 1 :
+ ParameterSpecification paramSpec = ( ParameterSpecification ) paramSpecs.get( 0 );
+ paramSpec.setExpectedType( queryableCollection.getIndexType() );
+ fromElement.setIndexCollectionSelectorParamSpec( paramSpec );
+ break;
+ default:
+ fromElement.setIndexCollectionSelectorParamSpec(
+ new AggregatedIndexCollectionSelectorParameterSpecifications( paramSpecs )
+ );
+ break;
+ }
+ }
// Now, set the text for this node. It should be the element columns.
String[] elementColumns = queryableCollection.getElementColumnNames( elementTable );
setText( elementColumns[0] );
setResolved();
}
+
+ /**
+ * In the (rare?) case where the index selector contains multiple parameters...
+ */
+ private static class AggregatedIndexCollectionSelectorParameterSpecifications implements
ParameterSpecification {
+ private final List paramSpecs;
+
+ public AggregatedIndexCollectionSelectorParameterSpecifications(List paramSpecs) {
+ this.paramSpecs = paramSpecs;
+ }
+
+ public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor
session, int position)
+ throws SQLException {
+ int bindCount = 0;
+ Iterator itr = paramSpecs.iterator();
+ while ( itr.hasNext() ) {
+ final ParameterSpecification paramSpec = ( ParameterSpecification ) itr.next();
+ bindCount += paramSpec.bind( statement, qp, session, position + bindCount );
+ }
+ return bindCount;
+ }
+
+ public Type getExpectedType() {
+ return null;
+ }
+
+ public void setExpectedType(Type expectedType) {
+ }
+
+ public String renderDisplayInfo() {
+ return "index-selector [" + collectDisplayInfo() + "]" ;
+ }
+
+ private String collectDisplayInfo() {
+ StringBuffer buffer = new StringBuffer();
+ Iterator itr = paramSpecs.iterator();
+ while ( itr.hasNext() ) {
+ buffer.append( ( ( ParameterSpecification ) itr.next() ).renderDisplayInfo() );
+ }
+ return buffer.toString();
+ }
+ }
}
Show replies by date