[hibernate-commits] Hibernate SVN: r15766 - in core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast: tree and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Jan 9 16:30:33 EST 2009


Author: cbredesen
Date: 2009-01-09 16:30:33 -0500 (Fri, 09 Jan 2009)
New Revision: 15766

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/tree/FromElement.java
   core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElementType.java
   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/util/SyntheticAndFactory.java
Log:
Fixed parameter binding problems caused by JBPAPP-1250, JBPAPP-1251

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	2009-01-09 14:56:30 UTC (rev 15765)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/HqlSqlWalker.java	2009-01-09 21:30:33 UTC (rev 15766)
@@ -47,6 +47,7 @@
 import org.hibernate.hql.ast.tree.UpdateStatement;
 import org.hibernate.hql.ast.tree.Node;
 import org.hibernate.hql.ast.tree.OperatorNode;
+import org.hibernate.hql.ast.tree.ParameterContainer;
 import org.hibernate.hql.ast.util.ASTPrinter;
 import org.hibernate.hql.ast.util.ASTUtil;
 import org.hibernate.hql.ast.util.AliasGenerator;
@@ -335,7 +336,7 @@
 			if ( log.isDebugEnabled() ) {
 				log.debug( "handleWithFragment() : " + getASTPrinter().showAsString( hqlSqlWithNode, "-- with clause --" ) );
 			}
-			WithClauseVisitor visitor = new WithClauseVisitor();
+			WithClauseVisitor visitor = new WithClauseVisitor( fromElement );
 			NodeTraverser traverser = new NodeTraverser( visitor );
 			traverser.traverseDepthFirst( hqlSqlWithNode );
 			FromElement referencedFromElement = visitor.getReferencedFromElement();
@@ -345,7 +346,6 @@
 			SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() );
 			sql.whereExpr( hqlSqlWithNode.getFirstChild() );
 			fromElement.setWithClauseFragment( visitor.getJoinAlias(), "(" + sql.getSQL() + ")" );
-
 		}
 		catch( SemanticException e ) {
 			throw e;
@@ -359,9 +359,14 @@
 	}
 
 	private static class WithClauseVisitor implements NodeTraverser.VisitationStrategy {
+		private final FromElement joinFragment;
 		private FromElement referencedFromElement;
 		private String joinAlias;
 
+		public WithClauseVisitor(FromElement fromElement) {
+			this.joinFragment = fromElement;
+		}
+
 		public void visit(AST node) {
 			// todo : currently expects that the individual with expressions apply to the same sql table join.
 			//      This may not be the case for joined-subclass where the property values
@@ -373,7 +378,6 @@
 			//          2) here we would need to track each comparison individually, along with
 			//              the join alias to which it applies and then pass that information
 			//              back to the FromElement so it can pass it along to the JoinSequence
-
 			if ( node instanceof DotNode ) {
 				DotNode dotNode = ( DotNode ) node;
 				FromElement fromElement = dotNode.getFromElement();
@@ -394,8 +398,27 @@
 					}
 				}
 			}
+			else if ( node instanceof ParameterNode ) {
+				applyParameterSpecification( ( ( ParameterNode ) node ).getHqlParameterSpecification() );
+			}
+			else if ( node instanceof ParameterContainer ) {
+				applyParameterSpecifications( ( ParameterContainer ) node );
+			}
 		}
 
+		private void applyParameterSpecifications(ParameterContainer parameterContainer) {
+			if ( parameterContainer.hasEmbeddedParameters() ) {
+				ParameterSpecification[] specs = parameterContainer.getEmbeddedParameters();
+				for ( int i = 0; i < specs.length; i++ ) {
+					applyParameterSpecification( specs[i] );
+				}
+			}
+		}
+
+		private void applyParameterSpecification(ParameterSpecification paramSpec) {
+			joinFragment.addEmbeddedParameter( paramSpec );
+		}
+
 		private String extractAppliedAlias(DotNode dotNode) {
 			return dotNode.getText().substring( 0, dotNode.getText().indexOf( '.' ) );
 		}

Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElement.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElement.java	2009-01-09 14:56:30 UTC (rev 15765)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElement.java	2009-01-09 21:30:33 UTC (rev 15766)
@@ -569,4 +569,21 @@
 	public ParameterSpecification[] getEmbeddedParameters() {
 		return ( ParameterSpecification[] ) embeddedParameters.toArray( new ParameterSpecification[ embeddedParameters.size() ] );
 	}
