Hibernate SVN: r15761 - core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/sql/hand/custom/sybase.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-01-09 06:00:17 -0500 (Fri, 09 Jan 2009)
New Revision: 15761
Modified:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml
Log:
JBPAPP-1546 HHH-3685 - Added workaround to unit test for creating Sybase stored procedures in chained transaction mode
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml 2009-01-09 09:52:13 UTC (rev 15760)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml 2009-01-09 11:00:17 UTC (rev 15761)
@@ -181,7 +181,7 @@
</return>
{ call selectAllEmployments() }
</sql-query>
-
+
<database-object>
<create>
CREATE PROCEDURE selectAllEmployments AS
@@ -194,8 +194,18 @@
</drop>
</database-object>
+ <!-- The following is a workaround for HHH-3685 so that SchemaExport -->
+ <!-- changes the transaction mode of selectAllEmployments to "chained" -->
<database-object>
<create>
+ sp_procxmode selectAllEmployments, 'chained'
+ </create>
+ <!-- no drop command corresponding to "sp_procxmode ..." -->
+ <drop/>
+ </database-object>
+
+ <database-object>
+ <create>
CREATE PROCEDURE paramHandling @j int, @i int AS
SELECT @j as value, @i as value2
</create>
@@ -203,9 +213,19 @@
DROP PROCEDURE paramHandling
</drop>
</database-object>
-
+
+ <!-- The following is a workaround for HHH-3685 so that SchemaExport -->
+ <!-- changes the transaction mode of paramHandling to "chained" -->
<database-object>
<create>
+ sp_procxmode paramHandling, 'chained'
+ </create>
+ <!-- no drop command corresponding to "sp_procxmode ..." -->
+ <drop/>
+ </database-object>
+
+ <database-object>
+ <create>
CREATE PROCEDURE simpleScalar @number int AS
SELECT @number as value, 'getAll' as name
</create>
@@ -213,5 +233,15 @@
DROP PROCEDURE simpleScalar
</drop>
</database-object>
-
+
+ <!-- The following is a workaround for HHH-3685 so that SchemaExport -->
+ <!-- changes the transaction mode of simpleScalar to "chained" -->
+ <database-object>
+ <create>
+ sp_procxmode simpleScalar, 'chained'
+ </create>
+ <!-- no drop command corresponding to "sp_procxmode ..." -->
+ <drop/>
+ </database-object>
+
</hibernate-mapping>
15 years, 3 months
Hibernate SVN: r15760 - in core/branches/Branch_3_2_4_SP1_CP: test/org/hibernate/test/interfaceproxy and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2009-01-09 04:52:13 -0500 (Fri, 09 Jan 2009)
New Revision: 15760
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseDialect.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/lob/SerializableTypeTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/mixed/MixedTest.java
Log:
JBPAPP-1555 HHH-3691 : Sybase does not support Blobs and Clobs; skip unit tests that use Blobs/Clobs
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java 2009-01-09 05:40:48 UTC (rev 15759)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SQLServerDialect.java 2009-01-09 09:52:13 UTC (rev 15760)
@@ -112,9 +112,9 @@
return false;
}
- public boolean supportsCascadeDelete() {
- return true;
- }
+ public boolean supportsCascadeDelete() {
+ return true;
+ }
public boolean supportsCircularCascadeDeleteConstraints() {
// SQL Server (at least up through 2005) does not support defining
@@ -123,6 +123,10 @@
return false;
}
+ public boolean supportsExpectedLobUsagePattern() {
+ return true;
+ }
+
public boolean supportsLobValueChangePropogation() {
// note: at least my local SQL Server 2005 Express shows this not working...
return false;
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseDialect.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseDialect.java 2009-01-09 05:40:48 UTC (rev 15759)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/dialect/SybaseDialect.java 2009-01-09 09:52:13 UTC (rev 15760)
@@ -228,6 +228,10 @@
return false;
}
+ public boolean supportsExpectedLobUsagePattern() {
+ return false;
+ }
+
public boolean supportsEmptyInList() {
return false;
}
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2009-01-09 05:40:48 UTC (rev 15759)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2009-01-09 09:52:13 UTC (rev 15760)
@@ -6,7 +6,6 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -33,8 +32,8 @@
public void testInterfaceProxies() {
- if ( getDialect() instanceof PostgreSQLDialect ) {
- // TODO : why?
+ if ( ! getDialect().supportsExpectedLobUsagePattern() ) {
+ reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
return;
}
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/lob/SerializableTypeTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/lob/SerializableTypeTest.java 2009-01-09 05:40:48 UTC (rev 15759)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/lob/SerializableTypeTest.java 2009-01-09 09:52:13 UTC (rev 15760)
@@ -4,6 +4,9 @@
import junit.framework.Test;
import org.hibernate.Session;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.SybaseDialect;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -26,11 +29,17 @@
return new FunctionalTestClassTestSuite( SerializableTypeTest.class );
}
+
public String getCacheConcurrencyStrategy() {
return null;
}
public void testNewSerializableType() {
+ // Sybase ASE does not support ResultSet.getBlob(String)
+ if ( getDialect() instanceof SybaseDialect && ! ( getDialect() instanceof SQLServerDialect ) ) {
+ return;
+ }
+
final String payloadText = "Initial payload";
Session s = openSession();
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/mixed/MixedTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/mixed/MixedTest.java 2009-01-09 05:40:48 UTC (rev 15759)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/mixed/MixedTest.java 2009-01-09 09:52:13 UTC (rev 15760)
@@ -6,7 +6,6 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
@@ -57,7 +56,10 @@
t.commit();
s.close();
- if ( getDialect() instanceof PostgreSQLDialect ) return;
+ if ( ! getDialect().supportsExpectedLobUsagePattern() ) {
+ reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
+ return;
+ }
s = openSession( new DocumentInterceptor() );
t = s.beginTransaction();
15 years, 3 months
Hibernate SVN: r15759 - in core/branches/Branch_3_2/src/org/hibernate/hql/ast: tree and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-01-09 00:40:48 -0500 (Fri, 09 Jan 2009)
New Revision: 15759
Modified:
core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java
core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElement.java
core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElementType.java
core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/IndexNode.java
core/branches/Branch_3_2/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java
Log:
HHH-3698 & HHH-3699 : HQL parameter binding issues
Modified: core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-09 05:39:49 UTC (rev 15758)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-09 05:40:48 UTC (rev 15759)
@@ -45,6 +45,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;
@@ -333,7 +334,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();
@@ -343,7 +344,6 @@
SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() );
sql.whereExpr( hqlSqlWithNode.getFirstChild() );
fromElement.setWithClauseFragment( visitor.getJoinAlias(), "(" + sql.getSQL() + ")" );
-
}
catch( SemanticException e ) {
throw e;
@@ -357,9 +357,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
@@ -371,7 +376,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();
@@ -392,8 +396,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/src/org/hibernate/hql/ast/tree/FromElement.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElement.java 2009-01-09 05:39:49 UTC (rev 15758)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElement.java 2009-01-09 05:40:48 UTC (rev 15759)
@@ -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/src/org/hibernate/hql/ast/tree/FromElementType.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-09 05:39:49 UTC (rev 15758)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-09 05:40:48 UTC (rev 15759)
@@ -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/src/org/hibernate/hql/ast/tree/IndexNode.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-09 05:39:49 UTC (rev 15758)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-09 05:40:48 UTC (rev 15759)
@@ -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/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-09 05:39:49 UTC (rev 15758)
+++ core/branches/Branch_3_2/src/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-09 05:40:48 UTC (rev 15759)
@@ -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()
15 years, 3 months
Hibernate SVN: r15758 - in core/trunk/core/src/main/java/org/hibernate/hql/ast: tree and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)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()
15 years, 3 months
Hibernate SVN: r15757 - in core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast: tree and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-01-09 00:32:56 -0500 (Fri, 09 Jan 2009)
New Revision: 15757
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java
Log:
HHH-3698 & HHH-3699 : HQL parameter binding issues
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-08 17:04:02 UTC (rev 15756)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2009-01-09 05:32:56 UTC (rev 15757)
@@ -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();
@@ -365,7 +366,6 @@
SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() );
sql.whereExpr( hqlSqlWithNode.getFirstChild() );
fromElement.setWithClauseFragment( visitor.getJoinAlias(), "(" + sql.getSQL() + ")" );
-
}
catch( SemanticException e ) {
throw e;
@@ -379,9 +379,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 +398,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 +418,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_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2009-01-08 17:04:02 UTC (rev 15756)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2009-01-09 05:32:56 UTC (rev 15757)
@@ -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/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-08 17:04:02 UTC (rev 15756)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/FromElementType.java 2009-01-09 05:32:56 UTC (rev 15757)
@@ -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/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-08 17:04:02 UTC (rev 15756)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/tree/IndexNode.java 2009-01-09 05:32:56 UTC (rev 15757)
@@ -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 );
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-08 17:04:02 UTC (rev 15756)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/hql/ast/util/SyntheticAndFactory.java 2009-01-09 05:32:56 UTC (rev 15757)
@@ -36,11 +36,9 @@
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.util.StringHelper;
-import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.type.Type;
import org.hibernate.param.CollectionFilterKeyParameterSpecification;
-import antlr.ASTFactory;
import antlr.collections.AST;
import org.slf4j.Logger;
@@ -97,6 +95,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()
15 years, 3 months