Author: stliu
Date: 2010-07-08 04:51:15 -0400 (Thu, 08 Jul 2010)
New Revision: 19914
Added:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Customer.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Employee.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Joined.hbm.xml
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Person.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/User.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/filter-defs.hbm.xml
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java
Log:
JBPAPP-4579 HHH-2470 Use of session.createSQLQuery causes memory leak
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java 2010-07-07
20:30:20 UTC (rev 19913)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryCollectionReturn.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -40,6 +40,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
@@ -61,6 +62,8 @@
super( alias, propertyResults, lockMode );
this.ownerEntityName = ownerEntityName;
this.ownerProperty = ownerProperty;
+ this.hashCode = determineHashCode();
+
}
/**
@@ -80,4 +83,38 @@
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_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java 2010-07-07
20:30:20 UTC (rev 19913)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryJoinReturn.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -37,6 +37,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.
@@ -56,6 +57,8 @@
super( alias, propertyResults, lockMode );
this.ownerAlias = ownerAlias;
this.ownerProperty = ownerProperty;
+ this.hashCode = determineHashCode();
+
}
/**
@@ -76,4 +79,38 @@
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_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java 2010-07-07
20:30:20 UTC (rev 19913)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryNonScalarReturn.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -42,6 +42,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
@@ -59,6 +60,8 @@
if ( propertyResults != null ) {
this.propertyResults.putAll( propertyResults );
}
+ this.hashCode = determineHashCode();
+
}
/**
@@ -87,4 +90,39 @@
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_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java 2010-07-07
20:30:20 UTC (rev 19913)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryRootReturn.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -37,6 +37,7 @@
*/
public class NativeSQLQueryRootReturn extends NativeSQLQueryNonScalarReturn {
private String returnEntityName;
+ private final int hashCode;
/**
* Construct a return representing an entity returned at the root
@@ -60,6 +61,7 @@
public NativeSQLQueryRootReturn(String alias, String entityName, Map propertyResults,
LockMode lockMode) {
super( alias, propertyResults, lockMode );
this.returnEntityName = entityName;
+ this.hashCode = determineHashCode();
}
@@ -71,5 +73,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_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java 2010-07-07
20:30:20 UTC (rev 19913)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/query/sql/NativeSQLQueryScalarReturn.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -34,10 +34,13 @@
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() {
@@ -48,4 +51,35 @@
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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Customer.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Customer.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Customer.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Employee.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Employee.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Employee.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Joined.hbm.xml
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Joined.hbm.xml
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Joined.hbm.xml 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -0,0 +1,75 @@
+/*
+ * 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 java.util.Map;
+
+import org.hibernate.engine.query.QueryPlanCache;
+import org.hibernate.engine.query.NativeSQLQueryPlan;
+import org.hibernate.engine.query.sql.NativeSQLQueryScalarReturn;
+import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
+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(null);
+ 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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -0,0 +1,272 @@
+/*
+ * 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 java.util.Map;
+
+import org.hibernate.LockMode;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.query.HQLQueryPlan;
+import org.hibernate.engine.query.QueryPlanCache;
+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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Person.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Person.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/Person.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/User.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/User.java
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/User.java 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/filter-defs.hbm.xml
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/filter-defs.hbm.xml
(rev 0)
+++
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/queryplan/filter-defs.hbm.xml 2010-07-08
08:51:15 UTC (rev 19914)
@@ -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