+
+	public ParameterSpecification getIndexCollectionSelectorParamSpec() {
+		return elementType.getIndexCollectionSelectorParamSpec();
+	}
+
+	public void setIndexCollectionSelectorParamSpec(ParameterSpecification indexCollectionSelectorParamSpec) {
+		if ( indexCollectionSelectorParamSpec == null ) {
+			if ( elementType.getIndexCollectionSelectorParamSpec() != null ) {
+				embeddedParameters.remove( elementType.getIndexCollectionSelectorParamSpec() );
+				elementType.setIndexCollectionSelectorParamSpec( null );
+			}
+		}
+		else {
+			elementType.setIndexCollectionSelectorParamSpec( indexCollectionSelectorParamSpec );
+			addEmbeddedParameter( indexCollectionSelectorParamSpec );
+		}
+	}
 }

Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElementType.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElementType.java	2009-01-09 14:56:30 UTC (rev 15765)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/FromElementType.java	2009-01-09 21:30:33 UTC (rev 15766)
@@ -5,6 +5,7 @@
 
 import org.hibernate.MappingException;
 import org.hibernate.QueryException;
+import org.hibernate.param.ParameterSpecification;
 import org.hibernate.util.ArrayHelper;
 import org.hibernate.engine.JoinSequence;
 import org.hibernate.hql.CollectionProperties;
@@ -39,6 +40,7 @@
 	private CollectionPropertyMapping collectionPropertyMapping;
 	private JoinSequence joinSequence;
 	private String collectionSuffix;
+	private ParameterSpecification indexCollectionSelectorParamSpec;
 
 	public FromElementType(FromElement fromElement, EntityPersister persister, EntityType entityType) {
 		this.fromElement = fromElement;
@@ -412,4 +414,12 @@
 	public boolean isEntity() {
 		return persister != null;
 	}
+
+	public ParameterSpecification getIndexCollectionSelectorParamSpec() {
+		return indexCollectionSelectorParamSpec;
+	}
+
+	public void setIndexCollectionSelectorParamSpec(ParameterSpecification indexCollectionSelectorParamSpec) {
+		this.indexCollectionSelectorParamSpec = indexCollectionSelectorParamSpec;
+	}
 }

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-09 14:56:30 UTC (rev 15765)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/tree/IndexNode.java	2009-01-09 21:30:33 UTC (rev 15766)
@@ -93,14 +93,15 @@
 			}
 		}
 
+		// The 'from element' that represents the elements of the collection.
+		setFromElement( fromElement );
+
 		// Add the condition to the join sequence that qualifies the indexed element.
-		AST index = collectionNode.getNextSibling();	// The index should be a constant, which will have been processed already.
-		if ( index == null ) {
+		AST selector = collectionNode.getNextSibling();
+		if ( selector == null ) {
 			throw new QueryException( "No index value!" );
 		}
 
-		setFromElement( fromElement );							// The 'from element' that represents the elements of the collection.
-
 		// Sometimes use the element table alias, sometimes use the... umm... collection table alias (many to many)
 		String collectionTableAlias = elementTable;
 		if ( elem.getCollectionTableAlias() != null ) {
@@ -116,19 +117,17 @@
 		}
 		SqlGenerator gen = new SqlGenerator( getSessionFactoryHelper().getFactory() );
 		try {
-			gen.simpleExpr( index ); //TODO: used to be exprNoParens! was this needed?
+			gen.simpleExpr( selector ); //TODO: used to be exprNoParens! was this needed?
 		}
 		catch ( RecognitionException e ) {
 			throw new QueryException( e.getMessage(), e );
 		}
-		String expression = gen.getSQL();
-		joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + expression );
+		String selectorExpression = gen.getSQL();
+		joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression );
 
 		// Now, set the text for this node.  It should be the element columns.
 		String[] elementColumns = queryableCollection.getElementColumnNames( elementTable );
 		setText( elementColumns[0] );
 		setResolved();
 	}
-
-
 }

Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java	2009-01-09 14:56:30 UTC (rev 15765)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java	2009-01-09 21:30:33 UTC (rev 15766)
@@ -74,6 +74,11 @@
 		fragment.setJoinFragment( joinFragment );
 		fragment.setFromElement( fromElement );
 
+		if ( fromElement.getIndexCollectionSelectorParamSpec() != null ) {
+			fragment.addEmbeddedParameter( fromElement.getIndexCollectionSelectorParamSpec() );
+			fromElement.setIndexCollectionSelectorParamSpec( null );
+		}
+
 		if ( hqlSqlWalker.isFilter() ) {
 			if ( whereFragment.indexOf( '?' ) >= 0 ) {
 				Type collectionFilterKeyType = hqlSqlWalker.getSessionFactoryHelper()




More information about the hibernate-commits mailing list