[hibernate-commits] Hibernate SVN: r15758 - in core/trunk/core/src/main/java/org/hibernate/hql/ast: tree and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jan 9 00:39:49 EST 2009
Author: steve.ebersole at jboss.com
Date: 2009-01-09 00:39:49 -0500 (Fri, 09 Jan 2009)
New Revision: 15758
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java
Log:
HHH-3698 & HHH-3699 : HQL parameter binding issues
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-09 05:32:56 UTC (rev 15757)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-09 05:39:49 UTC (rev 15758)
@@ -68,6 +68,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;
@@ -355,7 +356,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();
@@ -379,9 +380,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
@@ -393,7 +399,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();
@@ -414,8 +419,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/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2009-01-09 05:32:56 UTC (rev 15757)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2009-01-09 05:39:49 UTC (rev 15758)
@@ -590,4 +590,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/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-09 05:32:56 UTC (rev 15757)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-09 05:39:49 UTC (rev 15758)
@@ -28,6 +28,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;
@@ -62,6 +63,7 @@
private CollectionPropertyMapping collectionPropertyMapping;
private JoinSequence joinSequence;
private String collectionSuffix;
+ private ParameterSpecification indexCollectionSelectorParamSpec;
public FromElementType(FromElement fromElement, EntityPersister persister, EntityType entityType) {
this.fromElement = fromElement;
@@ -435,4 +437,12 @@
public boolean isEntity() {
return persister != null;
}
+
+ public ParameterSpecification getIndexCollectionSelectorParamSpec() {
+ return indexCollectionSelectorParamSpec;
+ }
+
+ public void setIndexCollectionSelectorParamSpec(ParameterSpecification indexCollectionSelectorParamSpec) {
+ this.indexCollectionSelectorParamSpec = indexCollectionSelectorParamSpec;
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-09 05:32:56 UTC (rev 15757)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-09 05:39:49 UTC (rev 15758)
@@ -116,14 +116,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 ) {
@@ -139,13 +140,13 @@
}
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 );
@@ -153,5 +154,4 @@
setResolved();
}
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-09 05:32:56 UTC (rev 15757)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-09 05:39:49 UTC (rev 15758)
@@ -97,6 +97,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