Hibernate SVN: r20876 - in core/branches/Branch_3_3_2_GA_CP: core/src/main/java/org/hibernate/tuple/entity and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-01-11 04:59:12 -0500 (Tue, 11 Jan 2011)
New Revision: 20876
Added:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Car.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/EntityNameFromSubClassTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Person.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.hbm.xml
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.java
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/Instantiator.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java
Log:
JBPAPP-5581 HHH-4036: EntityMetamodel entityNameByInheritenceClassNameMap field used inconsistently
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/Instantiator.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/Instantiator.java 2011-01-11 09:37:46 UTC (rev 20875)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/Instantiator.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -56,7 +56,7 @@
* or component which this Instantiator instantiates.
*
* @param object The object to be checked.
- * @return True is the object does respresent an instance of the underlying
+ * @return True is the object does represent an instance of the underlying
* entity/component.
*/
public boolean isInstance(Object object);
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java 2011-01-11 09:37:46 UTC (rev 20875)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -98,7 +98,7 @@
private final boolean hasInsertGeneratedValues;
private final boolean hasUpdateGeneratedValues;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- private final Map propertyIndexes = new HashMap();
+ private final Map<String,Integer> propertyIndexes = new HashMap<String,Integer>();
private final boolean hasCollections;
private final boolean hasMutableProperties;
private final boolean hasLazyProperties;
@@ -122,7 +122,7 @@
private final boolean inherited;
private final boolean hasSubclasses;
private final Set subclassEntityNames = new HashSet();
- private final Map entityNameByInheritenceClassNameMap = new HashMap();
+ private final Map<Class<?>,String> entityNameByInheritenceClassMap = new HashMap<Class<?>,String>();
private final EntityEntityModeToTuplizerMapping tuplizerMapping;
@@ -312,11 +312,11 @@
subclassEntityNames.add( name );
if ( persistentClass.hasPojoRepresentation() ) {
- entityNameByInheritenceClassNameMap.put( persistentClass.getMappedClass(), persistentClass.getEntityName() );
+ entityNameByInheritenceClassMap.put( persistentClass.getMappedClass(), persistentClass.getEntityName() );
iter = persistentClass.getSubclassIterator();
while ( iter.hasNext() ) {
final PersistentClass pc = ( PersistentClass ) iter.next();
- entityNameByInheritenceClassNameMap.put( pc.getMappedClass(), pc.getEntityName() );
+ entityNameByInheritenceClassMap.put( pc.getMappedClass(), pc.getEntityName() );
}
}
@@ -490,7 +490,7 @@
}
public Integer getPropertyIndexOrNull(String propertyName) {
- return (Integer) propertyIndexes.get( propertyName );
+ return propertyIndexes.get( propertyName );
}
public boolean hasCollections() {
@@ -570,13 +570,13 @@
}
/**
- * Return the entity-name mapped to the given class within our inheritence hierarchy, if any.
+ * Return the entity-name mapped to the given class within our inheritance hierarchy, if any.
*
* @param inheritenceClass The class for which to resolve the entity-name.
* @return The mapped entity-name, or null if no such mapping was found.
*/
public String findEntityNameByEntityClass(Class inheritenceClass) {
- return ( String ) entityNameByInheritenceClassNameMap.get( inheritenceClass.getName() );
+ return entityNameByInheritenceClassMap.get( inheritenceClass );
}
public String toString() {
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Car.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Car.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Car.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -0,0 +1,10 @@
+// $Id: Car.java 7087 2005-06-08 18:23:44Z steveebersole $
+package org.hibernate.test.entityname;
+
+/**
+ * Implementation of Car.
+ *
+ * @author Steve Ebersole
+ */
+public class Car extends Vehicle {
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/EntityNameFromSubClassTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/EntityNameFromSubClassTest.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/EntityNameFromSubClassTest.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -0,0 +1,41 @@
+package org.hibernate.test.entityname;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+/**
+ *
+ * @author stliu
+ *
+ */
+public class EntityNameFromSubClassTest extends FunctionalTestCase {
+
+ public EntityNameFromSubClassTest(String string) {
+ super(string);
+ }
+
+ public void testEntityName() {
+ Session s = openSession();
+ s.beginTransaction();
+ Person stliu = new Person();
+ stliu.setName("stliu");
+ Car golf = new Car();
+ golf.setOwner("stliu");
+ stliu.getCars().add(golf);
+ s.save(stliu);
+ s.getTransaction().commit();
+ s.close();
+
+ s=openSession();
+ s.beginTransaction();
+ Person p = (Person)s.get(Person.class, stliu.getId());
+ assertEquals(1, p.getCars().size());
+ assertEquals(Car.class, p.getCars().iterator().next().getClass());
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public String[] getMappings() {
+ return new String[] { "entityname/Vehicle.hbm.xml" };
+ }
+
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Person.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Person.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Person.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -0,0 +1,39 @@
+package org.hibernate.test.entityname;
+
+import java.util.HashSet;
+import java.util.Set;
+/**
+ *
+ * @author stliu
+ *
+ */
+public class Person {
+ private Long id;
+ private String Name;
+ private Set cars = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return Name;
+ }
+
+ public void setName(String name) {
+ Name = name;
+ }
+
+ public Set getCars() {
+ return cars;
+ }
+
+ public void setCars(Set cars) {
+ this.cars = cars;
+ }
+
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.hbm.xml (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.hbm.xml 2011-01-11 09:59:12 UTC (rev 20876)
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.entityname">
+
+ <!-- Vehicle represents an abstract root of a union-subclass hierarchy -->
+ <class name="Vehicle" abstract="true" entity-name="VEHICLE" discriminator-value="V">
+ <id name="id" access="field" type="long">
+ <generator class="increment"/>
+ </id>
+ <discriminator column="TYPE" type="string" />
+ <property name="vin" type="string"/>
+ <property name="owner" type="string"/>
+
+ <!-- Car represents a concrete leaf of a union-subclass hierarchy with no concrete super -->
+ <subclass name="Car" entity-name="CAR" discriminator-value="C"/>
+ </class>
+ <class name="Person">
+ <id name="id">
+ <generator class="increment" />
+ </id>
+ <property name="name" />
+ <set name="cars" cascade="all">
+ <key column="car_id"/>
+ <one-to-many entity-name="VEHICLE"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/entityname/Vehicle.java 2011-01-11 09:59:12 UTC (rev 20876)
@@ -0,0 +1,29 @@
+// $Id: Vehicle.java 7087 2005-06-08 18:23:44Z steveebersole $
+package org.hibernate.test.entityname;
+
+/**
+ * Implementation of Vehicle.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class Vehicle {
+ private Long id;
+ private String vin;
+ private String owner;
+
+ public String getVin() {
+ return vin;
+ }
+
+ public void setVin(String vin) {
+ this.vin = vin;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+}
14 years
Hibernate SVN: r20875 - in core/branches/Branch_3_3_2_GA_CP: core/src/main/java/org/hibernate/hql/classic and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-01-11 04:37:46 -0500 (Tue, 11 Jan 2011)
New Revision: 20875
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/antlr/hql.g
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/classic/FromParser.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
Log:
JBPAPP-5405 HHH-5727 : Collection member declaration not handling optional AS in HQL.
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/antlr/hql.g
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/antlr/hql.g 2011-01-08 16:10:57 UTC (rev 20874)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/antlr/hql.g 2011-01-11 09:37:46 UTC (rev 20875)
@@ -355,7 +355,7 @@
;
inCollectionDeclaration!
- : IN! OPEN! p:path CLOSE! a:alias {
+ : IN! OPEN! p:path CLOSE! a:asAlias {
#inCollectionDeclaration = #([JOIN, "join"], [INNER, "inner"], #p, #a);
}
;
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/classic/FromParser.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/classic/FromParser.java 2011-01-08 16:10:57 UTC (rev 20874)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/classic/FromParser.java 2011-01-11 09:37:46 UTC (rev 20875)
@@ -51,7 +51,14 @@
private boolean afterJoinType;
private int joinType;
private boolean afterFetch;
-
+
+ //support collection member declarations
+ //e.g. "from Customer c, in(c.orders) as o"
+ private boolean memberDeclarations;
+ private boolean expectingPathExpression;
+ private boolean afterMemberDeclarations;
+ private String collectionName;
+
private static final int NONE = -666;
private static final Map JOIN_TYPES = new HashMap();
@@ -113,15 +120,34 @@
afterClass = true;
}
else if ( lcToken.equals( "in" ) ) {
- if ( !expectingIn ) throw new QueryException( "unexpected token: in" );
- afterIn = true;
- expectingIn = false;
+ if (alias == null ){
+ memberDeclarations = true;
+ afterMemberDeclarations = false;
+ }
+ else if ( !expectingIn ) {
+ throw new QueryException( "unexpected token: in" );
+ } else {
+ afterIn = true;
+ expectingIn = false;
+ }
+
}
else if ( lcToken.equals( "as" ) ) {
if ( !expectingAs ) throw new QueryException( "unexpected token: as" );
afterAs = true;
expectingAs = false;
}
+ else if ( "(".equals( token ) ){
+ if( !memberDeclarations ) throw new QueryException( "unexpected token: (" );
+ //TODO alias should be null here
+ expectingPathExpression = true;
+
+ }
+ else if ( ")".equals( token ) ){
+// memberDeclarations = false;
+// expectingPathExpression = false;
+ afterMemberDeclarations = true;
+ }
else {
if ( afterJoinType ) throw new QueryException( "join expected: " + token );
@@ -141,6 +167,9 @@
if ( entityName != null ) {
q.setAliasName( token, entityName );
}
+ else if(collectionName != null ) {
+ q.setAliasName( token, collectionName );
+ }
else {
throw new QueryException( "unexpected: as " + token );
}
@@ -148,6 +177,10 @@
expectingJoin = true;
expectingAs = false;
entityName = null;
+ collectionName = null;
+ memberDeclarations = false;
+ expectingPathExpression = false;
+ afterMemberDeclarations = false;
}
else if ( afterIn ) {
@@ -180,6 +213,16 @@
afterClass = false;
expectingJoin = true;
}
+ else if( memberDeclarations && expectingPathExpression ){
+ expectingAs = true;
+ peParser.setJoinType( JoinFragment.INNER_JOIN );
+ peParser.setUseThetaStyleJoin( false );
+ ParserHelper.parse( peParser, q.unalias( token ), ParserHelper.PATH_SEPARATORS, q );
+ if ( !peParser.isCollectionValued() ) throw new QueryException( "path expression did not resolve to collection: " + token );
+ collectionName = peParser.addFromCollection( q );
+ expectingPathExpression = false;
+ memberDeclarations = false;
+ }
else {
// handle a path expression or class name that
@@ -238,6 +281,7 @@
public void start(QueryTranslatorImpl q) {
entityName = null;
+ collectionName = null;
alias = null;
afterIn = false;
afterAs = false;
@@ -245,10 +289,19 @@
expectingJoin = false;
expectingIn = false;
expectingAs = false;
+ memberDeclarations = false;
+ expectingPathExpression = false;
+ afterMemberDeclarations = false;
joinType = NONE;
}
public void end(QueryTranslatorImpl q) {
+ if( afterMemberDeclarations ){
+ //The exception throwned by the AST query translator contains the error token location, respensent by line and colum,
+ //but it hard to get that info here.
+ throw new QueryException("alias not specified for IN");
+ }
+
}
}
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2011-01-08 16:10:57 UTC (rev 20874)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/hql/HQLTest.java 2011-01-11 09:37:46 UTC (rev 20875)
@@ -103,6 +103,18 @@
public void testJoinFetchCollectionOfValues() {
assertTranslation( "select h from Human as h join fetch h.nickNames" );
}
+ public void testCollectionMemberDeclarations() {
+ assertTranslation( "from Customer c, in(c.orders) o" );
+ assertTranslation( "from Customer c, in(c.orders) as o" );
+ assertTranslation( "select c.name from Customer c, in(c.orders) as o where c.id = o.id.customerId" );
+ }
+ public void testCollectionMemberDeclarationsFailureExpected(){
+ // both these two query translators throw exeptions for this HQL since
+ // IN asks an alias, but the difference is that the error message from AST
+ // contains the error token location (by lines and columns), which is hardly
+ // to get from Classic query translator --stliu
+ assertTranslation( "from Customer c, in(c.orders)" );
+ }
public void testCollectionJoinsInSubselect() {
// caused by some goofiness in FromElementFactory that tries to
14 years
Hibernate SVN: r20874 - in core/branches/Branch_3_2_4_SP1_CP: test/org/hibernate/test and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2011-01-08 11:10:57 -0500 (Sat, 08 Jan 2011)
New Revision: 20874
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Customer.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Employee.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Joined.hbm.xml
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Person.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/User.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/filter-defs.hbm.xml
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java
Log:
JBPAPP-5733 HHH-2470 Use of session.createSQLQuery causes memory leak
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java 2010-12-03 09:26:07 UTC (rev 20873)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -17,6 +17,7 @@
public class NativeSQLQueryCollectionReturn extends NativeSQLQueryNonScalarReturn {
private String ownerEntityName;
private String ownerProperty;
+ private final int hashCode;
/**
* Construct a native-sql return representing a collection initializer
@@ -38,6 +39,7 @@
super( alias, propertyResults, lockMode );
this.ownerEntityName = ownerEntityName;
this.ownerProperty = ownerProperty;
+ this.hashCode = determineHashCode();
}
/**
@@ -57,4 +59,36 @@
public String getOwnerProperty() {
return ownerProperty;
}
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+ if ( !super.equals( o ) ) {
+ return false;
+ }
+
+ NativeSQLQueryCollectionReturn that = ( NativeSQLQueryCollectionReturn ) o;
+
+ if ( ownerEntityName != null ? !ownerEntityName.equals( that.ownerEntityName ) : that.ownerEntityName != null ) {
+ return false;
+ }
+ if ( ownerProperty != null ? !ownerProperty.equals( that.ownerProperty ) : that.ownerProperty != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+ private int determineHashCode() {
+ int result = super.hashCode();
+ result = 31 * result + ( ownerEntityName != null ? ownerEntityName.hashCode() : 0 );
+ result = 31 * result + ( ownerProperty != null ? ownerProperty.hashCode() : 0 );
+ return result;
+ }
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java 2010-12-03 09:26:07 UTC (rev 20873)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -14,6 +14,7 @@
public class NativeSQLQueryJoinReturn extends NativeSQLQueryNonScalarReturn {
private String ownerAlias;
private String ownerProperty;
+ private final int hashCode;
/**
* Construct a return descriptor representing some form of fetch.
@@ -33,6 +34,7 @@
super( alias, propertyResults, lockMode );
this.ownerAlias = ownerAlias;
this.ownerProperty = ownerProperty;
+ this.hashCode = determineHashCode();
}
/**
@@ -53,4 +55,37 @@
public String getOwnerProperty() {
return ownerProperty;
}
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+ if ( !super.equals( o ) ) {
+ return false;
+ }
+
+ NativeSQLQueryJoinReturn that = ( NativeSQLQueryJoinReturn ) o;
+
+ if ( ownerAlias != null ? !ownerAlias.equals( that.ownerAlias ) : that.ownerAlias != null ) {
+ return false;
+ }
+ if ( ownerProperty != null ? !ownerProperty.equals( that.ownerProperty ) : that.ownerProperty != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private int determineHashCode() {
+ int result = super.hashCode();
+ result = 31 * result + ( ownerAlias != null ? ownerAlias.hashCode() : 0 );
+ result = 31 * result + ( ownerProperty != null ? ownerProperty.hashCode() : 0 );
+ return result;
+ }
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java 2010-12-03 09:26:07 UTC (rev 20873)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -19,6 +19,7 @@
private final String alias;
private final LockMode lockMode;
private final Map propertyResults = new HashMap();
+ private final int hashCode;
/**
* Constructs some form of non-scalar return descriptor
@@ -36,6 +37,7 @@
if ( propertyResults != null ) {
this.propertyResults.putAll( propertyResults );
}
+ this.hashCode = determineHashCode();
}
/**
@@ -64,4 +66,38 @@
public Map getPropertyResultsMap() {
return Collections.unmodifiableMap( propertyResults );
}
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private int determineHashCode() {
+ int result = alias != null ? alias.hashCode() : 0;
+ result = 31 * result + ( getClass().getName().hashCode() );
+ result = 31 * result + ( lockMode != null ? lockMode.hashCode() : 0 );
+ result = 31 * result + ( propertyResults != null ? propertyResults.hashCode() : 0 );
+ return result;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ NativeSQLQueryNonScalarReturn that = ( NativeSQLQueryNonScalarReturn ) o;
+
+ if ( alias != null ? !alias.equals( that.alias ) : that.alias != null ) {
+ return false;
+ }
+ if ( lockMode != null ? !lockMode.equals( that.lockMode ) : that.lockMode != null ) {
+ return false;
+ }
+ if ( propertyResults != null ? !propertyResults.equals( that.propertyResults ) : that.propertyResults != null ) {
+ return false;
+ }
+
+ return true;
+ }
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java 2010-12-03 09:26:07 UTC (rev 20873)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -14,6 +14,7 @@
*/
public class NativeSQLQueryRootReturn extends NativeSQLQueryNonScalarReturn {
private String returnEntityName;
+ private final int hashCode;
/**
* Construct a return representing an entity returned at the root
@@ -37,6 +38,7 @@
public NativeSQLQueryRootReturn(String alias, String entityName, Map propertyResults, LockMode lockMode) {
super( alias, propertyResults, lockMode );
this.returnEntityName = entityName;
+ this.hashCode = determineHashCode();
}
@@ -48,5 +50,34 @@
public String getReturnEntityName() {
return returnEntityName;
}
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+ if ( ! super.equals( o ) ) {
+ return false;
+ }
+ NativeSQLQueryRootReturn that = ( NativeSQLQueryRootReturn ) o;
+
+ if ( returnEntityName != null ? !returnEntityName.equals( that.returnEntityName ) : that.returnEntityName != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private int determineHashCode() {
+ int result = super.hashCode();
+ result = 31 * result + ( returnEntityName != null ? returnEntityName.hashCode() : 0 );
+ return result;
+ }
+
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java 2010-12-03 09:26:07 UTC (rev 20873)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -10,10 +10,12 @@
public class NativeSQLQueryScalarReturn implements NativeSQLQueryReturn {
private Type type;
private String columnAlias;
+ private final int hashCode;
public NativeSQLQueryScalarReturn(String alias, Type type) {
this.type = type;
this.columnAlias = alias;
+ this.hashCode = determineHashCode();
}
public String getColumnAlias() {
@@ -23,5 +25,35 @@
public Type getType() {
return type;
}
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+ NativeSQLQueryScalarReturn that = ( NativeSQLQueryScalarReturn ) o;
+
+ if ( columnAlias != null ? !columnAlias.equals( that.columnAlias ) : that.columnAlias != null ) {
+ return false;
+ }
+ if ( type != null ? !type.equals( that.type ) : that.type != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private int determineHashCode() {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + ( getClass().getName().hashCode() );
+ result = 31 * result + ( columnAlias != null ? columnAlias.hashCode() : 0 );
+ return result;
+ }
+
}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Customer.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Customer.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Customer.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+/**
+ * Leaf subclass
+ *
+ * @author Steve Ebersole
+ */
+public class Customer extends User {
+ private String company;
+
+ protected Customer() {
+ super();
+ }
+
+ public Customer(String name, char sex, String username, String company) {
+ super( name, sex, username );
+ this.company = company;
+ }
+
+ public String getCompany() {
+ return company;
+ }
+
+ public void setCompany(String company) {
+ this.company = company;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Employee.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Employee.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Employee.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,53 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+import java.util.Date;
+
+/**
+ * Leaf subclass
+ *
+ * @author Steve Ebersole
+ */
+public class Employee extends User {
+ private Date hireDate;
+
+ protected Employee() {
+ super();
+ }
+
+ public Employee(String name, char sex, String username, Date hireDate) {
+ super( name, sex, username );
+ this.hireDate = hireDate;
+ }
+
+ public Date getHireDate() {
+ return hireDate;
+ }
+
+ public void setHireDate(Date hireDate) {
+ this.hireDate = hireDate;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Joined.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Joined.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Joined.hbm.xml 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ ~
+ -->
+
+<!DOCTYPE hibernate-mapping
+ SYSTEM
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.queryplan">
+ <class name="Person" table="FILTER_HQL_JOINED_PERSON">
+ <id column="ID" name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <property name="sex" column="SEX_CODE" type="char"/>
+ <joined-subclass name="User" table="FILTER_HQL_JOINED_USER">
+ <key column="USER_ID"/>
+ <property name="username" type="string"/>
+ <joined-subclass name="Employee" table="FILTER_HQL_JOINED_EMP">
+ <key column="EMP_ID"/>
+ <property name="hireDate" type="date"/>
+ </joined-subclass>
+ <joined-subclass name="Customer" table="FILTER_HQL_JOINED_CUST">
+ <key column="CUST_ID"/>
+ <property name="company" type="string"/>
+ </joined-subclass>
+ </joined-subclass>
+ <filter name="sex"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+import org.hibernate.engine.query.NativeSQLQueryPlan;
+import org.hibernate.engine.query.QueryPlanCache;
+import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryScalarReturn;
+import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.type.TypeFactory;
+
+/**
+ * Tests equals() for NativeSQLQueryReturn implementations.
+ *
+ * @author Michael Stevens
+ */
+public class NativeSQLQueryPlanEqualsTest extends FunctionalTestCase {
+ public NativeSQLQueryPlanEqualsTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] {};
+ }
+
+ public void testNativeSQLQuerySpecEquals() {
+ QueryPlanCache cache = new QueryPlanCache(sfi());
+ NativeSQLQuerySpecification firstSpec = createSpec();
+
+ NativeSQLQuerySpecification secondSpec = createSpec();
+
+ NativeSQLQueryPlan firstPlan = cache.getNativeSQLQueryPlan(firstSpec);
+ NativeSQLQueryPlan secondPlan = cache.getNativeSQLQueryPlan(secondSpec);
+
+ assertEquals(firstPlan, secondPlan);
+
+ }
+
+ private NativeSQLQuerySpecification createSpec() {
+ String blah = "blah";
+ String select = "select blah from blah";
+ NativeSQLQueryReturn[] queryReturns =
+ new NativeSQLQueryScalarReturn[] {new NativeSQLQueryScalarReturn(blah, TypeFactory.basic( "int" ) ) };
+ NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(select,
+ queryReturns, null);
+ return spec;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,267 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.hibernate.LockMode;
+import org.hibernate.engine.query.sql.NativeSQLQueryCollectionReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryJoinReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryRootReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryScalarReturn;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.type.TypeFactory;
+
+/**
+ * Tests equals() and hashCode() for NativeSQLQueryReturn implementations.
+ *
+ * @author Gail Badner
+ */
+public class NativeSQLQueryReturnEqualsAndHashCodeTest extends FunctionalTestCase {
+ public NativeSQLQueryReturnEqualsAndHashCodeTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] {};
+ }
+
+ public void testNativeSQLQueryScalarReturn() {
+ NativeSQLQueryScalarReturn typeNoAlias = new NativeSQLQueryScalarReturn( null, TypeFactory.basic( "int" ) );
+ NativeSQLQueryScalarReturn aliasNoType = new NativeSQLQueryScalarReturn( "abc", null );
+ NativeSQLQueryScalarReturn aliasTypeInt = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "int" ) );
+ NativeSQLQueryScalarReturn aliasTypeLong = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "long" ) );
+ NativeSQLQueryScalarReturn aliasTypeLongClass = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( Long.class.getName() ) );
+ NativeSQLQueryScalarReturn aliasTypeString = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "string" ) );
+ NativeSQLQueryScalarReturn aliasTypeStringClass = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( String.class.getName() ) );
+
+ check( false, typeNoAlias, aliasNoType );
+ check( false, typeNoAlias, aliasTypeInt );
+ check( false, typeNoAlias, aliasTypeLong );
+ check( false, typeNoAlias, aliasTypeLongClass );
+ check( false, typeNoAlias, aliasTypeString );
+ check( false, typeNoAlias, aliasTypeStringClass );
+
+ check( false, aliasNoType, aliasTypeInt );
+ check( false, aliasNoType, aliasTypeLong );
+ check( false, aliasNoType, aliasTypeLongClass );
+ check( false, aliasNoType, aliasTypeString );
+ check( false, aliasNoType, aliasTypeStringClass );
+
+ check( false, aliasTypeInt, aliasTypeLong );
+ check( false, aliasTypeInt, aliasTypeLongClass );
+ check( false, aliasTypeInt, aliasTypeString );
+ check( false, aliasTypeInt, aliasTypeStringClass );
+
+ check( true, aliasTypeLong, aliasTypeLongClass );
+ check( false, aliasTypeLong, aliasTypeString );
+ check( false, aliasTypeLong, aliasTypeStringClass );
+
+ check( false, aliasTypeLongClass, aliasTypeString );
+ check( false, aliasTypeLongClass, aliasTypeStringClass );
+
+ check( true, aliasTypeString, aliasTypeStringClass );
+
+ check( true, typeNoAlias, new NativeSQLQueryScalarReturn( null, TypeFactory.basic( "int" ) ) );
+ check( true, aliasNoType, new NativeSQLQueryScalarReturn( "abc", null ) );
+ check( true, aliasTypeInt, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "int" ) ) );
+ check( true, aliasTypeLong, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "long" ) ) );
+ check( true, aliasTypeLongClass, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( Long.class.getName() ) ) );
+ check( true, aliasTypeString, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "string" ) ) );
+ check( true, aliasTypeStringClass, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( String.class.getName() ) ) );
+ }
+
+ public void testNativeSQLQueryRootReturn() {
+ NativeSQLQueryRootReturn alias = new NativeSQLQueryRootReturn( "abc", null, null);
+ NativeSQLQueryRootReturn diffAlias = new NativeSQLQueryRootReturn( "def", null, null);
+ NativeSQLQueryRootReturn aliasEntityName = new NativeSQLQueryRootReturn( "abc", "Person", null);
+ NativeSQLQueryRootReturn aliasDiffEntityName = new NativeSQLQueryRootReturn( "abc", "Customer", null);
+ NativeSQLQueryRootReturn aliasEntityNameLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE );
+// NativeSQLQueryRootReturn aliasEntityNameDiffLockMode = new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC );
+
+ check( false, alias, diffAlias );
+ check( false, alias, aliasEntityName );
+ check( false, alias, aliasDiffEntityName );
+ check( false, alias, aliasEntityNameLockMode );
+
+ check( false, diffAlias, aliasEntityName );
+ check( false, diffAlias, aliasDiffEntityName );
+ check( false, diffAlias, aliasEntityNameLockMode );
+
+ check( false, aliasEntityName, aliasDiffEntityName );
+ check( false, aliasEntityName, aliasEntityNameLockMode );
+
+ check( false, aliasDiffEntityName, aliasEntityNameLockMode );
+
+
+ check( true, alias, new NativeSQLQueryRootReturn( "abc", null, null) );
+ check( true, diffAlias, new NativeSQLQueryRootReturn( "def", null, null) );
+ check( true, aliasEntityName, new NativeSQLQueryRootReturn( "abc", "Person", null) );
+ check( true, aliasDiffEntityName, new NativeSQLQueryRootReturn( "abc", "Customer", null) );
+ check( true, aliasEntityNameLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.NONE ) );
+// check( true, aliasEntityNameDiffLockMode, new NativeSQLQueryRootReturn( "abc", "Person", LockMode.OPTIMISTIC ) );
+ }
+
+ public void testNativeSQLQueryJoinReturn() {
+ NativeSQLQueryJoinReturn r1 = new NativeSQLQueryJoinReturn( "a", "b", "c", null, null);
+ NativeSQLQueryJoinReturn r2 = new NativeSQLQueryJoinReturn( "a", "c", "b", null, null);
+ NativeSQLQueryJoinReturn r3NullMap = new NativeSQLQueryJoinReturn( "b", "c", "a", null, null);
+ NativeSQLQueryJoinReturn r3EmptyMap= new NativeSQLQueryJoinReturn( "b", "c", "a", new HashMap(), null);
+ NativeSQLQueryJoinReturn r4 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null);
+ NativeSQLQueryJoinReturn r5 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null);
+ NativeSQLQueryJoinReturn r6 = new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE );
+ NativeSQLQueryJoinReturn r7 = new NativeSQLQueryJoinReturn( "b", "c", "a", null, LockMode.NONE );
+
+ check( false, r1, r2 );
+ check( false, r1, r3NullMap );
+ check( false, r1, r3EmptyMap );
+ check( false, r1, r4 );
+ check( false, r1, r5 );
+ check( false, r1, r6 );
+ check( false, r1, r7 );
+
+ check( false, r2, r3NullMap );
+ check( false, r2, r3EmptyMap );
+ check( false, r2, r4 );
+ check( false, r2, r5 );
+ check( false, r2, r6 );
+ check( false, r2, r7 );
+
+ check( true, r3NullMap, r3EmptyMap );
+ check( false, r3NullMap, r4 );
+ check( false, r3NullMap, r5 );
+ check( false, r3NullMap, r6 );
+ check( false, r3NullMap, r7 );
+
+ check( false, r3EmptyMap, r4 );
+ check( false, r3EmptyMap, r5 );
+ check( false, r3EmptyMap, r6 );
+ check( false, r3EmptyMap, r7 );
+
+ check( false, r4, r5 );
+ check( false, r4, r6 );
+ check( false, r4, r7 );
+
+ check( false, r5, r6 );
+ check( false, r5, r7 );
+
+ check( false, r6, r7 );
+
+ check( true, r1, new NativeSQLQueryJoinReturn( "a", "b", "c", null, null) );
+ check( true, r2, new NativeSQLQueryJoinReturn( "a", "c", "b", null, null) );
+ check( true, r3NullMap, new NativeSQLQueryJoinReturn( "b", "c", "a", null, null) );
+ check( true, r3EmptyMap, new NativeSQLQueryJoinReturn( "b", "c", "a", new HashMap(), null) );
+ check( true, r4, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null) );
+ check( true, r5, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null) );
+ check( true, r6, new NativeSQLQueryJoinReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE ) );
+ check( true, r7, new NativeSQLQueryJoinReturn( "b", "c", "a", null, LockMode.NONE ) );
+ }
+
+ public void testNativeSQLQueryCollectionReturn() {
+ NativeSQLQueryCollectionReturn r1 = new NativeSQLQueryCollectionReturn( "a", "b", "c", null, null);
+ NativeSQLQueryCollectionReturn r2 = new NativeSQLQueryCollectionReturn( "a", "c", "b", null, null);
+ NativeSQLQueryCollectionReturn r3NullMap = new NativeSQLQueryCollectionReturn( "b", "c", "a", null, null);
+ NativeSQLQueryCollectionReturn r3EmptyMap= new NativeSQLQueryCollectionReturn( "b", "c", "a", new HashMap(), null);
+ NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null);
+ NativeSQLQueryCollectionReturn r5 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null);
+ NativeSQLQueryCollectionReturn r6 = new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE );
+ NativeSQLQueryCollectionReturn r7 = new NativeSQLQueryCollectionReturn( "b", "c", "a", null, LockMode.NONE );
+
+ check( false, r1, r2 );
+ check( false, r1, r3NullMap );
+ check( false, r1, r3EmptyMap );
+ check( false, r1, r4 );
+ check( false, r1, r5 );
+ check( false, r1, r6 );
+ check( false, r1, r7 );
+
+ check( false, r2, r3NullMap );
+ check( false, r2, r3EmptyMap );
+ check( false, r2, r4 );
+ check( false, r2, r5 );
+ check( false, r2, r6 );
+ check( false, r2, r7 );
+
+ check( true, r3NullMap, r3EmptyMap );
+ check( false, r3NullMap, r4 );
+ check( false, r3NullMap, r5 );
+ check( false, r3NullMap, r6 );
+ check( false, r3NullMap, r7 );
+
+ check( false, r3EmptyMap, r4 );
+ check( false, r3EmptyMap, r5 );
+ check( false, r3EmptyMap, r6 );
+ check( false, r3EmptyMap, r7 );
+
+ check( false, r4, r5 );
+ check( false, r4, r6 );
+ check( false, r4, r7 );
+
+ check( false, r5, r6 );
+ check( false, r5, r7 );
+
+ check( false, r6, r7 );
+
+ check( true, r1, new NativeSQLQueryCollectionReturn( "a", "b", "c", null, null) );
+ check( true, r2, new NativeSQLQueryCollectionReturn( "a", "c", "b", null, null) );
+ check( true, r3NullMap, new NativeSQLQueryCollectionReturn( "b", "c", "a", null, null) );
+ check( true, r3EmptyMap, new NativeSQLQueryCollectionReturn( "b", "c", "a", new HashMap(), null) );
+ check( true, r4, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), null) );
+ check( true, r5, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "otherkey", "othervalue" ), null) );
+ check( true, r6, new NativeSQLQueryCollectionReturn( "b", "c", "a", Collections.singletonMap( "key", "value" ), LockMode.NONE ) );
+ check( true, r7, new NativeSQLQueryCollectionReturn( "b", "c", "a", null, LockMode.NONE ) );
+ }
+
+ public void testNativeSQLQueryReturnTypes() {
+ NativeSQLQueryScalarReturn r1 = new NativeSQLQueryScalarReturn( "a", TypeFactory.basic( "int" ) );
+ NativeSQLQueryRootReturn r2 = new NativeSQLQueryRootReturn( "a", "b", LockMode.NONE );
+ NativeSQLQueryJoinReturn r3 = new NativeSQLQueryJoinReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE );
+ NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE);
+
+ check( false, r1, r2 );
+ check( false, r1, r3 );
+ check( false, r1, r4 );
+
+ check( false, r2, r3 );
+ check( false, r2, r4 );
+
+ check( false, r3, r4 );
+ }
+
+ private void check(boolean expectedEquals, NativeSQLQueryReturn queryReturn1, NativeSQLQueryReturn queryReturn2) {
+ if ( expectedEquals ) {
+ assertTrue( queryReturn1.equals( queryReturn2 ) );
+ assertTrue( queryReturn2.equals( queryReturn1 ) );
+ assertTrue( queryReturn1.hashCode() == queryReturn2.hashCode() );
+ }
+ else {
+ assertFalse( queryReturn1.equals( queryReturn2 ) );
+ assertFalse( queryReturn2.equals( queryReturn1 ) );
+ assertFalse( queryReturn1.hashCode() == queryReturn2.hashCode() );
+ }
+ }
+}
\ No newline at end of file
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Person.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Person.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/Person.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+/**
+ * Base of inheritence hierarchy
+ *
+ * @author Steve Ebersole
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private char sex;
+
+ /**
+ * Used by persistence
+ */
+ protected Person() {
+ }
+
+ public Person(String name, char sex) {
+ this.name = name;
+ this.sex = sex;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public char getSex() {
+ return sex;
+ }
+
+ public void setSex(char sex) {
+ this.sex = sex;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/User.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/User.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/User.java 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.test.queryplan;
+
+/**
+ * Non-leaf subclass
+ *
+ * @author Steve Ebersole
+ */
+public class User extends Person {
+ private String username;
+
+ protected User() {
+ super();
+ }
+
+ public User(String name, char sex, String username) {
+ super( name, sex );
+ this.username = username;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/filter-defs.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/filter-defs.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/queryplan/filter-defs.hbm.xml 2011-01-08 16:10:57 UTC (rev 20874)
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Middleware LLC.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ ~
+ -->
+
+<!DOCTYPE hibernate-mapping
+ SYSTEM
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.queryplan">
+ <filter-def name="sex" condition="SEX_CODE = :sexCode">
+ <filter-param name="sexCode" type="char"/>
+ </filter-def>
+</hibernate-mapping>
\ No newline at end of file
14 years