Hibernate SVN: r11379 - branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-30 07:23:58 -0400 (Fri, 30 Mar 2007)
New Revision: 11379
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
Log:
HHH-2532 : BulkOperationCleanupAction#afterTransactionCompletion && JBC
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-30 11:23:48 UTC (rev 11378)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-30 11:23:58 UTC (rev 11379)
@@ -217,7 +217,9 @@
}
else {
// Otherwise, this is a primitive type.
- checkLhsIsNotCollection();
+ if ( ! CollectionProperties.isAnyCollectionProperty( propertyName ) ) {
+ checkLhsIsNotCollection();
+ }
dereferenceType = DEREF_PRIMITIVE;
initText();
}
17 years, 8 months
Hibernate SVN: r11378 - trunk/Hibernate3/src/org/hibernate/hql/ast/tree.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-30 07:23:48 -0400 (Fri, 30 Mar 2007)
New Revision: 11378
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
Log:
HHH-2534 : better improper HQL collection-dereference error message
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-29 22:10:22 UTC (rev 11377)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-30 11:23:48 UTC (rev 11378)
@@ -217,7 +217,9 @@
}
else {
// Otherwise, this is a primitive type.
- checkLhsIsNotCollection();
+ if ( ! CollectionProperties.isAnyCollectionProperty( propertyName ) ) {
+ checkLhsIsNotCollection();
+ }
dereferenceType = DEREF_PRIMITIVE;
initText();
}
17 years, 8 months
Hibernate SVN: r11377 - trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model.
by hibernate-commits@lists.jboss.org
Author: maulik
Date: 2007-03-29 18:10:22 -0400 (Thu, 29 Mar 2007)
New Revision: 11377
Modified:
trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelQueryPermutedIntegrationTest.java
Log:
fixes bugs regard setMaxResults and setFirstResult on ShardedQueryImpl
Modified: trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelQueryPermutedIntegrationTest.java
===================================================================
--- trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelQueryPermutedIntegrationTest.java 2007-03-29 22:10:03 UTC (rev 11376)
+++ trunk/HibernateExt/shards/src/test/org/hibernate/shards/integration/model/ModelQueryPermutedIntegrationTest.java 2007-03-29 22:10:22 UTC (rev 11377)
@@ -139,6 +139,20 @@
assertEquals(1, floors.size());
}
+ public void testSetMaxResults() {
+ String queryString = "from Floor";
+ Query query = session.createQuery(queryString).setMaxResults(1);
+ List<Floor> floors = query.list();
+ assertEquals(1, floors.size());
+ }
+
+ public void testSetFirstResultQuery() {
+ String queryString = "from Floor";
+ Query query = session.createQuery(queryString).setFirstResult(2);
+ List<Floor> floors = query.list();
+ assertEquals(2, floors.size());
+ }
+
public void xtestAggregating() throws Exception {
//TODO(maulik) make this test work
String queryString = "min(floor.number) from Floor floor";
17 years, 8 months
Hibernate SVN: r11376 - trunk/HibernateExt/shards/src/java/org/hibernate/shards/query.
by hibernate-commits@lists.jboss.org
Author: maulik
Date: 2007-03-29 18:10:03 -0400 (Thu, 29 Mar 2007)
New Revision: 11376
Modified:
trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java
trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java
Log:
fixes bugs regard setMaxResults and setFirstResult on ShardedQueryImpl
Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java 2007-03-29 19:36:33 UTC (rev 11375)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ExitOperationsQueryCollector.java 2007-03-29 22:10:03 UTC (rev 11376)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007 Google Inc.
+ * Copyright (C) 2006 Google Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,8 @@
package org.hibernate.shards.query;
import org.hibernate.shards.strategy.exit.ExitOperationsCollector;
+import org.hibernate.shards.strategy.exit.FirstResultExitOperation;
+import org.hibernate.shards.strategy.exit.MaxResultsExitOperation;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -29,15 +31,44 @@
* is to record a set of aggregation type operations to be executed on the
* combined results for a query executed on each shard.
*
+ * We do implement setMaxResults and setFirstResult as these operations do not
+ * require parsing the query string.
+ *
+ * {@inheritDoc}
+ *
* @author maulik(a)google.com (Maulik Shah)
*/
public class ExitOperationsQueryCollector implements ExitOperationsCollector {
+ // maximum number of results requested by the client
+ private Integer maxResults = null;
+
+ // index of the first result requested by the client
+ private Integer firstResult = null;
+
public List<Object> apply(List<Object> result) {
+ if (firstResult != null) {
+ result = new FirstResultExitOperation(firstResult).apply(result);
+ }
+ if (maxResults != null) {
+ result = new MaxResultsExitOperation(maxResults).apply(result);
+ }
+
return result;
}
public void setSessionFactory(SessionFactoryImplementor sessionFactoryImplementor) {
throw new UnsupportedOperationException();
}
+
+ public ExitOperationsCollector setMaxResults(int maxResults) {
+ this.maxResults = maxResults;
+ return this;
+ }
+
+ public ExitOperationsCollector setFirstResult(int firstResult) {
+ this.firstResult = firstResult;
+ return this;
+ }
+
}
Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java 2007-03-29 19:36:33 UTC (rev 11375)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/query/ShardedQueryImpl.java 2007-03-29 22:10:03 UTC (rev 11376)
@@ -261,27 +261,12 @@
}
public Query setMaxResults(int maxResults) {
- SetMaxResultsEvent event = new SetMaxResultsEvent(maxResults);
- for (Shard shard : shards) {
- if (shard.getQueryById(queryId) != null) {
- shard.getQueryById(queryId).setMaxResults(maxResults);
- } else {
- shard.addQueryEvent(queryId, event);
- }
- }
-
+ queryCollector.setMaxResults(maxResults);
return this;
}
public Query setFirstResult(int firstResult) {
- QueryEvent event = new SetFirstResultEvent(firstResult);
- for (Shard shard : shards) {
- if (shard.getQueryById(queryId) != null) {
- shard.getQueryById(queryId).setFirstResult(firstResult);
- } else {
- shard.addQueryEvent(queryId, event);
- }
- }
+ queryCollector.setFirstResult(firstResult);
return this;
}
17 years, 8 months
Hibernate SVN: r11375 - branches/Branch_3_2/Hibernate3/src/org/hibernate/action.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-29 15:36:33 -0400 (Thu, 29 Mar 2007)
New Revision: 11375
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/action/BulkOperationCleanupAction.java
Log:
HHH-2532 : BulkOperationCleanupAction#afterTransactionCompletion && JBC
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/action/BulkOperationCleanupAction.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/action/BulkOperationCleanupAction.java 2007-03-29 19:09:18 UTC (rev 11374)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/action/BulkOperationCleanupAction.java 2007-03-29 19:36:33 UTC (rev 11375)
@@ -2,14 +2,12 @@
package org.hibernate.action;
import org.hibernate.HibernateException;
-import org.hibernate.metadata.ClassMetadata;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import java.io.Serializable;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
@@ -108,6 +106,13 @@
}
public void afterTransactionCompletion(boolean success) throws HibernateException {
+ ///////////////////////////////////////////////////////////////////////
+ // HACK ALERT!!!!!
+ if ( session.getFactory().getSettings().getCacheProvider() instanceof org.hibernate.cache.OptimisticTreeCacheProvider
+ || session.getFactory().getSettings().getCacheProvider() instanceof org.hibernate.cache.TreeCacheProvider ) {
+ return;
+ }
+ ///////////////////////////////////////////////////////////////////////
evictEntityRegions();
evictCollectionRegions();
}
17 years, 8 months
Hibernate SVN: r11374 - trunk/Hibernate3/test/org/hibernate/test/hql.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-29 15:09:18 -0400 (Thu, 29 Mar 2007)
New Revision: 11374
Modified:
trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
Log:
HHH-2534 : better improper HQL collection-dereference error message
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 19:09:07 UTC (rev 11373)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 19:09:18 UTC (rev 11374)
@@ -13,6 +13,7 @@
import junit.framework.Test;
import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
@@ -34,6 +35,7 @@
import org.hibernate.hql.ast.tree.DotNode;
import org.hibernate.hql.ast.tree.IndexNode;
import org.hibernate.hql.ast.tree.SelectClause;
+import org.hibernate.hql.ast.tree.FromReferenceNode;
/**
* Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL.
@@ -46,27 +48,41 @@
super( x );
}
- protected boolean dropAfterFailure() {
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( HQLTest.class );
+ }
+
+ public boolean createSchema() {
return false;
}
+ public boolean recreateSchemaAfterFailure() {
+ return false;
+ }
+
protected void prepareTest() throws Exception {
super.prepareTest();
SelectClause.VERSION2_SQL = true;
DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = true;
+ DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = new DotNode.IllegalCollectionDereferenceExceptionBuilder() {
+ public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
+ throw new QueryException( "illegal syntax near collection: " + propertyName );
+ }
+ };
}
- public static Test suite() {
- return new FunctionalTestClassTestSuite( HQLTest.class );
- }
-
protected void cleanupTest() throws Exception {
SelectClause.VERSION2_SQL = false;
DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+ DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = DotNode.DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER;
super.cleanupTest();
}
- //FAILING TESTS:
+ public void testInvalidCollectionDereferencesFail() {
+ // should fail with the same exceptions (because of the DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER injection)
+ assertTranslation( "from Animal a where a.offspring.description = 'xyz'" );
+ assertTranslation( "from Animal a where a.offspring.father.description = 'xyz'" );
+ }
public void testSubComponentReferences() {
assertTranslation( "select c.address.zip.code from ComponentContainer c" );
17 years, 8 months
Hibernate SVN: r11373 - trunk/Hibernate3/test/org/hibernate/test/hql.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-29 15:09:07 -0400 (Thu, 29 Mar 2007)
New Revision: 11373
Modified:
trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-2534 : better improper HQL collection-dereference error message
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-03-29 19:08:53 UTC (rev 11372)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-03-29 19:09:07 UTC (rev 11373)
@@ -50,6 +50,9 @@
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* Tests the integration of the new AST parser into the loading of query results using
* the Hibernate persisters and loaders.
@@ -62,6 +65,8 @@
*/
public class ASTParserLoadingTest extends FunctionalTestCase {
+ private static final Log log = LogFactory.getLog( ASTParserLoadingTest.class );
+
private List createdAnimalIds = new ArrayList();
public ASTParserLoadingTest(String name) {
@@ -96,6 +101,52 @@
return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
}
+ public void testInvalidCollectionDereferencesFail() {
+ Session s = openSession();
+ s.beginTransaction();
+
+ // control group...
+ s.createQuery( "from Animal a join a.offspring o where o.description = 'xyz'" ).list();
+ s.createQuery( "from Animal a join a.offspring o where o.father.description = 'xyz'" ).list();
+ s.createQuery( "from Animal a join a.offspring o order by o.description" ).list();
+ s.createQuery( "from Animal a join a.offspring o order by o.father.description" ).list();
+
+ try {
+ s.createQuery( "from Animal a where a.offspring.description = 'xyz'" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a where a.offspring.father.description = 'xyz'" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a order by a.offspring.description" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a order by a.offspring.father.description" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ s.getTransaction().commit();
+ s.close();
+ }
+
/**
* Copied from {@link HQLTest#testConcatenation}
*/
17 years, 8 months
Hibernate SVN: r11372 - trunk/Hibernate3/src/org/hibernate/hql/ast/tree.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-29 15:08:53 -0400 (Thu, 29 Mar 2007)
New Revision: 11372
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
Log:
HHH-2534 : better improper HQL collection-dereference error message
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-29 19:08:40 UTC (rev 11371)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-29 19:08:53 UTC (rev 11372)
@@ -32,9 +32,21 @@
///////////////////////////////////////////////////////////////////////////
// USED ONLY FOR REGRESSION TESTING!!!!
+ //
+ // todo : obviously get rid of all this junk ;)
///////////////////////////////////////////////////////////////////////////
public static boolean useThetaStyleImplicitJoins = false;
public static boolean REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+ public static interface IllegalCollectionDereferenceExceptionBuilder {
+ public QueryException buildIllegalCollectionDereferenceException(String collectionPropertyName, FromReferenceNode lhs);
+ }
+ public static final IllegalCollectionDereferenceExceptionBuilder DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER = new IllegalCollectionDereferenceExceptionBuilder() {
+ public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
+ String lhsPath = ASTUtil.getPathText( lhs );
+ return new QueryException( "illegal attempt to dereference collection [" + lhsPath + "] with element property reference [" + propertyName + "]" );
+ }
+ };
+ public static IllegalCollectionDereferenceExceptionBuilder ILLEGAL_COLL_DEREF_EXCP_BUILDER = DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER;
///////////////////////////////////////////////////////////////////////////
private static final Log log = LogFactory.getLog( DotNode.class );
@@ -186,24 +198,26 @@
return;
}
- // The property is a component...
if ( propertyType.isComponentType() ) {
+ // The property is a component...
checkLhsIsNotCollection();
dereferenceComponent( parent );
initText();
}
- // The property is another class..
else if ( propertyType.isEntityType() ) {
+ // The property is another class..
checkLhsIsNotCollection();
dereferenceEntity( ( EntityType ) propertyType, implicitJoin, classAlias, generateJoin, parent );
initText();
}
- // The property is a collection...
else if ( propertyType.isCollectionType() ) {
+ // The property is a collection...
checkLhsIsNotCollection();
dereferenceCollection( ( CollectionType ) propertyType, implicitJoin, false, classAlias, parent );
}
- else { // Otherwise, this is a primitive type.
+ else {
+ // Otherwise, this is a primitive type.
+ checkLhsIsNotCollection();
dereferenceType = DEREF_PRIMITIVE;
initText();
}
@@ -493,9 +507,7 @@
private void checkLhsIsNotCollection() throws SemanticException {
if ( getLhs().getDataType() != null && getLhs().getDataType().isCollectionType() ) {
- // TODO : this exactly matches the output of the old parser, but we might want to be more explicit here
- // that will however cause regression issues in HQLTest
- throw new SemanticException( "illegal syntax near collection: " + propertyName );
+ throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() );
}
}
private void dereferenceComponent(AST parent) {
17 years, 8 months
Hibernate SVN: r11371 - in branches/Branch_3_2/Hibernate3: test/org/hibernate/test/hql and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-03-29 15:08:40 -0400 (Thu, 29 Mar 2007)
New Revision: 11371
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
Log:
HHH-2534 : better improper HQL collection-dereference error message
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-29 17:39:59 UTC (rev 11370)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2007-03-29 19:08:40 UTC (rev 11371)
@@ -25,18 +25,28 @@
/**
* Represents a reference to a property or alias expression. This should duplicate the relevant behaviors in
* PathExpressionParser.
- * <hr>
- * User: josh<br>
- * Date: Dec 16, 2003<br>
- * Time: 8:03:09 AM
+ *
+ * @author Joshua Davis
*/
public class DotNode extends FromReferenceNode implements DisplayableNode, SelectExpression {
///////////////////////////////////////////////////////////////////////////
// USED ONLY FOR REGRESSION TESTING!!!!
+ //
+ // todo : obviously get rid of all this junk ;)
///////////////////////////////////////////////////////////////////////////
public static boolean useThetaStyleImplicitJoins = false;
public static boolean REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+ public static interface IllegalCollectionDereferenceExceptionBuilder {
+ public QueryException buildIllegalCollectionDereferenceException(String collectionPropertyName, FromReferenceNode lhs);
+ }
+ public static final IllegalCollectionDereferenceExceptionBuilder DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER = new IllegalCollectionDereferenceExceptionBuilder() {
+ public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
+ String lhsPath = ASTUtil.getPathText( lhs );
+ return new QueryException( "illegal attempt to dereference collection [" + lhsPath + "] with element property reference [" + propertyName + "]" );
+ }
+ };
+ public static IllegalCollectionDereferenceExceptionBuilder ILLEGAL_COLL_DEREF_EXCP_BUILDER = DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER;
///////////////////////////////////////////////////////////////////////////
private static final Log log = LogFactory.getLog( DotNode.class );
@@ -188,24 +198,26 @@
return;
}
- // The property is a component...
if ( propertyType.isComponentType() ) {
+ // The property is a component...
checkLhsIsNotCollection();
dereferenceComponent( parent );
initText();
}
- // The property is another class..
else if ( propertyType.isEntityType() ) {
+ // The property is another class..
checkLhsIsNotCollection();
dereferenceEntity( ( EntityType ) propertyType, implicitJoin, classAlias, generateJoin, parent );
initText();
}
- // The property is a collection...
else if ( propertyType.isCollectionType() ) {
+ // The property is a collection...
checkLhsIsNotCollection();
dereferenceCollection( ( CollectionType ) propertyType, implicitJoin, false, classAlias, parent );
}
- else { // Otherwise, this is a primitive type.
+ else {
+ // Otherwise, this is a primitive type.
+ checkLhsIsNotCollection();
dereferenceType = DEREF_PRIMITIVE;
initText();
}
@@ -495,11 +507,10 @@
private void checkLhsIsNotCollection() throws SemanticException {
if ( getLhs().getDataType() != null && getLhs().getDataType().isCollectionType() ) {
- // TODO : this exactly matches the output of the old parser, but we might want to be more explicit here
- // that will however cause regression issues in HQLTest
- throw new SemanticException( "illegal syntax near collection: " + propertyName );
+ throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() );
}
}
+
private void dereferenceComponent(AST parent) {
dereferenceType = DEREF_COMPONENT;
setPropertyNameAndPath( parent );
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-03-29 17:39:59 UTC (rev 11370)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-03-29 19:08:40 UTC (rev 11371)
@@ -50,6 +50,9 @@
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* Tests the integration of the new AST parser into the loading of query results using
* the Hibernate persisters and loaders.
@@ -62,6 +65,8 @@
*/
public class ASTParserLoadingTest extends FunctionalTestCase {
+ private static final Log log = LogFactory.getLog( ASTParserLoadingTest.class );
+
private List createdAnimalIds = new ArrayList();
public ASTParserLoadingTest(String name) {
@@ -96,6 +101,52 @@
return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
}
+ public void testInvalidCollectionDereferencesFail() {
+ Session s = openSession();
+ s.beginTransaction();
+
+ // control group...
+ s.createQuery( "from Animal a join a.offspring o where o.description = 'xyz'" ).list();
+ s.createQuery( "from Animal a join a.offspring o where o.father.description = 'xyz'" ).list();
+ s.createQuery( "from Animal a join a.offspring o order by o.description" ).list();
+ s.createQuery( "from Animal a join a.offspring o order by o.father.description" ).list();
+
+ try {
+ s.createQuery( "from Animal a where a.offspring.description = 'xyz'" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a where a.offspring.father.description = 'xyz'" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a order by a.offspring.description" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ try {
+ s.createQuery( "from Animal a order by a.offspring.father.description" ).list();
+ fail( "illegal collection dereference semantic did not cause failure" );
+ }
+ catch( QueryException qe ) {
+ log.trace( "expected failure...", qe );
+ }
+
+ s.getTransaction().commit();
+ s.close();
+ }
+
/**
* Copied from {@link HQLTest#testConcatenation}
*/
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 17:39:59 UTC (rev 11370)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2007-03-29 19:08:40 UTC (rev 11371)
@@ -13,6 +13,7 @@
import junit.framework.Test;
import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.HSQLDialect;
@@ -34,6 +35,7 @@
import org.hibernate.hql.ast.tree.DotNode;
import org.hibernate.hql.ast.tree.IndexNode;
import org.hibernate.hql.ast.tree.SelectClause;
+import org.hibernate.hql.ast.tree.FromReferenceNode;
/**
* Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL.
@@ -46,28 +48,44 @@
super( x );
}
- protected boolean dropAfterFailure() {
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( HQLTest.class );
+ }
+
+ public boolean createSchema() {
return false;
}
+ public boolean recreateSchemaAfterFailure() {
+ return false;
+ }
+
protected void prepareTest() throws Exception {
super.prepareTest();
SelectClause.VERSION2_SQL = true;
DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = true;
+ DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = new DotNode.IllegalCollectionDereferenceExceptionBuilder() {
+ public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) {
+ throw new QueryException( "illegal syntax near collection: " + propertyName );
+ }
+ };
}
- public static Test suite() {
- return new FunctionalTestClassTestSuite( HQLTest.class );
- }
-
protected void cleanupTest() throws Exception {
SelectClause.VERSION2_SQL = false;
DotNode.REGRESSION_STYLE_JOIN_SUPPRESSION = false;
+ DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = DotNode.DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER;
super.cleanupTest();
}
//FAILING TESTS:
+ public void testInvalidCollectionDereferencesFail() {
+ // should fail with the same exceptions (because of the DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER)
+ assertTranslation( "from Animal a where a.offspring.description = 'xyz'" );
+ assertTranslation( "from Animal a where a.offspring.father.description = 'xyz'" );
+ }
+
public void testSubComponentReferences() {
assertTranslation( "select c.address.zip.code from ComponentContainer c" );
assertTranslation( "select c.address.zip from ComponentContainer c" );
17 years, 8 months
Hibernate SVN: r11370 - trunk/HibernateExt/validator/src/test/org/hibernate/validator/test.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-29 13:39:59 -0400 (Thu, 29 Mar 2007)
New Revision: 11370
Modified:
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/Address.java
trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/ValidatorTest.java
Log:
minor test
Modified: trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/Address.java
===================================================================
--- trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/Address.java 2007-03-29 15:55:41 UTC (rev 11369)
+++ trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/Address.java 2007-03-29 17:39:59 UTC (rev 11370)
@@ -7,6 +7,7 @@
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;
import org.hibernate.validator.Range;
+import org.hibernate.validator.Max;
/**
* @author Gavin King
@@ -25,7 +26,8 @@
private long id;
private boolean internalValid = true;
@Range(min = -2, max = 50, message = "{floor.out.of.range} (escaping #{el})")
- public int floor;
+ @Max(70)
+ public int floor;
public String getCountry() {
return country;
Modified: trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/ValidatorTest.java
===================================================================
--- trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-03-29 15:55:41 UTC (rev 11369)
+++ trunk/HibernateExt/validator/src/test/org/hibernate/validator/test/ValidatorTest.java 2007-03-29 17:39:59 UTC (rev 11370)
@@ -53,7 +53,7 @@
a.setCountry( "France" );
a.floor = 4000;
validationMessages = classValidator.getInvalidValues( a );
- assertEquals( 1, validationMessages.length );
+ assertEquals( 2, validationMessages.length );
assertEquals(
"Floor cannot " + ESCAPING_EL
+ " be lower that -2 and greater than 50 " + ESCAPING_EL,
17 years, 8 months