Hibernate SVN: r20074 - in core/trunk: core/src/main/java/org/hibernate/loader and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-07-28 14:55:13 -0400 (Wed, 28 Jul 2010)
New Revision: 20074
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/AbstractQueryCacheResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Address.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Course.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeeting.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeetingId.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheIgnoreResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheNormalResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCachePutResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheIgnoreResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheNormalResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCachePutResultTransformerTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/PersonName.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Student.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/StudentDTO.java
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
core/trunk/core/src/main/java/org/hibernate/loader/Loader.java
Log:
HHH-5163 : added logging and test cases for ClassCastException when caching transformed query results
Modified: core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2010-07-27 16:17:42 UTC (rev 20073)
+++ core/trunk/core/src/main/java/org/hibernate/cache/QueryKey.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -173,6 +173,10 @@
this.hashCode = generateHashCode();
}
+ public ResultTransformer getResultTransformer() {
+ return customTransformer;
+ }
+
/**
* Deserialization hook used to re-init the cached hashcode which is needed for proper clustering support.
*
Modified: core/trunk/core/src/main/java/org/hibernate/loader/Loader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/Loader.java 2010-07-27 16:17:42 UTC (rev 20073)
+++ core/trunk/core/src/main/java/org/hibernate/loader/Loader.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -2275,6 +2275,13 @@
session
);
+ if ( querySpaces == null || querySpaces.size() == 0 ) {
+ log.trace( "unexpected querySpaces is "+( querySpaces == null ? "null" : "empty" ) );
+ }
+ else {
+ log.trace( "querySpaces is "+querySpaces.toString() );
+ }
+
List result = getResultFromQueryCache(
session,
queryParameters,
@@ -2327,6 +2334,11 @@
}
try {
result = queryCache.get( key, resultTypes, isImmutableNaturalKeyLookup, querySpaces, session );
+ logCachedResultDetails(
+ key.getResultTransformer(),
+ resultTypes,
+ result
+ );
}
finally {
persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig );
@@ -2355,6 +2367,13 @@
final QueryKey key,
final List result) {
if ( session.getCacheMode().isPutEnabled() ) {
+ if ( log.isTraceEnabled() ) {
+ logCachedResultDetails(
+ key.getResultTransformer(),
+ resultTypes,
+ result
+ );
+ }
boolean put = queryCache.put( key, resultTypes, result, queryParameters.isNaturalKeyLookup(), session );
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor()
@@ -2363,6 +2382,86 @@
}
}
+
+ private void logCachedResultDetails(ResultTransformer resultTransformer, Type[] returnTypes, List result) {
+ if ( ! log.isTraceEnabled() ) {
+ return;
+ }
+ if ( returnTypes == null || returnTypes.length == 0 ) {
+ log.trace( "unexpected returnTypes is "+( returnTypes == null ? "null" : "empty" )+
+ "! transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " result"+( result == null ? " is null": ".size()=" + result.size() ) );
+ }
+ else {
+ StringBuffer returnTypeNames = new StringBuffer();
+ StringBuffer returnClassNames = new StringBuffer();
+ for ( int i=0; i<returnTypes.length; i++ ) {
+ returnTypeNames.append( returnTypes[ i ].getName() ).append(' ');
+ returnClassNames.append( returnTypes[ i ].getReturnedClass() ).append(' ');
+ }
+ log.trace( "transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " returnTypes=[ "+returnTypeNames+"]"+" returnClasses=[ "+returnClassNames+"]" );
+ }
+ if ( result != null && result.size() != 0 ) {
+ for ( Iterator it = result.iterator(); it.hasNext(); ) {
+ Object value = it.next();
+ if ( value == null ) {
+ log.trace( "transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " value is null; returnTypes is "+( returnTypes == null ? "null" : "Type["+returnTypes.length+"]" ) );
+ if ( returnTypes != null && returnTypes.length > 1 ) {
+ log.trace( "unexpected result value! "+
+ "transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ "value is null; should be Object["+returnTypes.length+"]!" );
+ }
+ }
+ else {
+ if ( returnTypes == null || returnTypes.length == 0 ) {
+ log.trace( "unexpected result value! "+
+ "transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ "value is non-null; returnTypes is "+( returnTypes == null ? "null" : "empty" ) );
+ }
+ else if ( Object[].class.isInstance( value ) ) {
+ Object[] tuple = ( Object[] ) value;
+ log.trace( "transformer="+( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " value is Object["+tuple.length+
+ "]; returnTypes is Type["+returnTypes.length+"]" );
+ if ( tuple.length != returnTypes.length ) {
+ log.trace( "unexpected tuple length! transformer="+
+ ( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " expected="+returnTypes.length+
+ " got="+tuple.length );
+ }
+ else {
+ for ( int j = 0; j < tuple.length; j++ ) {
+ if ( tuple[ j ] != null && ! returnTypes[ j ].getReturnedClass().isInstance( tuple[ j ] ) ) {
+ log.trace( "unexpected tuple value type! transformer="+
+ ( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " expected="+returnTypes[ j ].getReturnedClass().getName()+
+ " got="+tuple[ j ].getClass().getName() );
+ }
+ }
+ }
+ }
+ else {
+ if ( returnTypes.length != 1 ) {
+ log.trace( "unexpected number of result columns! should be Object["+returnTypes.length+"]! transformer="+
+ ( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " value type="+value.getClass().getName()+
+ " returnTypes is Type["+returnTypes.length+"]" );
+ }
+ else if ( ! returnTypes[ 0 ].getReturnedClass().isInstance( value ) ) {
+ log.trace( "unexpected value type! transformer="+
+ ( resultTransformer == null ? "null" : resultTransformer.getClass().getName() )+
+ " expected="+returnTypes[ 0 ].getReturnedClass().getName()+
+ " got="+ value.getClass().getName() );
+ }
+ }
+ }
+ }
+ }
+ }
+
+
/**
* Actually execute a query, ignoring the query cache
*/
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/AbstractQueryCacheResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/AbstractQueryCacheResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/AbstractQueryCacheResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,2170 @@
+/*
+ * 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.querycache;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.CacheMode;
+import org.hibernate.Criteria;
+import org.hibernate.FetchMode;
+import org.hibernate.Hibernate;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Property;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.impl.SessionFactoryImpl;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+import org.hibernate.proxy.HibernateProxy;
+import org.hibernate.transform.AliasToBeanConstructorResultTransformer;
+import org.hibernate.transform.Transformers;
+import org.hibernate.type.Type;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * @author Gail Badner
+ */
+public abstract class AbstractQueryCacheResultTransformerTest extends FunctionalTestCase {
+
+ private Student yogiExpected;
+ private Student shermanExpected;
+ private CourseMeeting courseMeetingExpected1;
+ private CourseMeeting courseMeetingExpected2;
+ private Course courseExpected;
+ private Enrolment yogiEnrolmentExpected;
+ private Enrolment shermanEnrolmentExpected;
+
+ public AbstractQueryCacheResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "querycache/Enrolment.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "foo" );
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ protected abstract class CriteriaExecutor extends QueryExecutor {
+ protected abstract Criteria getCriteria(Session s) throws Exception;
+ protected Object getResults(Session s, boolean isSingleResult) throws Exception {
+ Criteria criteria = getCriteria( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() );
+ return ( isSingleResult ? criteria.uniqueResult() : criteria.list() );
+ }
+ }
+
+ protected abstract class HqlExecutor extends QueryExecutor {
+ protected abstract Query getQuery(Session s);
+ protected Object getResults(Session s, boolean isSingleResult) {
+ Query query = getQuery( s ).setCacheable( getQueryCacheMode() != CacheMode.IGNORE ).setCacheMode( getQueryCacheMode() );
+ return ( isSingleResult ? query.uniqueResult() : query.list() );
+ }
+ }
+
+ protected abstract class QueryExecutor {
+ public Object execute(boolean isSingleResult) throws Exception{
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Object result = getResults( s, isSingleResult );
+ t.commit();
+ s.close();
+ return result;
+ }
+ protected abstract Object getResults(Session s, boolean isSingleResult) throws Exception;
+ }
+
+ protected interface ResultChecker {
+ void check(Object results);
+ }
+
+ protected abstract CacheMode getQueryCacheMode();
+
+ protected boolean areDynamicNonLazyAssociationsChecked() {
+ return true;
+ }
+
+ protected void createData() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ courseExpected = new Course();
+ courseExpected.setCourseCode( "HIB" );
+ courseExpected.setDescription( "Hibernate Training" );
+ courseMeetingExpected1 = new CourseMeeting( courseExpected, "Monday", 1, "1313 Mockingbird Lane" );
+ courseMeetingExpected2 = new CourseMeeting( courseExpected, "Tuesday", 2, "1313 Mockingbird Lane" );
+ courseExpected.getCourseMeetings().add( courseMeetingExpected1 );
+ courseExpected.getCourseMeetings().add( courseMeetingExpected2 );
+ s.save( courseExpected );
+
+ yogiExpected = new Student();
+ yogiExpected.setName( new PersonName( "Yogi", "The", "Bear" ) );
+ yogiExpected.setStudentNumber( 111 );
+ yogiExpected.setPreferredCourse( courseExpected );
+ List yogiSecretCodes = new ArrayList();
+ yogiSecretCodes.add( Integer.valueOf( 0 ) );
+ yogiExpected.setSecretCodes( yogiSecretCodes );
+ s.save( yogiExpected );
+
+ Address address1 = new Address( yogiExpected, "home", "1 Main Street", "Podunk", "WA", "98000", "USA" );
+ Address address2 = new Address( yogiExpected, "work", "2 Main Street", "NotPodunk", "WA", "98001", "USA" );
+ yogiExpected.getAddresses().put( address1.getAddressType(), address1 );
+ yogiExpected.getAddresses().put( address2.getAddressType(), address2 );
+ s.save( address1 );
+ s.save( address2 );
+
+ shermanExpected = new Student();
+ shermanExpected.setName( new PersonName( "Sherman", null, "Grote" ) );
+ shermanExpected.setStudentNumber( 999 );
+ List shermanSecretCodes = new ArrayList();
+ shermanSecretCodes.add( Integer.valueOf( 1 ) );
+ shermanSecretCodes.add( Integer.valueOf( 2 ) );
+ shermanExpected.setSecretCodes( shermanSecretCodes );
+ s.save( shermanExpected );
+
+ shermanEnrolmentExpected = new Enrolment();
+ shermanEnrolmentExpected.setCourse( courseExpected );
+ shermanEnrolmentExpected.setCourseCode( courseExpected.getCourseCode() );
+ shermanEnrolmentExpected.setSemester( ( short ) 1 );
+ shermanEnrolmentExpected.setYear( ( short ) 1999 );
+ shermanEnrolmentExpected.setStudent( shermanExpected );
+ shermanEnrolmentExpected.setStudentNumber( shermanExpected.getStudentNumber() );
+ shermanExpected.getEnrolments().add( shermanEnrolmentExpected );
+ s.save( shermanEnrolmentExpected );
+
+ yogiEnrolmentExpected = new Enrolment();
+ yogiEnrolmentExpected.setCourse( courseExpected );
+ yogiEnrolmentExpected.setCourseCode( courseExpected.getCourseCode() );
+ yogiEnrolmentExpected.setSemester( ( short ) 3 );
+ yogiEnrolmentExpected.setYear( ( short ) 1998 );
+ yogiEnrolmentExpected.setStudent( yogiExpected );
+ yogiEnrolmentExpected.setStudentNumber( yogiExpected.getStudentNumber() );
+ yogiExpected.getEnrolments().add( yogiEnrolmentExpected );
+ s.save( yogiEnrolmentExpected );
+
+ t.commit();
+ s.close();
+ }
+
+ protected void deleteData() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+/*
+ List students = s.createQuery( "from Student" ).list();
+ for ( Iterator it = students.iterator(); it.hasNext(); ) {
+ s.delete( it.next() );
+ }
+ s.createQuery( "delete from Enrolment" ).executeUpdate();
+ s.createQuery( "delete from CourseMeeting" ).executeUpdate();
+ s.createQuery( "delete from Course" ).executeUpdate();
+*/
+ s.delete( yogiExpected );
+ s.delete( shermanExpected );
+ s.delete( yogiEnrolmentExpected );
+ s.delete( shermanEnrolmentExpected );
+ s.delete( courseMeetingExpected1 );
+ s.delete( courseMeetingExpected2 );
+ s.delete( courseExpected );
+ t.commit();
+ s.close();
+ }
+
+ public void testEntityWithNonLazyOneToManyUnique() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Course.class );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Course" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Course );
+ assertEquals( courseExpected, results );
+ assertTrue( Hibernate.isInitialized( ( ( Course ) courseExpected ).getCourseMeetings() ) );
+ assertEquals( courseExpected.getCourseMeetings(), ( ( Course ) courseExpected ).getCourseMeetings() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testEntityWithNonLazyManyToOneList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( CourseMeeting.class )
+ .addOrder( Order.asc( "id.day") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ protected Query getQuery(Session s) {
+ return s.createQuery( "from CourseMeeting order by id.day" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( courseMeetingExpected1, resultList.get( 0 ) );
+ assertEquals( courseMeetingExpected2, resultList.get( 1 ) );
+ assertTrue( Hibernate.isInitialized( ( ( CourseMeeting ) resultList.get( 0 ) ).getCourse() ) );
+ assertTrue( Hibernate.isInitialized( ( ( CourseMeeting ) resultList.get( 1 ) ).getCourse() ) );
+ assertEquals( courseExpected, ( ( CourseMeeting ) resultList.get( 0 ) ).getCourse() );
+ assertEquals( courseExpected, ( ( CourseMeeting ) resultList.get( 1 ) ).getCourse() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testEntityWithLazyAssnUnique() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .add( Restrictions.eq( "studentNumber", shermanExpected.getStudentNumber() ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s where s.studentNumber = :studentNumber" )
+ .setParameter( "studentNumber", shermanExpected.getStudentNumber() );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Student );
+ assertEquals( shermanExpected, results );
+ assertFalse( Hibernate.isInitialized( ( ( Student ) results ).getEnrolments() ) );
+ assertNull( ( ( Student ) results ).getPreferredCourse() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ // should use RootEntityTransformer by default
+ public void testEntityWithLazyAssnList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class )
+ .addOrder( Order.asc( "studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student order by studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ assertFalse( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getEnrolments() ) );
+ assertFalse( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getPreferredCourse() ) );
+ assertFalse( Hibernate.isInitialized( ( ( Student ) resultList.get( 1 ) ).getEnrolments() ) );
+ assertNull( ( ( Student ) resultList.get( 1 ) ).getPreferredCourse() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testEntityWithJoinFetchedLazyOneToManySingleElementList() throws Exception {
+ // unaliased
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .setFetchMode( "enrolments", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.enrolments order by s.studentNumber" );
+ }
+ };
+
+ // aliased
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .setFetchMode( "enrolments", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .setFetchMode( "e", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .setFetchMode( "enrolments", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .setFetchMode( "e", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.enrolments e order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ if ( areDynamicNonLazyAssociationsChecked() ) {
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getEnrolments() ) );
+ assertEquals( yogiExpected.getEnrolments(), ( ( Student ) resultList.get( 0 ) ).getEnrolments() );
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 1 ) ).getEnrolments() ) );
+ assertEquals( shermanExpected.getEnrolments(), ( ( Student ) resultList.get( 1 ) ).getEnrolments() );
+ }
+ }
+ };
+
+ runTest( hqlExecutorUnaliased, criteriaExecutorUnaliased, checker, false);
+ runTest( hqlExecutorAliased, criteriaExecutorAliased1, checker, false);
+ runTest( null, criteriaExecutorAliased2, checker, false);
+ runTest( null, criteriaExecutorAliased3, checker, false);
+ runTest( null, criteriaExecutorAliased4, checker, false);
+
+ }
+
+ public void testEntityWithJoinFetchedLazyOneToManyMultiAndNullElementList() throws Exception {
+ //unaliased
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .setFetchMode( "addresses", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.addresses order by s.studentNumber" );
+ }
+ };
+
+ //aliased
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .setFetchMode( "addresses", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .setFetchMode( "a", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .setFetchMode( "addresses", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .setFetchMode( "a", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.addresses a order by s.studentNumber" );
+ }
+ };
+
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 3, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertSame( resultList.get( 0 ), resultList.get( 1 ) );
+ assertEquals( shermanExpected, resultList.get( 2 ) );
+ if ( areDynamicNonLazyAssociationsChecked() ) {
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getAddresses() ) );
+ assertEquals( yogiExpected.getAddresses(), ( ( Student ) resultList.get( 0 ) ).getAddresses() );
+ assertTrue( ( ( Student ) resultList.get( 2 ) ).getAddresses().isEmpty() );
+ }
+ }
+ };
+ runTest( hqlExecutorUnaliased, criteriaExecutorUnaliased, checker, false );
+ runTest( hqlExecutorAliased, criteriaExecutorAliased1, checker, false );
+ runTest( null, criteriaExecutorAliased2, checker, false );
+ runTest( null, criteriaExecutorAliased3, checker, false );
+ runTest( null, criteriaExecutorAliased4, checker, false );
+ }
+
+ public void testEntityWithJoinFetchedLazyManyToOneList() throws Exception {
+ // unaliased
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .setFetchMode( "preferredCourse", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.preferredCourse order by s.studentNumber" );
+ }
+ };
+
+ // aliased
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
+ .setFetchMode( "preferredCourse", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
+ .setFetchMode( "pCourse", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased3 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
+ .setFetchMode( "preferredCourse", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased4 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
+ .setFetchMode( "pCourse", FetchMode.JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join fetch s.preferredCourse pCourse order by s.studentNumber" );
+ }
+ };
+
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ assertEquals( yogiExpected.getPreferredCourse().getCourseCode(),
+ ( ( Student ) resultList.get( 0 ) ).getPreferredCourse().getCourseCode() );
+ assertNull( ( ( Student ) resultList.get( 1 ) ).getPreferredCourse() );
+ }
+ };
+ runTest( hqlExecutorUnaliased, criteriaExecutorUnaliased, checker, false );
+ runTest( hqlExecutorAliased, criteriaExecutorAliased1, checker, false );
+ runTest( null, criteriaExecutorAliased2, checker, false );
+ runTest( null, criteriaExecutorAliased3, checker, false );
+ runTest( null, criteriaExecutorAliased4, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyOneToManySingleElementListCriteria() throws Exception {
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.enrolments", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ if ( areDynamicNonLazyAssociationsChecked() ) {
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getEnrolments() ) );
+ assertEquals( yogiExpected.getEnrolments(), ( ( Student ) resultList.get( 0 ) ).getEnrolments() );
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 1 ) ).getEnrolments() ) );
+ assertEquals( shermanExpected.getEnrolments(), ( ( Student ) resultList.get( 1 ) ).getEnrolments() );
+ }
+ }
+ };
+ runTest( null, criteriaExecutorUnaliased, checker, false );
+ runTest( null, criteriaExecutorAliased1, checker, false );
+ runTest( null, criteriaExecutorAliased2, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyOneToManyMultiAndNullListCriteria() throws Exception {
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.addresses", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 3, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertSame( resultList.get( 0 ), resultList.get( 1 ) );
+ assertEquals( shermanExpected, resultList.get( 2 ) );
+ if ( areDynamicNonLazyAssociationsChecked() ) {
+ assertTrue( Hibernate.isInitialized( ( ( Student ) resultList.get( 0 ) ).getAddresses() ) );
+ assertEquals( yogiExpected.getAddresses(), ( ( Student ) resultList.get( 0 ) ).getAddresses() );
+ assertTrue( ( ( Student ) resultList.get( 2 ) ).getAddresses().isEmpty() );
+ }
+ }
+ };
+ runTest( null, criteriaExecutorUnaliased, checker, false );
+ runTest( null, criteriaExecutorAliased1, checker, false );
+ runTest( null, criteriaExecutorAliased2, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyManyToOneListCriteria() throws Exception {
+ CriteriaExecutor criteriaExecutorUnaliased = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.preferredCourse", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased1 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.preferredCourse", "p", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ CriteriaExecutor criteriaExecutorAliased2 = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.preferredCourse", "p", Criteria.LEFT_JOIN )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ assertEquals( yogiExpected.getPreferredCourse().getCourseCode(),
+ ( ( Student ) resultList.get( 0 ) ).getPreferredCourse().getCourseCode() );
+ assertNull( ( ( Student ) resultList.get( 1 ) ).getPreferredCourse() );
+ }
+ };
+ runTest( null, criteriaExecutorUnaliased, checker, false );
+ runTest( null, criteriaExecutorAliased1, checker, false );
+ runTest( null, criteriaExecutorAliased2, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyOneToManySingleElementListHql() throws Exception {
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.enrolments order by s.studentNumber" );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.enrolments e order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertTrue( resultList.get( 0 ) instanceof Object[] );
+ Object[] yogiObjects = ( Object[] ) resultList.get( 0 );
+ assertEquals( yogiExpected, yogiObjects[ 0 ] );
+ assertEquals( yogiEnrolmentExpected, yogiObjects[ 1 ] );
+ assertTrue( resultList.get( 0 ) instanceof Object[] );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 1 );
+ assertEquals( shermanExpected, shermanObjects[ 0 ] );
+ assertEquals( shermanEnrolmentExpected, shermanObjects[ 1 ] );
+ }
+ };
+ runTest( hqlExecutorUnaliased, null, checker, false );
+ runTest( hqlExecutorAliased, null, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyOneToManyMultiAndNullListHql() throws Exception {
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.addresses order by s.studentNumber" );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.addresses a order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 3, resultList.size() );
+ assertTrue( resultList.get( 0 ) instanceof Object[] );
+ Object[] yogiObjects1 = ( Object[] ) resultList.get( 0 );
+ assertEquals( yogiExpected, yogiObjects1[ 0 ] );
+ Address address1 = ( Address ) yogiObjects1[ 1 ];
+ assertEquals( yogiExpected.getAddresses().get( address1.getAddressType() ), address1 );
+ Object[] yogiObjects2 = ( Object[] ) resultList.get( 1 );
+ assertSame( yogiObjects1[ 0 ], yogiObjects2[ 0 ] );
+ Address address2 = ( Address ) yogiObjects2[ 1 ];
+ assertEquals( yogiExpected.getAddresses().get( address2.getAddressType() ), address2 );
+ assertFalse( address1.getAddressType().equals( address2.getAddressType() ) );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 2 );
+ assertEquals( shermanExpected, shermanObjects[ 0 ] );
+ assertNull( shermanObjects[ 1 ] );
+ }
+ };
+ runTest( hqlExecutorUnaliased, null, checker, false );
+ runTest( hqlExecutorAliased, null, checker, false );
+ }
+
+ public void testEntityWithJoinedLazyManyToOneListHql() throws Exception {
+ HqlExecutor hqlExecutorUnaliased = new HqlExecutor() {
+ protected Query getQuery(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createQuery( "from Student s left join s.preferredCourse order by s.studentNumber" );
+ }
+ };
+ HqlExecutor hqlExecutorAliased = new HqlExecutor() {
+ protected Query getQuery(Session s) {
+ // should use RootEntityTransformer by default
+ return s.createQuery( "from Student s left join s.preferredCourse p order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Object[] yogiObjects = ( Object[] ) resultList.get( 0 );
+ assertEquals( yogiExpected, yogiObjects[ 0 ] );
+ assertEquals( yogiExpected.getPreferredCourse(), yogiObjects[ 1 ] );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 1 );
+ assertEquals( shermanExpected, shermanObjects[ 0 ] );
+ assertNull( shermanObjects[ 1 ] );
+ }
+ };
+ runTest( hqlExecutorUnaliased, null, checker, false );
+ runTest( hqlExecutorAliased, null, checker, false );
+ }
+
+ public void testAliasToEntityMapNoProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.enrolments", "e", Criteria.LEFT_JOIN )
+ .createAlias( "e.course", "c", Criteria.LEFT_JOIN )
+ .setResultTransformer( Criteria.ALIAS_TO_ENTITY_MAP )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.enrolments e left join e.course c order by s.studentNumber" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Map yogiMap = ( Map ) resultList.get( 0 );
+ assertEquals( 3, yogiMap.size() );
+ Map shermanMap = ( Map ) resultList.get( 1 );
+ assertEquals( 3, shermanMap.size() );
+ assertEquals( yogiExpected, yogiMap.get( "s" ) );
+ assertEquals( yogiEnrolmentExpected, yogiMap.get( "e" ) );
+ assertEquals( courseExpected, yogiMap.get( "c" ) );
+ assertEquals( shermanExpected, shermanMap.get( "s" ) );
+ assertEquals( shermanEnrolmentExpected, shermanMap.get( "e" ) );
+ assertEquals( courseExpected, shermanMap.get( "c" ) );
+ assertSame( ( ( Map ) resultList.get( 0 ) ).get( "c" ), shermanMap.get( "c" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToEntityMapNoProjectionMultiAndNullList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.preferredCourse", "p", Criteria.LEFT_JOIN )
+ .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
+ .setResultTransformer( Criteria.ALIAS_TO_ENTITY_MAP )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "from Student s left join s.preferredCourse p left join s.addresses a order by s.studentNumber" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 3, resultList.size() );
+ Map yogiMap1 = ( Map ) resultList.get( 0 );
+ assertEquals( 3, yogiMap1.size() );
+ Map yogiMap2 = ( Map ) resultList.get( 1 );
+ assertEquals( 3, yogiMap2.size() );
+ Map shermanMap = ( Map ) resultList.get( 2 );
+ assertEquals( 3, shermanMap.size() );
+ assertEquals( yogiExpected, yogiMap1.get( "s" ) );
+ assertEquals( courseExpected, yogiMap1.get( "p" ) );
+ Address yogiAddress1 = ( Address ) yogiMap1.get( "a" );
+ assertEquals( yogiExpected.getAddresses().get( yogiAddress1.getAddressType() ),
+ yogiMap1.get( "a" ));
+ assertEquals( yogiExpected, yogiMap2.get( "s" ) );
+ assertEquals( courseExpected, yogiMap2.get( "p" ) );
+ Address yogiAddress2 = ( Address ) yogiMap2.get( "a" );
+ assertEquals( yogiExpected.getAddresses().get( yogiAddress2.getAddressType() ),
+ yogiMap2.get( "a" ));
+ assertSame( yogiMap1.get( "s" ), yogiMap2.get( "s" ) );
+ assertSame( yogiMap1.get( "p" ), yogiMap2.get( "p" ) );
+ assertFalse( yogiAddress1.getAddressType().equals( yogiAddress2.getAddressType() ) );
+ assertEquals( shermanExpected, shermanMap.get( "s" ) );
+ assertEquals( shermanExpected.getPreferredCourse(), shermanMap.get( "p" ) );
+ assertNull( shermanMap.get( "a") );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToEntityMapOneProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection( Projections.property( "e.student" ).as( "student" ) )
+ .addOrder( Order.asc( "e.studentNumber") )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student as student from Enrolment e order by e.studentNumber" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Map yogiMap = ( Map ) resultList.get( 0 );
+ Map shermanMap = ( Map ) resultList.get( 1 );
+ assertEquals( 1, yogiMap.size() );
+ //assertTrue( yogiMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( yogiMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( yogiMap.get( "student" ) ) ) {
+ assertEquals( yogiExpected, yogiMap.get( "student" ) );
+ }
+ else {
+ assertEquals( yogiExpected.getStudentNumber(), ( ( Student ) yogiMap.get( "student" ) ).getStudentNumber() );
+ }
+ assertEquals( 1, shermanMap.size() );
+ //assertTrue( shermanMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( shermanMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( shermanMap.get( "student" ) ) ) {
+ assertEquals( shermanExpected, shermanMap.get( "student" ) );
+ }
+ else {
+ assertEquals( shermanExpected.getStudentNumber(), ( ( Student ) shermanMap.get( "student" ) ).getStudentNumber() );
+ }
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false);
+ }
+
+ public void testAliasToEntityMapMultiProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "e.student" ), "student" )
+ .add( Property.forName( "e.semester" ), "semester" )
+ .add( Property.forName( "e.year" ), "year" )
+ .add( Property.forName( "e.course" ), "course" )
+ )
+ .addOrder( Order.asc( "studentNumber") )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student as student, e.semester as semester, e.year as year, e.course as course from Enrolment e order by e.studentNumber" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Map yogiMap = ( Map ) resultList.get( 0 );
+ Map shermanMap = ( Map ) resultList.get( 1 );
+ assertEquals( 4, yogiMap.size() );
+ //assertTrue( yogiMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( yogiMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( yogiMap.get( "student" ) ) ) {
+ assertEquals( yogiExpected, yogiMap.get( "student" ) );
+ }
+ else {
+ assertEquals( yogiExpected.getStudentNumber(), ( ( Student ) yogiMap.get( "student" ) ).getStudentNumber() );
+ }
+ assertEquals( yogiEnrolmentExpected.getSemester(), yogiMap.get( "semester" ) );
+ assertEquals( yogiEnrolmentExpected.getYear(), yogiMap.get( "year" ) );
+ assertEquals( courseExpected, yogiMap.get( "course" ) );
+ assertEquals( 4, shermanMap.size() );
+ //assertTrue( shermanMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( shermanMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( shermanMap.get( "student" ) ) ) {
+ assertEquals( shermanExpected, shermanMap.get( "student" ) );
+ }
+ else {
+ assertEquals( shermanExpected.getStudentNumber(), ( ( Student ) shermanMap.get( "student" ) ).getStudentNumber() );
+ }
+ assertEquals( shermanEnrolmentExpected.getSemester(), shermanMap.get( "semester" ) );
+ assertEquals( shermanEnrolmentExpected.getYear(), shermanMap.get( "year" ) );
+ assertEquals( courseExpected, shermanMap.get( "course" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToEntityMapMultiProjectionWithNullAliasList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "e.student" ), "student" )
+ .add( Property.forName( "e.semester" ) )
+ .add( Property.forName( "e.year" ) )
+ .add( Property.forName( "e.course" ), "course" )
+ )
+ .addOrder( Order.asc( "e.studentNumber") )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student as student, e.semester, e.year, e.course as course from Enrolment e order by e.studentNumber" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Map yogiMap = ( Map ) resultList.get( 0 );
+ Map shermanMap = ( Map ) resultList.get( 1 );
+ //assertEquals( 2, yogiMap.size() );
+ //assertTrue( yogiMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( yogiMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( yogiMap.get( "student" ) ) ) {
+ assertEquals( yogiExpected, yogiMap.get( "student" ) );
+ }
+ else {
+ assertEquals( yogiExpected.getStudentNumber(), ( ( Student ) yogiMap.get( "student" ) ).getStudentNumber() );
+ }
+ assertNull( yogiMap.get( "semester" ) );
+ assertNull( yogiMap.get( "year" ) );
+ assertEquals( courseExpected, yogiMap.get( "course" ) );
+ //assertEquals( 2, shermanMap.size() );
+ //assertTrue( shermanMap[ 0 ] instanceof HibernateProxy );
+ assertTrue( shermanMap.get( "student" ) instanceof Student );
+ if( Hibernate.isInitialized( shermanMap.get( "student" ) ) ) {
+ assertEquals( shermanExpected, shermanMap.get( "student" ) );
+ }
+ else {
+ assertEquals( shermanExpected.getStudentNumber(), ( ( Student ) shermanMap.get( "student" ) ).getStudentNumber() );
+ }
+ assertNull( shermanMap.get( "semester" ) );
+ assertNull( shermanMap.get( "year" ) );
+ assertEquals( courseExpected, shermanMap.get( "course" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToEntityMapMultiAggregatedPropProjectionSingleResult() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.min( "studentNumber" ).as( "minStudentNumber" ) )
+ .add( Projections.max( "studentNumber" ).as( "maxStudentNumber" ) )
+ )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery(
+ "select min( e.studentNumber ) as minStudentNumber, max( e.studentNumber ) as maxStudentNumber from Enrolment e" )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Map );
+ Map resultMap = ( Map ) results;
+ assertEquals( 2, resultMap.size() );
+ assertEquals( yogiExpected.getStudentNumber(), resultMap.get( "minStudentNumber" ) );
+ assertEquals( shermanExpected.getStudentNumber(), resultMap.get( "maxStudentNumber" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testOneNonEntityProjectionUnique() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection( Projections.property( "e.semester" ) )
+ .add( Restrictions.eq( "e.studentNumber", shermanEnrolmentExpected.getStudentNumber() ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.semester from Enrolment e where e.studentNumber = :studentNumber" )
+ .setParameter( "studentNumber", shermanEnrolmentExpected.getStudentNumber() );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Short );
+ assertEquals( Short.valueOf( shermanEnrolmentExpected.getSemester() ), results );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testOneNonEntityProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection( Projections.property( "e.semester" ) )
+ .addOrder( Order.asc( "e.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.semester from Enrolment e order by e.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertEquals( yogiEnrolmentExpected.getSemester(), resultList.get( 0 ) );
+ assertEquals( shermanEnrolmentExpected.getSemester(), resultList.get( 1 ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testListElementsProjectionList() throws Exception {
+ /*
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Student.class, "s" )
+ .createCriteria( "s.secretCodes" )
+ .setProjection( Projections.property( "s.secretCodes" ) )
+ .addOrder( Order.asc( "s.studentNumber") );
+ }
+ };
+ */
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select elements(s.secretCodes) from Student s" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 3, resultList.size() );
+ assertTrue( resultList.contains( yogiExpected.getSecretCodes().get( 0 ) ) );
+ assertTrue( resultList.contains( shermanExpected.getSecretCodes().get( 0 ) ) );
+ assertTrue( resultList.contains( shermanExpected.getSecretCodes().get( 1 ) ) );
+ }
+ };
+ runTest( hqlExecutor, null, checker, false );
+ }
+
+ public void testOneEntityProjectionUnique() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Enrolment.class )
+ .setProjection( Projections.property( "student" ) )
+ .add( Restrictions.eq( "studentNumber", Long.valueOf( yogiExpected.getStudentNumber() ) ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student from Enrolment e where e.studentNumber = :studentNumber" )
+ .setParameter( "studentNumber", Long.valueOf( yogiExpected.getStudentNumber() ) );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Student );
+ Student student = ( Student ) results;
+ if ( Hibernate.isInitialized( student ) ) {
+ assertEquals( yogiExpected, student );
+ }
+ else {
+ assertEquals( yogiExpected.getStudentNumber(), student.getStudentNumber() );
+ }
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testOneEntityProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ // should use PassThroughTransformer by default
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection( Projections.property( "e.student" ) )
+ .addOrder( Order.asc( "e.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student from Enrolment e order by e.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ if ( Hibernate.isInitialized( resultList.get( 0 ) ) ) {
+ assertEquals( yogiExpected, resultList.get( 0 ) );
+ }
+ else {
+ assertEquals( yogiExpected.getStudentNumber(), ( ( Student ) resultList.get( 0 ) ).getStudentNumber() );
+ }
+ if ( Hibernate.isInitialized( resultList.get( 1 ) ) ) {
+ assertEquals( shermanExpected, resultList.get( 1 ) );
+ }
+ else {
+ assertEquals( shermanExpected.getStudentNumber(), ( ( Student ) resultList.get( 1 ) ).getStudentNumber() );
+ }
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMultiEntityProjectionUnique() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Enrolment.class )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "student" ) )
+ .add( Property.forName( "semester" ) )
+ .add( Property.forName( "year" ) )
+ .add( Property.forName( "course" ) )
+ )
+ .add( Restrictions.eq( "studentNumber", Long.valueOf( shermanEnrolmentExpected.getStudentNumber() ) ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery(
+ "select e.student, e.semester, e.year, e.course from Enrolment e where e.studentNumber = :studentNumber" )
+ .setParameter( "studentNumber", shermanEnrolmentExpected.getStudentNumber() );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Object[] );
+ Object shermanObjects[] = ( Object [] ) results;
+ assertEquals( 4, shermanObjects.length );
+ //assertTrue( shermanObjects[ 0 ] instanceof HibernateProxy );
+ assertTrue( shermanObjects[ 0 ] instanceof Student );
+ if ( Hibernate.isInitialized( shermanObjects[ 0 ] ) ) {
+ assertEquals( shermanExpected, shermanObjects[ 0 ] );
+ }
+ assertEquals( shermanEnrolmentExpected.getSemester(), ( (Short) shermanObjects[ 1 ] ).shortValue() );
+ assertEquals( shermanEnrolmentExpected.getYear(), ( (Short) shermanObjects[ 2 ] ).shortValue() );
+ assertTrue( ! ( shermanObjects[ 3 ] instanceof HibernateProxy ) );
+ assertTrue( shermanObjects[ 3 ] instanceof Course );
+ assertEquals( courseExpected, shermanObjects[ 3 ] );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testMultiEntityProjectionList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ // should use PassThroughTransformer by default
+ return s.createCriteria( Enrolment.class, "e" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "e.student" ) )
+ .add( Property.forName( "e.semester" ) )
+ .add( Property.forName( "e.year" ) )
+ .add( Property.forName( "e.course" ) )
+ )
+ .addOrder( Order.asc( "e.studentNumber") );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select e.student, e.semester, e.year, e.course from Enrolment e order by e.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Object[] yogiObjects = ( Object[] ) resultList.get( 0 );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 1 );
+ assertEquals( 4, yogiObjects.length );
+ //assertTrue( yogiObjects[ 0 ] instanceof HibernateProxy );
+ assertTrue( yogiObjects[ 0 ] instanceof Student );
+ if( Hibernate.isInitialized( yogiObjects[ 0 ] ) ) {
+ assertEquals( yogiExpected, yogiObjects[ 0 ] );
+ }
+ assertEquals( yogiEnrolmentExpected.getSemester(), ( (Short) yogiObjects[ 1 ] ).shortValue() );
+ assertEquals( yogiEnrolmentExpected.getYear(), ( (Short) yogiObjects[ 2 ] ).shortValue() );
+ assertEquals( courseExpected, yogiObjects[ 3 ] );
+ //assertTrue( shermanObjects[ 0 ] instanceof HibernateProxy );
+ assertTrue( shermanObjects[ 0 ] instanceof Student );
+ if ( Hibernate.isInitialized( shermanObjects[ 0 ] ) ) {
+ assertEquals( shermanExpected, shermanObjects[ 0 ] );
+ }
+ assertEquals( shermanEnrolmentExpected.getSemester(), ( (Short) shermanObjects[ 1 ] ).shortValue() );
+ assertEquals( shermanEnrolmentExpected.getYear(), ( (Short) shermanObjects[ 2 ] ).shortValue() );
+ //assertTrue( ! ( shermanObjects[ 3 ] instanceof HibernateProxy ) );
+ assertTrue( shermanObjects[ 3 ] instanceof Course );
+ assertEquals( courseExpected, shermanObjects[ 3 ] );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testSingleAggregatedPropProjectionSingleResult() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class )
+ .setProjection( Projections.min( "studentNumber" ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select min( e.studentNumber ) from Enrolment e" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Long );
+ assertEquals( Long.valueOf( yogiExpected.getStudentNumber() ), results );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testMultiAggregatedPropProjectionSingleResult() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.min( "studentNumber" ).as( "minStudentNumber" ) )
+ .add( Projections.max( "studentNumber" ).as( "maxStudentNumber" ) )
+ );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery(
+ "select min( e.studentNumber ) as minStudentNumber, max( e.studentNumber ) as maxStudentNumber from Enrolment e" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ assertTrue( results instanceof Object[] );
+ Object[] resultObjects = ( Object[] ) results;
+ assertEquals( Long.valueOf( yogiExpected.getStudentNumber() ), resultObjects[ 0 ] );
+ assertEquals( Long.valueOf( shermanExpected.getStudentNumber() ), resultObjects[ 1 ] );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, true );
+ }
+
+ public void testAliasToBeanDtoOneArgList() throws Exception {
+
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .createAlias( "e.student", "st" )
+ .createAlias( "e.course", "co" )
+ .setProjection( Projections.property( "st.name" ).as( "studentName" ) )
+ .addOrder( Order.asc( "st.studentNumber" ) )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select st.name as studentName from Student st order by st.studentNumber" )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ StudentDTO dto = ( StudentDTO ) resultList.get( 0 );
+ assertNull( dto.getDescription() );
+ assertEquals( yogiExpected.getName(), dto.getName() );
+ dto = ( StudentDTO ) resultList.get( 1 );
+ assertNull( dto.getDescription() );
+ assertEquals( shermanExpected.getName(), dto.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToBeanDtoMultiArgList() throws Exception {
+
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .createAlias( "e.student", "st" )
+ .createAlias( "e.course", "co" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "st.name" ).as( "studentName" ) )
+ .add( Property.forName( "co.description" ).as( "courseDescription" ) )
+ )
+ .addOrder( Order.asc( "e.studentNumber" ) )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select st.name as studentName, co.description as courseDescription from Enrolment e join e.student st join e.course co order by e.studentNumber" )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ StudentDTO dto = ( StudentDTO ) resultList.get( 0 );
+ assertEquals( courseExpected.getDescription(), dto.getDescription() );
+ assertEquals( yogiExpected.getName(), dto.getName() );
+ dto = ( StudentDTO ) resultList.get( 1 );
+ assertEquals( courseExpected.getDescription(), dto.getDescription() );
+ assertEquals( shermanExpected.getName(), dto.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToBeanDtoLiteralArgList() throws Exception {
+
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .createAlias( "e.student", "st" )
+ .createAlias( "e.course", "co" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "st.name" ).as( "studentName" ) )
+ .add( Projections.sqlProjection(
+ "'lame description' as courseDescription",
+ new String[] { "courseDescription" },
+ new Type[] { Hibernate.STRING }
+ )
+ )
+ )
+ .addOrder( Order.asc( "e.studentNumber" ) )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select st.name as studentName, 'lame description' as courseDescription from Enrolment e join e.student st join e.course co order by e.studentNumber" )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ StudentDTO dto = ( StudentDTO ) resultList.get( 0 );
+ assertEquals( "lame description", dto.getDescription() );
+ assertEquals( yogiExpected.getName(), dto.getName() );
+ dto = ( StudentDTO ) resultList.get( 1 );
+ assertEquals( "lame description", dto.getDescription() );
+ assertEquals( shermanExpected.getName(), dto.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testAliasToBeanDtoWithNullAliasList() throws Exception {
+
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Enrolment.class, "e" )
+ .createAlias( "e.student", "st" )
+ .createAlias( "e.course", "co" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "st.name" ).as( "studentName" ) )
+ .add( Property.forName( "st.studentNumber" ) )
+ .add( Property.forName( "co.description" ).as( "courseDescription" ) )
+ )
+ .addOrder( Order.asc( "e.studentNumber" ) )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select st.name as studentName, co.description as courseDescription from Enrolment e join e.student st join e.course co order by e.studentNumber" )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ StudentDTO dto = ( StudentDTO ) resultList.get( 0 );
+ assertEquals( courseExpected.getDescription(), dto.getDescription() );
+ assertEquals( yogiExpected.getName(), dto.getName() );
+ dto = ( StudentDTO ) resultList.get( 1 );
+ assertEquals( courseExpected.getDescription(), dto.getDescription() );
+ assertEquals( shermanExpected.getName(), dto.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testOneSelectNewList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) throws Exception {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection( Projections.property( "s.name" ) )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
+ }
+ private Constructor getConstructor() throws NoSuchMethodException {
+ return StudentDTO.class.getConstructor( PersonName.class );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new org.hibernate.test.querycache.StudentDTO(s.name) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ StudentDTO yogi = ( StudentDTO ) resultList.get( 0 );
+ assertNull( yogi.getDescription() );
+ assertEquals( yogiExpected.getName(), yogi.getName() );
+ StudentDTO sherman = ( StudentDTO ) resultList.get( 1 );
+ assertEquals( shermanExpected.getName(), sherman.getName() );
+ assertNull( sherman.getDescription() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMultiSelectNewList() throws Exception{
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) throws Exception {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "s.studentNumber" ) )
+ .add( Property.forName( "s.name" ) )
+ )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
+ }
+ private Constructor getConstructor() throws NoSuchMethodException {
+ return Student.class.getConstructor( long.class, PersonName.class );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new Student(s.studentNumber, s.name) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Student yogi = ( Student ) resultList.get( 0 );
+ assertEquals( yogiExpected.getStudentNumber(), yogi.getStudentNumber() );
+ assertEquals( yogiExpected.getName(), yogi.getName() );
+ Student sherman = ( Student ) resultList.get( 1 );
+ assertEquals( shermanExpected.getStudentNumber(), sherman.getStudentNumber() );
+ assertEquals( shermanExpected.getName(), sherman.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMultiSelectNewWithLiteralList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) throws Exception {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.sqlProjection( "555 as sCode", new String[]{ "sCode" }, new Type[] { Hibernate.LONG } ) )
+ .add( Property.forName( "s.name" ) )
+ )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
+ }
+ private Constructor getConstructor() throws NoSuchMethodException {
+ return Student.class.getConstructor( long.class, PersonName.class );
+ }
+ };
+
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new Student(555L, s.name) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Student yogi = ( Student ) resultList.get( 0 );
+ assertEquals( 555L, yogi.getStudentNumber() );
+ assertEquals( yogiExpected.getName(), yogi.getName() );
+ Student sherman = ( Student ) resultList.get( 1 );
+ assertEquals( 555L, sherman.getStudentNumber() );
+ assertEquals( shermanExpected.getName(), sherman.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMultiSelectNewListList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "s.studentNumber" ) )
+ .add( Property.forName( "s.name" ) )
+ )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( Transformers.TO_LIST );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new list(s.studentNumber, s.name) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ List yogiList = ( List ) resultList.get( 0 );
+ assertEquals( yogiExpected.getStudentNumber(), yogiList.get( 0 ) );
+ assertEquals( yogiExpected.getName(), yogiList.get( 1 ) );
+ List shermanList = ( List ) resultList.get( 1 );
+ assertEquals( shermanExpected.getStudentNumber(), shermanList.get( 0 ) );
+ assertEquals( shermanExpected.getName(), shermanList.get( 1 ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMultiSelectNewMapList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "s.studentNumber" ).as( "sNumber" ) )
+ .add( Property.forName( "s.name" ).as( "sName" ) )
+ )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new map(s.studentNumber as sNumber, s.name as sName) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Map yogiMap = ( Map ) resultList.get( 0 );
+ assertEquals( yogiExpected.getStudentNumber(), yogiMap.get( "sNumber" ) );
+ assertEquals( yogiExpected.getName(), yogiMap.get( "sName" ) );
+ Map shermanMap = ( Map ) resultList.get( 1 );
+ assertEquals( shermanExpected.getStudentNumber(), shermanMap.get( "sNumber" ) );
+ assertEquals( shermanExpected.getName(), shermanMap.get( "sName" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testSelectNewEntityConstructorList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "s.studentNumber" ) )
+ .add( Property.forName( "s.name" ) )
+ )
+ .addOrder( Order.asc( "s.studentNumber" ) )
+ .setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
+ }
+ private Constructor getConstructor() {
+ Type studentNametype =
+ ( ( SessionFactoryImpl ) getSessions() )
+ .getEntityPersister( Student.class.getName() )
+ .getPropertyType( "name" );
+ return ReflectHelper.getConstructor( Student.class, new Type[] { Hibernate.LONG, studentNametype } );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select new Student(s.studentNumber, s.name) from Student s order by s.studentNumber" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Student yogi = ( Student ) resultList.get( 0 );
+ assertEquals( yogiExpected.getStudentNumber(), yogi.getStudentNumber() );
+ assertEquals( yogiExpected.getName(), yogi.getName() );
+ Student sherman = ( Student ) resultList.get( 1 );
+ assertEquals( shermanExpected.getStudentNumber(), sherman.getStudentNumber() );
+ assertEquals( shermanExpected.getName(), sherman.getName() );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMapKeyList() throws Exception {
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a" )
+ .setProjection( Projections.property( "a.addressType" ) );
+ }
+ };
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select key(s.addresses) from Student s" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertTrue( resultList.contains( "home" ) );
+ assertTrue( resultList.contains( "work" ) );
+ }
+ };
+ runTest( hqlExecutor, criteriaExecutor, checker, false );
+ }
+
+ public void testMapValueList() throws Exception {
+ /*
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a" )
+ .setProjection( Projections.property( "s.addresses" ));
+ }
+ };
+ */
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select value(s.addresses) from Student s" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertTrue( resultList.contains( yogiExpected.getAddresses().get( "home" ) ) );
+ assertTrue( resultList.contains( yogiExpected.getAddresses().get( "work" ) ) );
+ }
+ };
+ runTest( hqlExecutor, null, checker, false );
+ }
+
+ public void testMapEntryList() throws Exception {
+ /*
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.property( "a.addressType" ) )
+ .add( Projections.property( "s.addresses" ).as( "a" ) );
+ )
+ }
+ };
+ */
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select entry(s.addresses) from Student s" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ Iterator it=resultList.iterator();
+ assertTrue( resultList.get( 0 ) instanceof Map.Entry );
+ Map.Entry entry = ( Map.Entry ) it.next();
+ if ( "home".equals( entry.getKey() ) ) {
+ assertTrue( yogiExpected.getAddresses().get( "home" ).equals( entry.getValue() ) );
+ entry = ( Map.Entry ) it.next();
+ assertTrue( yogiExpected.getAddresses().get( "work" ).equals( entry.getValue() ) );
+ }
+ else {
+ assertTrue( "work".equals( entry.getKey() ) );
+ assertTrue( yogiExpected.getAddresses().get( "work" ).equals( entry.getValue() ) );
+ entry = ( Map.Entry ) it.next();
+ assertTrue( yogiExpected.getAddresses().get( "home" ).equals( entry.getValue() ) );
+ }
+ }
+ };
+ runTest( hqlExecutor, null, checker, false );
+ }
+
+ public void testMapElementsList() throws Exception {
+ /*
+ CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
+ protected Criteria getCriteria(Session s) {
+ return s.createCriteria( Student.class, "s" )
+ .createAlias( "s.addresses", "a", Criteria.INNER_JOIN )
+ .setProjection( Projections.property( "s.addresses" ) );
+ }
+ };
+ */
+ HqlExecutor hqlExecutor = new HqlExecutor() {
+ public Query getQuery(Session s) {
+ return s.createQuery( "select elements(a) from Student s inner join s.addresses a" );
+ }
+ };
+ ResultChecker checker = new ResultChecker() {
+ public void check(Object results) {
+ List resultList = ( List ) results;
+ assertEquals( 2, resultList.size() );
+ assertTrue( resultList.contains( yogiExpected.getAddresses().get( "home" ) ) );
+ assertTrue( resultList.contains( yogiExpected.getAddresses().get( "work" ) ) );
+ }
+ };
+ runTest( hqlExecutor, null, checker, false );
+ }
+
+ protected void runTest(HqlExecutor hqlExecutor, CriteriaExecutor criteriaExecutor, ResultChecker checker, boolean isSingleResult)
+ throws Exception {
+ createData();
+ if ( criteriaExecutor != null ) {
+ runTest( criteriaExecutor, checker, isSingleResult );
+ }
+ if ( hqlExecutor != null ) {
+ runTest( hqlExecutor, checker, isSingleResult );
+ }
+ deleteData();
+ }
+
+ private boolean isQueryCacheGetEnabled() {
+ return getQueryCacheMode() == CacheMode.NORMAL ||
+ getQueryCacheMode() == CacheMode.GET;
+ }
+
+ private boolean isQueryCachePutEnabled() {
+ return getQueryCacheMode() == CacheMode.NORMAL ||
+ getQueryCacheMode() == CacheMode.PUT;
+ }
+
+ protected void runTest(QueryExecutor queryExecutor, ResultChecker resultChecker, boolean isSingleResult) throws Exception{
+ clearCache();
+ clearStatistics();
+
+ Object results = queryExecutor.execute( isSingleResult );
+
+ assertHitCount( 0 );
+ assertMissCount( isQueryCacheGetEnabled() ? 1 : 0 );
+ assertPutCount( isQueryCachePutEnabled() ? 1 : 0 );
+ clearStatistics();
+
+ resultChecker.check( results );
+
+ // check again to make sure nothing got initialized while checking results;
+ assertHitCount( 0 );
+ assertMissCount( 0 );
+ assertPutCount( 0 );
+ clearStatistics();
+
+ results = queryExecutor.execute( isSingleResult );
+
+ assertHitCount( isQueryCacheGetEnabled() ? 1 : 0 );
+ assertMissCount( 0 );
+ assertPutCount( ! isQueryCacheGetEnabled() && isQueryCachePutEnabled() ? 1 : 0 );
+ clearStatistics();
+
+ resultChecker.check( results );
+
+ // check again to make sure nothing got initialized while checking results;
+ assertHitCount( 0 );
+ assertMissCount( 0 );
+ assertPutCount( 0 );
+ clearStatistics();
+ }
+
+ private void multiPropProjectionNoTransformerDynNonLazy(CacheMode sessionCacheMode,
+ boolean isCacheableQuery) {
+ Session s = openSession();
+ s.setCacheMode( sessionCacheMode );
+ Transaction t = s.beginTransaction();
+ List resultList = s.createCriteria( Enrolment.class )
+ .setCacheable( isCacheableQuery )
+ .setFetchMode( "student", FetchMode.JOIN )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "student" ), "student" )
+ .add( Property.forName( "semester" ), "semester" )
+ .add( Property.forName( "year" ), "year" )
+ .add( Property.forName( "course" ), "course" )
+ )
+ .addOrder( Order.asc( "studentNumber") )
+ .list();
+ t.commit();
+ s.close();
+
+ assertEquals( 2, resultList.size() );
+ Object[] yogiObjects = ( Object[] ) resultList.get( 0 );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 1 );
+ assertEquals( 4, yogiObjects.length );
+ assertTrue( yogiObjects[ 0 ] instanceof Student );
+ assertTrue( Hibernate.isInitialized( yogiObjects[ 0 ] ) );
+ assertEquals( yogiEnrolmentExpected.getSemester(), ( (Short) yogiObjects[ 1 ] ).shortValue() );
+ assertEquals( yogiEnrolmentExpected.getYear(), ( (Short) yogiObjects[ 2 ] ).shortValue() );
+ assertEquals( courseExpected, yogiObjects[ 3 ] );
+ assertTrue( shermanObjects[ 0 ] instanceof Student );
+ assertTrue( Hibernate.isInitialized( shermanObjects[ 0 ] ) );
+ assertEquals( shermanEnrolmentExpected.getSemester(), ( (Short) shermanObjects[ 1 ] ).shortValue() );
+ assertEquals( shermanEnrolmentExpected.getYear(), ( (Short) shermanObjects[ 2 ] ).shortValue() );
+ assertTrue( ! ( shermanObjects[ 3 ] instanceof HibernateProxy ) );
+ assertTrue( shermanObjects[ 3 ] instanceof Course );
+ assertEquals( courseExpected, shermanObjects[ 3 ] );
+ }
+
+/*
+ {
+
+ assertEquals( 2, resultList.size() );
+ Object[] yogiObjects = ( Object[] ) resultList.get( 0 );
+ Object[] shermanObjects = ( Object[] ) resultList.get( 1 );
+ assertEquals( 4, yogiObjects.length );
+ assertEquals( yogiExpected, ( Student ) yogiObjects[ 0 ] );
+ assertEquals( yogiEnrolmentExpected.getSemester(), ( (Short) yogiObjects[ 1 ] ).shortValue() );
+ assertEquals( yogiEnrolmentExpected.getYear(), ( (Short) yogiObjects[ 2 ] ).shortValue() );
+ assertEquals( courseExpected, yogiObjects[ 3 ] );
+ assertEquals( shermanExpected, ( Student ) shermanObjects[ 0 ] );
+ assertEquals( shermanEnrolmentExpected.getSemester(), ( (Short) shermanObjects[ 1 ] ).shortValue() );
+ assertEquals( shermanEnrolmentExpected.getYear(), ( (Short) shermanObjects[ 2 ] ).shortValue() );
+ assertEquals( courseExpected, shermanObjects[ 3 ] );
+
+ }
+
+*/
+/*
+ private void executeProperty() {
+ resultList = s.createCriteria( Student.class )
+ .setCacheable( true )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.id().as( "studentNumber" ) )
+ .add( Property.forName( "name" ), "name" )
+ .add( Property.forName( "cityState" ), "cityState" )
+ .add( Property.forName( "preferredCourse" ), "preferredCourse" )
+ )
+ .list();
+ assertEquals( 2, resultList.size() );
+ for ( Iterator it = resultList.iterator(); it.hasNext(); ) {
+ Object[] objects = ( Object[] ) it.next();
+ assertEquals( 4, objects.length );
+ assertTrue( objects[0] instanceof Long );
+ assertTrue( objects[1] instanceof String );
+ if ( "yogiExpected King".equals( objects[1] ) ) {
+ assertTrue( objects[2] instanceof Name );
+ assertTrue( objects[3] instanceof Course );
+ }
+ else {
+ assertNull( objects[2] );
+ assertNull( objects[3] );
+ }
+ }
+
+ Object[] aResult = ( Object[] ) s.createCriteria( Student.class )
+ .setCacheable( true )
+ .add( Restrictions.idEq( new Long( 667 ) ) )
+ .setProjection(
+ Projections.projectionList()
+ .add( Projections.id().as( "studentNumber" ) )
+ .add( Property.forName( "name" ), "name" )
+ .add( Property.forName( "cityState" ), "cityState" )
+ .add( Property.forName( "preferredCourse" ), "preferredCourse" )
+ )
+ .uniqueResult();
+ assertNotNull( aResult );
+ assertEquals( 4, aResult.length );
+ assertTrue( aResult[0] instanceof Long );
+ assertTrue( aResult[1] instanceof String );
+ assertTrue( aResult[2] instanceof Name );
+ assertTrue( aResult[3] instanceof Course );
+
+ Long count = ( Long ) s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .setProjection( Property.forName( "studentNumber" ).count().setDistinct() )
+ .uniqueResult();
+ assertEquals( count, new Long( 2 ) );
+
+ Object object = s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "studentNumber" ).count() )
+ .add( Property.forName( "studentNumber" ).max() )
+ .add( Property.forName( "studentNumber" ).min() )
+ .add( Property.forName( "studentNumber" ).avg() )
+ )
+ .uniqueResult();
+ Object[] result = ( Object[] ) object;
+
+ assertEquals( new Long( 2 ), result[0] );
+ assertEquals( new Long( 667 ), result[1] );
+ assertEquals( new Long( 101 ), result[2] );
+ assertEquals( 384.0, ( ( Double ) result[3] ).doubleValue(), 0.01 );
+
+
+ s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .add( Property.forName( "studentNumber" ).gt( new Long( 665 ) ) )
+ .add( Property.forName( "studentNumber" ).lt( new Long( 668 ) ) )
+ .add( Property.forName( "courseCode" ).like( "HIB", MatchMode.START ) )
+ .add( Property.forName( "year" ).eq( new Short( ( short ) 1999 ) ) )
+ .addOrder( Property.forName( "studentNumber" ).asc() )
+ .uniqueResult();
+
+ List resultWithMaps = s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "studentNumber" ).as( "stNumber" ) )
+ .add( Property.forName( "courseCode" ).as( "cCode" ) )
+ )
+ .add( Property.forName( "studentNumber" ).gt( new Long( 665 ) ) )
+ .add( Property.forName( "studentNumber" ).lt( new Long( 668 ) ) )
+ .addOrder( Property.forName( "studentNumber" ).asc() )
+ .setResultTransformer( Criteria.ALIAS_TO_ENTITY_MAP )
+ .list();
+
+ assertEquals( 1, resultWithMaps.size() );
+ Map m1 = ( Map ) resultWithMaps.get( 0 );
+
+ assertEquals( new Long( 667 ), m1.get( "stNumber" ) );
+ assertEquals( courseExpected.getCourseCode(), m1.get( "cCode" ) );
+
+ resultWithMaps = s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .setProjection( Property.forName( "studentNumber" ).as( "stNumber" ) )
+ .addOrder( Order.desc( "stNumber" ) )
+ .setResultTransformer( Criteria.ALIAS_TO_ENTITY_MAP )
+ .list();
+
+ assertEquals( 2, resultWithMaps.size() );
+ Map m0 = ( Map ) resultWithMaps.get( 0 );
+ m1 = ( Map ) resultWithMaps.get( 1 );
+
+ assertEquals( new Long( 101 ), m1.get( "stNumber" ) );
+ assertEquals( new Long( 667 ), m0.get( "stNumber" ) );
+
+ List resultWithAliasedBean = s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .createAlias( "student", "st" )
+ .createAlias( "courseExpected", "co" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "st.name" ).as( "studentName" ) )
+ .add( Property.forName( "co.description" ).as( "courseDescription" ) )
+ )
+ .addOrder( Order.desc( "studentName" ) )
+ .setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) )
+ .list();
+
+ assertEquals( 2, resultWithAliasedBean.size() );
+
+ StudentDTO dto = ( StudentDTO ) resultWithAliasedBean.get( 0 );
+ assertNotNull( dto.getDescription() );
+ assertNotNull( dto.getName() );
+
+ CourseMeeting courseMeetingDto = ( CourseMeeting ) s.createCriteria( CourseMeeting.class )
+ .setCacheable( true )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "id" ).as( "id" ) )
+ .add( Property.forName( "courseExpected" ).as( "courseExpected" ) )
+ )
+ .addOrder( Order.desc( "id" ) )
+ .setResultTransformer( Transformers.aliasToBean( CourseMeeting.class ) )
+ .uniqueResult();
+
+ assertNotNull( courseMeetingDto.getId() );
+ assertEquals( courseExpected.getCourseCode(), courseMeetingDto.getId().getCourseCode() );
+ assertEquals( "Monday", courseMeetingDto.getId().getDay() );
+ assertEquals( "1313 Mockingbird Lane", courseMeetingDto.getId().getLocation() );
+ assertEquals( 1, courseMeetingDto.getId().getPeriod() );
+ assertEquals( courseExpected.getDescription(), courseMeetingDto.getCourse().getDescription() );
+
+ s.createCriteria( Student.class )
+ .setCacheable( true )
+ .add( Restrictions.like( "name", "yogiExpected", MatchMode.START ) )
+ .addOrder( Order.asc( "name" ) )
+ .createCriteria( "enrolments", "e" )
+ .addOrder( Order.desc( "year" ) )
+ .addOrder( Order.desc( "semester" ) )
+ .createCriteria( "courseExpected", "c" )
+ .addOrder( Order.asc( "description" ) )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "this.name" ) )
+ .add( Property.forName( "e.year" ) )
+ .add( Property.forName( "e.semester" ) )
+ .add( Property.forName( "c.courseCode" ) )
+ .add( Property.forName( "c.description" ) )
+ )
+ .uniqueResult();
+
+ Projection p1 = Projections.projectionList()
+ .add( Property.forName( "studentNumber" ).count() )
+ .add( Property.forName( "studentNumber" ).max() )
+ .add( Projections.rowCount() );
+
+ Projection p2 = Projections.projectionList()
+ .add( Property.forName( "studentNumber" ).min() )
+ .add( Property.forName( "studentNumber" ).avg() )
+ .add(
+ Projections.sqlProjection(
+ "1 as constOne, count(*) as countStar",
+ new String[] { "constOne", "countStar" },
+ new Type[] { Hibernate.INTEGER, Hibernate.INTEGER }
+ )
+ );
+
+ Object[] array = ( Object[] ) s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .setProjection( Projections.projectionList().add( p1 ).add( p2 ) )
+ .uniqueResult();
+
+ assertEquals( array.length, 7 );
+
+ List list = s.createCriteria( Enrolment.class )
+ .setCacheable( true )
+ .createAlias( "student", "st" )
+ .createAlias( "courseExpected", "co" )
+ .setProjection(
+ Projections.projectionList()
+ .add( Property.forName( "co.courseCode" ).group() )
+ .add( Property.forName( "st.studentNumber" ).count().setDistinct() )
+ .add( Property.forName( "year" ).group() )
+ )
+ .list();
+
+ assertEquals( list.size(), 2 );
+ }
+*/
+ protected void clearCache() {
+ getSessions().getCache().evictQueryRegions();
+ }
+
+ protected void clearStatistics() {
+ getSessions().getStatistics().clear();
+ }
+
+ protected void assertEntityFetchCount(int expected) {
+ int actual = ( int ) getSessions().getStatistics().getEntityFetchCount();
+ assertEquals( expected, actual );
+ }
+
+ protected void assertCount(int expected) {
+ int actual = ( int ) getSessions().getStatistics().getQueries().length;
+ assertEquals( expected, actual );
+ }
+
+ protected void assertHitCount(int expected) {
+ int actual = ( int ) getSessions().getStatistics().getQueryCacheHitCount();
+ assertEquals( expected, actual );
+ }
+
+ protected void assertMissCount(int expected) {
+ int actual = ( int ) getSessions().getStatistics().getQueryCacheMissCount();
+ assertEquals( expected, actual );
+ }
+
+ protected void assertPutCount(int expected) {
+ int actual = ( int ) getSessions().getStatistics().getQueryCachePutCount();
+ assertEquals( expected, actual );
+ }
+
+ protected void assertInsertCount(int expected) {
+ int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
+ assertEquals( "unexpected insert count", expected, inserts );
+ }
+
+ protected void assertUpdateCount(int expected) {
+ int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
+ assertEquals( "unexpected update counts", expected, updates );
+ }
+
+ protected void assertDeleteCount(int expected) {
+ int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
+ assertEquals( "unexpected delete counts", expected, deletes );
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Address.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Address.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Address.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,134 @@
+// $Id: Address.java 7996 2005-08-22 14:49:57Z steveebersole $
+package org.hibernate.test.querycache;
+
+/**
+ * Implementation of Address.
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+ private long id;
+ private String addressType;
+ private String street;
+ private String city;
+ private String stateProvince;
+ private String postalCode;
+ private String country;
+ private Student student;
+
+ public Address() {}
+
+ public Address(Student student, String type, String street, String city, String stateProvince, String postalCode, String country) {
+ this.student = student;
+ this.addressType = type;
+ this.street = street;
+ this.city = city;
+ this.stateProvince = stateProvince;
+ this.postalCode = postalCode;
+ this.country = country;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public Student getStudent() {
+ return student;
+ }
+
+ public void setStudent(Student student) {
+ this.student = student;
+ }
+
+ public String getAddressType() {
+ return addressType;
+ }
+
+ public void setAddressType(String addressType) {
+ this.addressType = addressType;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getStateProvince() {
+ return stateProvince;
+ }
+
+ public void setStateProvince(String stateProvince) {
+ this.stateProvince = stateProvince;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ Address address = ( Address ) o;
+
+ if ( city != null ? !city.equals( address.city ) : address.city != null ) {
+ return false;
+ }
+ if ( country != null ? !country.equals( address.country ) : address.country != null ) {
+ return false;
+ }
+ if ( postalCode != null ? !postalCode.equals( address.postalCode ) : address.postalCode != null ) {
+ return false;
+ }
+ if ( stateProvince != null ? !stateProvince.equals( address.stateProvince ) : address.stateProvince != null ) {
+ return false;
+ }
+ if ( street != null ? !street.equals( address.street ) : address.street != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = street != null ? street.hashCode() : 0;
+ result = 31 * result + ( city != null ? city.hashCode() : 0 );
+ result = 31 * result + ( stateProvince != null ? stateProvince.hashCode() : 0 );
+ result = 31 * result + ( postalCode != null ? postalCode.hashCode() : 0 );
+ result = 31 * result + ( country != null ? country.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Course.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Course.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Course.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,60 @@
+//$Id: Course.java 5686 2005-02-12 07:27:32Z steveebersole $
+package org.hibernate.test.querycache;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Gavin King
+ */
+public class Course implements Serializable {
+ private String courseCode;
+ private String description;
+ private Set courseMeetings = new HashSet();
+
+ public String getCourseCode() {
+ return courseCode;
+ }
+ public void setCourseCode(String courseCode) {
+ this.courseCode = courseCode;
+ }
+ public String getDescription() {
+ return description;
+ }
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public Set getCourseMeetings() {
+ return courseMeetings;
+ }
+ public void setCourseMeetings(Set courseMeetings) {
+ this.courseMeetings = courseMeetings;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || ! ( o instanceof Course ) ) {
+ return false;
+ }
+
+ Course course = ( Course ) o;
+
+ if ( courseCode != null ? !courseCode.equals( course.getCourseCode() ) : course.getCourseCode() != null ) {
+ return false;
+ }
+ if ( description != null ? !description.equals( course.getDescription() ) : course.getDescription() != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = courseCode != null ? courseCode.hashCode() : 0;
+ result = 31 * result + ( description != null ? description.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeeting.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeeting.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeeting.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,55 @@
+package org.hibernate.test.querycache;
+
+/**
+ * @author Gail Badner
+ */
+public class CourseMeeting {
+ private CourseMeetingId id;
+ private Course course;
+
+ public CourseMeeting() {}
+
+ public CourseMeeting(Course course, String day, int period, String location) {
+ this.id = new CourseMeetingId( course, day, period, location );
+ this.course = course;
+ }
+
+ public CourseMeetingId getId() {
+ return id;
+ }
+ public void setId(CourseMeetingId id) {
+ this.id = id;
+ }
+ public Course getCourse() {
+ return course;
+ }
+ public void setCourse(Course course) {
+ this.course = course;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ CourseMeeting that = ( CourseMeeting ) o;
+
+ if ( course != null ? !course.equals( that.course ) : that.course != null ) {
+ return false;
+ }
+ if ( id != null ? !id.equals( that.id ) : that.id != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + ( course != null ? course.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeetingId.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeetingId.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CourseMeetingId.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,81 @@
+package org.hibernate.test.querycache;
+
+import java.io.Serializable;
+
+/**
+ * @author Gail Badner
+ */
+public class CourseMeetingId implements Serializable {
+ private String courseCode;
+ private String day;
+ private int period;
+ private String location;
+
+ public CourseMeetingId() {}
+
+ public CourseMeetingId(Course course, String day, int period, String location) {
+ this.courseCode = course.getCourseCode();
+ this.day = day;
+ this.period = period;
+ this.location = location;
+ }
+
+ public String getCourseCode() {
+ return courseCode;
+ }
+ public void setCourseCode(String courseCode) {
+ this.courseCode = courseCode;
+ }
+ public String getDay() {
+ return day;
+ }
+ public void setDay(String day) {
+ this.day = day;
+ }
+ public int getPeriod() {
+ return period;
+ }
+ public void setPeriod(int period) {
+ this.period = period;
+ }
+ public String getLocation() {
+ return location;
+ }
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ CourseMeetingId that = ( CourseMeetingId ) o;
+
+ if ( period != that.period ) {
+ return false;
+ }
+ if ( courseCode != null ? !courseCode.equals( that.courseCode ) : that.courseCode != null ) {
+ return false;
+ }
+ if ( day != null ? !day.equals( that.day ) : that.day != null ) {
+ return false;
+ }
+ if ( location != null ? !location.equals( that.location ) : that.location != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = courseCode != null ? courseCode.hashCode() : 0;
+ result = 31 * result + ( day != null ? day.hashCode() : 0 );
+ result = 31 * result + period;
+ result = 31 * result + ( location != null ? location.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheIgnoreResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheIgnoreResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheIgnoreResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,57 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class CriteriaQueryCacheIgnoreResultTransformerTest extends AbstractQueryCacheResultTransformerTest {
+
+ public CriteriaQueryCacheIgnoreResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CriteriaQueryCacheIgnoreResultTransformerTest.class );
+ }
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.IGNORE;
+ }
+
+ protected void runTest(HqlExecutor hqlExecutor, CriteriaExecutor criteriaExecutor, ResultChecker checker, boolean isSingleResult)
+ throws Exception {
+ createData();
+ if ( criteriaExecutor != null ) {
+ runTest( criteriaExecutor, checker, isSingleResult );
+ }
+ deleteData();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheNormalResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheNormalResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCacheNormalResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,48 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class CriteriaQueryCacheNormalResultTransformerTest extends CriteriaQueryCachePutResultTransformerTest {
+
+ public CriteriaQueryCacheNormalResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CriteriaQueryCacheNormalResultTransformerTest.class );
+ }
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.NORMAL;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCachePutResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCachePutResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/CriteriaQueryCachePutResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,181 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class CriteriaQueryCachePutResultTransformerTest extends CriteriaQueryCacheIgnoreResultTransformerTest {
+
+ public CriteriaQueryCachePutResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CriteriaQueryCachePutResultTransformerTest.class );
+ }
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.PUT;
+ }
+
+ protected boolean areDynamicNonLazyAssociationsChecked() {
+ return false;
+ }
+
+ public void testAliasToEntityMapNoProjectionList() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+
+ public void testAliasToEntityMapNoProjectionListFailureExpected() throws Exception {
+ super.testAliasToEntityMapNoProjectionList();
+ }
+
+ public void testAliasToEntityMapNoProjectionMultiAndNullList() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+ public void testAliasToEntityMapNoProjectionMultiAndNullListFailureExpected() throws Exception {
+ super.testAliasToEntityMapNoProjectionMultiAndNullList();
+ }
+
+ public void testAliasToEntityMapOneProjectionList() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+ public void testAliasToEntityMapOneProjectionListFailureExpected() throws Exception {
+ super.testAliasToEntityMapOneProjectionList();
+ }
+
+ public void testAliasToEntityMapMultiProjectionList() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+ public void testAliasToEntityMapMultiProjectionListFailureExpected() throws Exception {
+ super.testAliasToEntityMapMultiProjectionList();
+ }
+
+ public void testAliasToEntityMapMultiProjectionWithNullAliasList() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+ public void testAliasToEntityMapMultiProjectionWithNullAliasListFailureExpected() throws Exception {
+ super.testAliasToEntityMapMultiProjectionWithNullAliasList();
+ }
+
+ public void testAliasToEntityMapMultiAggregatedPropProjectionSingleResult() {
+ reportSkip( "Transformers.ALIAS_TO_ENTITY_MAP with Criteria fails when try put in cache",
+ "Cache results using Transformers.ALIAS_TO_ENTITY_MAP with Criteria" );
+ }
+ public void testAliasToEntityMapMultiAggregatedPropProjectionSingleResultFailureExpected() throws Exception {
+ super.testAliasToEntityMapMultiAggregatedPropProjectionSingleResult();
+ }
+
+ public void testAliasToBeanDtoOneArgList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testAliasToBeanDtoOneArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoOneArgList();
+ }
+
+ public void testAliasToBeanDtoMultiArgList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testAliasToBeanDtoMultiArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoMultiArgList();
+ }
+
+ public void testAliasToBeanDtoLiteralArgList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testAliasToBeanDtoLiteralArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoLiteralArgList();
+ }
+
+ public void testAliasToBeanDtoWithNullAliasList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testAliasToBeanDtoWithNullAliasListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoWithNullAliasList();
+ }
+
+ public void testOneSelectNewList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testOneSelectNewListFailureExpected() throws Exception {
+ super.testOneSelectNewList();
+ }
+
+ public void testMultiSelectNewList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testMultiSelectNewListFailureExpected() throws Exception {
+ super.testMultiSelectNewList();
+ }
+
+ public void testMultiSelectNewWithLiteralList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testMultiSelectNewWithLiteralListFailureExpected() throws Exception {
+ super.testMultiSelectNewWithLiteralList();
+ }
+
+ public void testMultiSelectNewListList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testMultiSelectNewListListFailureExpected() throws Exception {
+ super.testMultiSelectNewListList();
+ }
+
+ public void testMultiSelectNewMapList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testMultiSelectNewMapListFailureExpected() throws Exception {
+ super.testMultiSelectNewMapList();
+ }
+
+ public void testSelectNewEntityConstructorList() {
+ reportSkip( "Transformers.aliasToBean with Criteria fails when try put in cache",
+ "Cache results using Transformers.aliasToBean with Criteria" );
+ }
+ public void testSelectNewEntityConstructorListFailureExpected() throws Exception {
+ super.testMultiSelectNewMapList();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.hbm.xml 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,90 @@
+<?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.querycache">
+
+ <class name="Course">
+ <id name="courseCode">
+ <generator class="assigned"/>
+ </id>
+ <property name="description"/>
+ <set name="courseMeetings" inverse="true" cascade="all-delete-orphan" lazy="false">
+ <key column="courseCode"/>
+ <one-to-many class="CourseMeeting"/>
+ </set>
+ </class>
+
+ <class name="CourseMeeting">
+ <composite-id name="id" class="CourseMeetingId">
+ <key-property name="courseCode"/>
+ <key-property name="day"/>
+ <key-property name="period"/>
+ <key-property name="location"/>
+ </composite-id>
+ <many-to-one name="course" insert="false" update="false" lazy="false">
+ <column name="courseCode"/>
+ </many-to-one>
+ </class>
+
+ <class name="Student">
+ <id name="studentNumber">
+ <column name="studentId"/>
+ <generator class="assigned"/>
+ </id>
+ <component name="name">
+ <property name="first" column="name_first" not-null="true"/>
+ <property name="middle" column="name_middle" not-null="false"/>
+ <property name="last" column="name_last" not-null="true"/>
+ </component>
+ <set name="enrolments" inverse="true" cascade="delete">
+ <key column="studentId"/>
+ <one-to-many class="Enrolment"/>
+ </set>
+ <map name="addresses" table="addresses" cascade="all,delete" lazy="true">
+ <key column="studentNumber"/>
+ <map-key column="addressType" type="string"/>
+ <one-to-many class="Address"/>
+ </map>
+ <many-to-one name="preferredCourse" column="preferredCourseCode" lazy="proxy"/>
+ <list name="secretCodes" lazy="false">
+ <key>
+ <column name="studentNumber"/>
+ </key>
+ <index column="i"/>
+ <element column="secretCode" type="int"/>
+ </list>
+ </class>
+
+ <class name="Address">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <property name="addressType"/>
+ <property name="street"/>
+ <property name="city"/>
+ <property name="stateProvince"/>
+ <property name="postalCode"/>
+ <property name="country"/>
+ <many-to-one name="student" class="Student" column="studentNumber" not-null="false"/>
+ </class>
+
+ <class name="Enrolment">
+ <composite-id>
+ <key-property name="studentNumber">
+ <column name="studentId"/>
+ </key-property>
+ <key-property name="courseCode"/>
+ </composite-id>
+ <many-to-one name="student" insert="false" update="false" lazy="proxy">
+ <column name="studentId"/>
+ </many-to-one>
+ <many-to-one name="course" insert="false" update="false" lazy="false">
+ <column name="courseCode"/>
+ </many-to-one>
+ <property name="semester" type="short" not-null="true"/>
+ <property name="year" column="`year`" type="short" not-null="true"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Enrolment.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,87 @@
+//$Id: Enrolment.java 6970 2005-05-31 20:24:41Z oneovthafew $
+package org.hibernate.test.querycache;
+
+import java.io.Serializable;
+
+/**
+ * @author Gavin King
+ */
+public class Enrolment implements Serializable {
+ private Student student;
+ private Course course;
+ private long studentNumber;
+ private String courseCode;
+ private short year;
+ private short semester;
+
+ public String getCourseCode() {
+ return courseCode;
+ }
+ public void setCourseCode(String courseId) {
+ this.courseCode = courseId;
+ }
+ public long getStudentNumber() {
+ return studentNumber;
+ }
+ public void setStudentNumber(long studentId) {
+ this.studentNumber = studentId;
+ }
+ public Course getCourse() {
+ return course;
+ }
+ public void setCourse(Course course) {
+ this.course = course;
+ }
+ public Student getStudent() {
+ return student;
+ }
+ public void setStudent(Student student) {
+ this.student = student;
+ }
+ public short getSemester() {
+ return semester;
+ }
+ public void setSemester(short semester) {
+ this.semester = semester;
+ }
+ public short getYear() {
+ return year;
+ }
+ public void setYear(short year) {
+ this.year = year;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ Enrolment enrolment = ( Enrolment ) o;
+
+ if ( semester != enrolment.semester ) {
+ return false;
+ }
+ if ( studentNumber != enrolment.studentNumber ) {
+ return false;
+ }
+ if ( year != enrolment.year ) {
+ return false;
+ }
+ if ( courseCode != null ? !courseCode.equals( enrolment.courseCode ) : enrolment.courseCode != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = ( int ) ( studentNumber ^ ( studentNumber >>> 32 ) );
+ result = 31 * result + ( courseCode != null ? courseCode.hashCode() : 0 );
+ result = 31 * result + ( int ) year;
+ result = 31 * result + ( int ) semester;
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheIgnoreResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheIgnoreResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheIgnoreResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,73 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class HqlQueryCacheIgnoreResultTransformerTest extends AbstractQueryCacheResultTransformerTest {
+
+ public HqlQueryCacheIgnoreResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( HqlQueryCacheIgnoreResultTransformerTest.class );
+ }
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.IGNORE;
+ }
+
+ protected void runTest(HqlExecutor hqlExecutor, CriteriaExecutor criteriaExecutor, ResultChecker checker, boolean isSingleResult)
+ throws Exception {
+ createData();
+ if ( hqlExecutor != null ) {
+ runTest( hqlExecutor, checker, isSingleResult );
+ }
+ deleteData();
+ }
+
+ public void testAliasToEntityMapNoProjectionList() throws Exception {
+ reportSkip( "known to fail using HQL", "HQL query using Transformers.ALIAS_TO_ENTITY_MAP with no projection" );
+ }
+
+ public void testAliasToEntityMapNoProjectionListFailureExpected() throws Exception {
+ super.testAliasToEntityMapNoProjectionList();
+ }
+
+ public void testAliasToEntityMapNoProjectionMultiAndNullList() throws Exception {
+ reportSkip( "known to fail using HQL", "HQL query using Transformers.ALIAS_TO_ENTITY_MAP with no projection" );
+ }
+
+ public void testAliasToEntityMapNoProjectionMultiAndNullListFailureExpected() throws Exception {
+ super.testAliasToEntityMapNoProjectionMultiAndNullList();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheNormalResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheNormalResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCacheNormalResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,73 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class HqlQueryCacheNormalResultTransformerTest extends HqlQueryCachePutResultTransformerTest {
+
+ public HqlQueryCacheNormalResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( HqlQueryCacheNormalResultTransformerTest.class );
+ }
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.NORMAL;
+ }
+
+ public void testAliasToBeanDtoMultiArgList() {
+ reportSkip( "Results from queries using Transformers.aliasToBean cannot be found in the cache due to bug in hashCode",
+ "Query using Transformers.aliasToBean with cache"
+ );
+ }
+ public void testAliasToBeanDtoMultiArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoMultiArgList();
+ }
+
+ public void testAliasToBeanDtoLiteralArgList() {
+ reportSkip( "Results from queries using Transformers.aliasToBean cannot be found in the cache due to bug in hashCode",
+ "Query using Transformers.aliasToBean with cache" );
+ }
+ public void testAliasToBeanDtoLiteralArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoLiteralArgList();
+ }
+
+ public void testAliasToBeanDtoWithNullAliasList() {
+ reportSkip( "Results from queries using Transformers.aliasToBean cannot be found in the cache due to bug in hashCode",
+ "Query using Transformers.aliasToBean with cache" );
+ }
+ public void testAliasToBeanDtoWithNullAliasListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoWithNullAliasList();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCachePutResultTransformerTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCachePutResultTransformerTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/HqlQueryCachePutResultTransformerTest.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,78 @@
+/*
+ * 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.querycache;
+
+import junit.framework.Test;
+
+import org.hibernate.CacheMode;
+import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gail Badner
+ */
+public class HqlQueryCachePutResultTransformerTest extends HqlQueryCacheIgnoreResultTransformerTest {
+
+ public HqlQueryCachePutResultTransformerTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( HqlQueryCachePutResultTransformerTest.class );
+ }
+
+
+ protected CacheMode getQueryCacheMode() {
+ return CacheMode.PUT;
+ }
+
+ protected boolean areDynamicNonLazyAssociationsChecked() {
+ return false;
+ }
+
+ public void testAliasToEntityMapOneProjectionList() {
+ reportSkip( "HQL queries using a ResultTransformer are known to fail when caching a row with a single value",
+ "HQL queries using a ResultTransformer has row with a single value");
+ }
+ public void testAliasToEntityMapOneProjectionListFailureExpected() throws Exception {
+ super.testAliasToEntityMapOneProjectionList();
+ }
+
+ public void testAliasToBeanDtoOneArgList() {
+ reportSkip( "HQL queries using a ResultTransformer are known to fail when caching a row with a single value",
+ "HQL queries using a ResultTransformer has row with a single value");
+ }
+
+ public void testAliasToBeanDtoOneArgListFailureExpected() throws Exception {
+ super.testAliasToBeanDtoOneArgList();
+ }
+
+ public void testOneSelectNewList() {
+ reportSkip( "HQL queries using a ResultTransformer are known to fail when caching a row with a single value",
+ "HQL queries using a ResultTransformer has row with a single value");
+ }
+ public void testOneSelectNewListFailureExpected() throws Exception {
+ super.testOneSelectNewList();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/PersonName.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/PersonName.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/PersonName.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,96 @@
+/*
+ * 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.querycache;
+
+/**
+ * @author Gail Badner
+ */
+
+public class PersonName {
+ private String first;
+ private String middle;
+ private String last;
+
+ public PersonName() {}
+
+ public PersonName(String first, String middle, String state) {
+ this.first = first;
+ this.middle = middle;
+ this.last = state;
+ }
+
+ public String getFirst() {
+ return first;
+ }
+
+ public void setFirst(String first) {
+ this.first = first;
+ }
+
+ public String getMiddle() {
+ return middle;
+ }
+
+ public void setMiddle(String middle) {
+ this.middle = middle;
+ }
+
+ public String getLast() {
+ return last;
+ }
+
+ public void setLast(String last) {
+ this.last = last;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ PersonName name = ( PersonName ) o;
+
+ if ( first != null ? !first.equals( name.first ) : name.first != null ) {
+ return false;
+ }
+ if ( middle != null ? !middle.equals( name.middle ) : name.middle != null ) {
+ return false;
+ }
+ if ( last != null ? !last.equals( name.last ) : name.last != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = first != null ? first.hashCode() : 0;
+ result = 31 * result + ( last != null ? last.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Student.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Student.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/Student.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,102 @@
+//$Id: Student.java 9116 2006-01-23 21:21:01Z steveebersole $
+package org.hibernate.test.querycache;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Gavin King
+ */
+public class Student {
+ private long studentNumber;
+ private PersonName name;
+ private Course preferredCourse;
+ private Set enrolments = new HashSet();
+ private Map addresses = new HashMap();
+ private List secretCodes = new ArrayList();
+
+ public Student() {}
+
+ public Student(long studentNumber, PersonName name) {
+ this.studentNumber = studentNumber;
+ this.name = name;
+ }
+
+ public PersonName getName() {
+ return name;
+ }
+
+ public void setName(PersonName name) {
+ this.name = name;
+ }
+
+ public long getStudentNumber() {
+ return studentNumber;
+ }
+
+ public void setStudentNumber(long studentNumber) {
+ this.studentNumber = studentNumber;
+ }
+
+ public Map getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(Map addresses) {
+ this.addresses = addresses;
+ }
+
+ public Course getPreferredCourse() {
+ return preferredCourse;
+ }
+
+ public void setPreferredCourse(Course preferredCourse) {
+ this.preferredCourse = preferredCourse;
+ }
+
+ public Set getEnrolments() {
+ return enrolments;
+ }
+
+ public void setEnrolments(Set employments) {
+ this.enrolments = employments;
+ }
+
+ public List getSecretCodes() {
+ return secretCodes;
+ }
+
+ public void setSecretCodes(List secretCodes) {
+ this.secretCodes = secretCodes;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || ! ( o instanceof Student ) ) {
+ return false;
+ }
+
+ Student student = ( Student ) o;
+
+ if ( studentNumber != student.getStudentNumber() ) {
+ return false;
+ }
+ if ( name != null ? !name.equals( student.getName() ) : student.getName() != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = ( int ) ( studentNumber ^ ( studentNumber >>> 32 ) );
+ result = 31 * result + ( name != null ? name.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/StudentDTO.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/StudentDTO.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/StudentDTO.java 2010-07-28 18:55:13 UTC (rev 20074)
@@ -0,0 +1,60 @@
+/*
+ * Created on 28-Jan-2005
+ *
+ */
+package org.hibernate.test.querycache;
+
+/**
+ * @author max
+ *
+ */
+public class StudentDTO {
+
+ private PersonName studentName;
+ private String courseDescription;
+
+ public StudentDTO() { }
+
+ public StudentDTO(PersonName name) {
+ this.studentName = name;
+ }
+
+ public StudentDTO(PersonName name, String description) {
+ this.studentName = name;
+ this.courseDescription = description;
+ }
+
+ public PersonName getName() {
+ return studentName;
+ }
+
+ public String getDescription() {
+ return courseDescription;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ StudentDTO that = ( StudentDTO ) o;
+
+ if ( courseDescription != null ? !courseDescription.equals( that.courseDescription ) : that.courseDescription != null ) {
+ return false;
+ }
+ if ( studentName != null ? !studentName.equals( that.studentName ) : that.studentName != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = studentName != null ? studentName.hashCode() : 0;
+ result = 31 * result + ( courseDescription != null ? courseDescription.hashCode() : 0 );
+ return result;
+ }
+}
\ No newline at end of file
14 years, 5 months
Hibernate SVN: r20073 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-27 12:17:42 -0400 (Tue, 27 Jul 2010)
New Revision: 20073
Added:
core/trunk/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
Log:
HHH-5420 introducing new dialect for ms sql server 2008 with jdbc 3.0 and above
Added: core/trunk/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java 2010-07-27 16:17:42 UTC (rev 20073)
@@ -0,0 +1,45 @@
+/*
+ * 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.dialect;
+
+import java.sql.Types;
+
+import org.hibernate.Hibernate;
+import org.hibernate.dialect.function.NoArgSQLFunction;
+
+/**
+ * A dialect for Microsoft SQL Server 2008 with JDBC Driver 3.0 and above
+ *
+ * @author Gavin King
+ */
+public class SQLServer2008Dialect extends SQLServerDialect {
+ public SQLServer2008Dialect(){
+ registerColumnType( Types.DATE, "date" );
+ registerColumnType( Types.TIME, "time" );
+ registerColumnType( Types.TIMESTAMP, "datetime2" );
+
+ registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP,false) );
+ }
+}
14 years, 5 months
Hibernate SVN: r20072 - core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-27 12:05:51 -0400 (Tue, 27 Jul 2010)
New Revision: 20072
Added:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
Log:
HHH-5420 introducing new dialect for ms sql server 2008 with jdbc 3.0 and above
Added: core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java (rev 0)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java 2010-07-27 16:05:51 UTC (rev 20072)
@@ -0,0 +1,44 @@
+/*
+ * 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.dialect;
+
+import java.sql.Types;
+
+import org.hibernate.Hibernate;
+import org.hibernate.dialect.function.NoArgSQLFunction;
+
+/**
+ * A dialect for Microsoft SQL Server 2008 with JDBC Driver 3.0 and above
+ *
+ * @author Strong Liu
+ */
+public class SQLServer2008Dialect extends SQLServerDialect {
+ public SQLServer2008Dialect(){
+ registerColumnType( Types.DATE, "date" );
+ registerColumnType( Types.TIME, "time" );
+ registerColumnType( Types.TIMESTAMP, "datetime2" );
+ registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP,false) );
+ }
+}
14 years, 5 months
Hibernate SVN: r20071 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-27 11:52:04 -0400 (Tue, 27 Jul 2010)
New Revision: 20071
Added:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
Log:
JBPAPP-4738 HHH-5420 introducing new dialect for ms sql server 2008 with jdbc 3.0 and above
Added: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java 2010-07-27 15:52:04 UTC (rev 20071)
@@ -0,0 +1,45 @@
+/*
+ * 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.dialect;
+
+import java.sql.Types;
+
+import org.hibernate.Hibernate;
+import org.hibernate.dialect.function.NoArgSQLFunction;
+
+/**
+ * A dialect for Microsoft SQL Server 2008 with JDBC Driver 3.0 and above
+ *
+ * @author Gavin King
+ */
+public class SQLServer2008Dialect extends SQLServerDialect {
+ public SQLServer2008Dialect(){
+ registerColumnType( Types.DATE, "date" );
+ registerColumnType( Types.TIME, "time" );
+ registerColumnType( Types.TIMESTAMP, "datetime2" );
+
+ registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP,false) );
+ }
+}
14 years, 5 months
Hibernate SVN: r20070 - in core/trunk: core/src/main/java/org/hibernate/type/descriptor and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-26 16:03:49 -0400 (Mon, 26 Jul 2010)
New Revision: 20070
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/jdbc/BlobProxy.java
core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/BinaryStream.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BinaryStreamImpl.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java
core/trunk/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java
Log:
HHH-5400 - Blob persistence fails with Hibernate 3.6.0-SNAPSHOT, works with 3.5.3-Final
Modified: core/trunk/core/src/main/java/org/hibernate/engine/jdbc/BlobProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/jdbc/BlobProxy.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/engine/jdbc/BlobProxy.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -29,9 +29,11 @@
import java.sql.Blob;
import java.sql.SQLException;
import java.io.InputStream;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
+import org.hibernate.type.descriptor.java.BinaryStreamImpl;
+import org.hibernate.type.descriptor.java.DataHelper;
+
/**
* Manages aspects of proxying {@link Blob Blobs} for non-contextual creation, including proxy creation and
* handling proxy invocations.
@@ -48,18 +50,18 @@
private boolean needsReset = false;
/**
- * Ctor used to build {@link Blob} from byte array.
+ * Constructor used to build {@link Blob} from byte array.
*
* @param bytes The byte array
* @see #generateProxy(byte[])
*/
private BlobProxy(byte[] bytes) {
- this.stream = new ByteArrayInputStream( bytes );
+ this.stream = new BinaryStreamImpl( bytes );
this.length = bytes.length;
}
/**
- * Ctor used to build {@link Blob} from a stream.
+ * Constructor used to build {@link Blob} from a stream.
*
* @param stream The binary stream
* @param length The length of the stream
@@ -93,26 +95,62 @@
* @throws UnsupportedOperationException if any methods other than {@link Blob#length()}
* or {@link Blob#getBinaryStream} are invoked.
*/
+ @SuppressWarnings({ "UnnecessaryBoxing" })
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if ( "length".equals( method.getName() ) ) {
- return new Long( getLength() );
+ final String methodName = method.getName();
+ final int argCount = method.getParameterTypes().length;
+
+ if ( "length".equals( methodName ) && argCount == 0 ) {
+ return Long.valueOf( getLength() );
}
- if ( "getBinaryStream".equals( method.getName() ) && method.getParameterTypes().length == 0 ) {
- return getStream();
+ if ( "getBinaryStream".equals( methodName ) ) {
+ if ( argCount == 0 ) {
+ return getStream();
+ }
+ else if ( argCount == 2 ) {
+ long start = (Long) args[0];
+ if ( start < 1 ) {
+ throw new SQLException( "Start position 1-based; must be 1 or more." );
+ }
+ if ( start > getLength() ) {
+ throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" );
+ }
+ int length = (Integer) args[1];
+ if ( length < 0 ) {
+ // java docs specifically say for getBinaryStream(long,int) that the start+length must not exceed the
+ // total length, however that is at odds with the getBytes(long,int) behavior.
+ throw new SQLException( "Length must be great-than-or-equal to zero." );
+ }
+ return DataHelper.subStream( getStream(), start-1, length );
+ }
}
- if ( "free".equals( method.getName() ) ) {
+ if ( "getBytes".equals( methodName ) ) {
+ if ( argCount == 2 ) {
+ long start = (Long) args[0];
+ if ( start < 1 ) {
+ throw new SQLException( "Start position 1-based; must be 1 or more." );
+ }
+ int length = (Integer) args[1];
+ if ( length < 0 ) {
+ throw new SQLException( "Length must be great-than-or-equal to zero." );
+ }
+ return DataHelper.extractBytes( getStream(), start-1, length );
+ }
+ }
+ if ( "free".equals( methodName ) && argCount == 0 ) {
stream.close();
return null;
}
- if ( "toString".equals( method.getName() ) ) {
+ if ( "toString".equals( methodName ) && argCount == 0 ) {
return this.toString();
}
- if ( "equals".equals( method.getName() ) ) {
+ if ( "equals".equals( methodName ) && argCount == 1 ) {
return Boolean.valueOf( proxy == args[0] );
}
- if ( "hashCode".equals( method.getName() ) ) {
+ if ( "hashCode".equals( methodName ) && argCount == 0 ) {
return new Integer( this.hashCode() );
}
+
throw new UnsupportedOperationException( "Blob may not be manipulated from creating session" );
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -33,6 +33,8 @@
import java.io.InputStream;
import java.io.IOException;
+import org.hibernate.type.descriptor.java.DataHelper;
+
/**
* Manages aspects of proxying {@link Clob Clobs} for non-contextual creation, including proxy creation and
* handling proxy invocations.
@@ -51,7 +53,7 @@
/**
- * Ctor used to build {@link Clob} from string data.
+ * Constructor used to build {@link Clob} from string data.
*
* @param string The byte array
* @see #generateProxy(String)
@@ -63,7 +65,7 @@
}
/**
- * Ctor used to build {@link Clob} from a reader.
+ * Constructor used to build {@link Clob} from a reader.
*
* @param reader The character reader.
* @param length The length of the reader stream.
@@ -88,12 +90,13 @@
return reader;
}
- protected String getSubString(long pos, int length) {
+ protected String getSubString(long start, int length) {
if ( string == null ) {
throw new UnsupportedOperationException( "Clob was not created from string; cannot substring" );
}
- // naive impl...
- return string.substring( (int)pos-1, (int)(pos+length-1) );
+ // semi-naive implementation
+ int endIndex = Math.min( ((int)start)+length, string.length() );
+ return string.substring( (int)start, endIndex );
}
/**
@@ -104,31 +107,64 @@
*/
@SuppressWarnings({ "UnnecessaryBoxing" })
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if ( "length".equals( method.getName() ) ) {
+ final String methodName = method.getName();
+ final int argCount = method.getParameterTypes().length;
+
+ if ( "length".equals( methodName ) && argCount == 0 ) {
return Long.valueOf( getLength() );
}
- if ( "getAsciiStream".equals( method.getName() ) ) {
+ if ( "getAsciiStream".equals( methodName ) && argCount == 0 ) {
return getAsciiStream();
}
- if ( "getCharacterStream".equals( method.getName() ) ) {
- return getCharacterStream();
+ if ( "getCharacterStream".equals( methodName ) ) {
+ if ( argCount == 0 ) {
+ return getCharacterStream();
+ }
+ else if ( argCount == 2 ) {
+ long start = (Long) args[0];
+ if ( start < 1 ) {
+ throw new SQLException( "Start position 1-based; must be 1 or more." );
+ }
+ if ( start > getLength() ) {
+ throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" );
+ }
+ int length = (Integer) args[1];
+ if ( length < 0 ) {
+ // java docs specifically say for getCharacterStream(long,int) that the start+length must not exceed the
+ // total length, however that is at odds with the getSubString(long,int) behavior.
+ throw new SQLException( "Length must be great-than-or-equal to zero." );
+ }
+ return DataHelper.subStream( getCharacterStream(), start-1, length );
+ }
}
- if ( "getSubString".equals( method.getName() ) ) {
- return getSubString( (Long)args[0], (Integer)args[1] );
+ if ( "getSubString".equals( methodName ) && argCount == 2 ) {
+ long start = (Long) args[0];
+ if ( start < 1 ) {
+ throw new SQLException( "Start position 1-based; must be 1 or more." );
+ }
+ if ( start > getLength() ) {
+ throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" );
+ }
+ int length = (Integer) args[1];
+ if ( length < 0 ) {
+ throw new SQLException( "Length must be great-than-or-equal to zero." );
+ }
+ return getSubString( start-1, length );
}
- if ( "free".equals( method.getName() ) ) {
+ if ( "free".equals( methodName ) && argCount == 0 ) {
reader.close();
return null;
}
- if ( "toString".equals( method.getName() ) ) {
+ if ( "toString".equals( methodName ) && argCount == 0 ) {
return this.toString();
}
- if ( "equals".equals( method.getName() ) ) {
+ if ( "equals".equals( methodName ) && argCount == 1 ) {
return Boolean.valueOf( proxy == args[0] );
}
- if ( "hashCode".equals( method.getName() ) ) {
+ if ( "hashCode".equals( methodName ) && argCount == 0 ) {
return new Integer( this.hashCode() );
}
+
throw new UnsupportedOperationException( "Clob may not be manipulated from creating session" );
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/BinaryStream.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/BinaryStream.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/BinaryStream.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -39,6 +39,13 @@
public InputStream getInputStream();
/**
+ * Access to the bytes.
+ *
+ * @return The bytes.
+ */
+ public byte[] getBytes();
+
+ /**
* Retrieve the length of the input stream
*
* @return The input stream length
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BinaryStreamImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BinaryStreamImpl.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BinaryStreamImpl.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -33,19 +33,23 @@
*
* @author Steve Ebersole
*/
-public class BinaryStreamImpl implements BinaryStream {
- private final ByteArrayInputStream stream;
+public class BinaryStreamImpl extends ByteArrayInputStream implements BinaryStream {
private final int length;
public BinaryStreamImpl(byte[] bytes) {
- this.stream = new ByteArrayInputStream( bytes );
+ super( bytes );
this.length = bytes.length;
}
public InputStream getInputStream() {
- return stream;
+ return this;
}
+ public byte[] getBytes() {
+ // from ByteArrayInputStream
+ return buf;
+ }
+
public int getLength() {
return length;
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -27,11 +27,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.io.StringReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
+import org.hibernate.type.descriptor.BinaryStream;
import org.hibernate.util.ReflectHelper;
/**
@@ -84,7 +86,46 @@
return stringBuilder.toString();
}
+ private static String extractString(Reader characterStream, long start, int length) {
+ StringBuilder stringBuilder = new StringBuilder( length );
+ try {
+ long skipped = characterStream.skip( start - 1 );
+ if ( skipped != start - 1 ) {
+ throw new HibernateException( "Unable to skip needed bytes" );
+ }
+ char[] buffer = new char[2048];
+ int charsRead = 0;
+ while ( true ) {
+ int amountRead = characterStream.read( buffer, 0, buffer.length );
+ if ( amountRead == -1 ) {
+ break;
+ }
+ stringBuilder.append( buffer, 0, amountRead );
+ if ( amountRead < buffer.length ) {
+ // we have read up to the end of stream
+ break;
+ }
+ charsRead += amountRead;
+ if ( charsRead >= length ) {
+ break;
+ }
+ }
+ }
+ catch ( IOException ioe ) {
+ throw new HibernateException( "IOException occurred reading a binary value", ioe );
+ }
+ return stringBuilder.toString();
+ }
+
+ public static Object subStream(Reader characterStream, long start, int length) {
+ return new StringReader( extractString( characterStream, start, length ) );
+ }
+
public static byte[] extractBytes(InputStream inputStream) {
+ if ( BinaryStream.class.isInstance( inputStream ) ) {
+ return ( (BinaryStream ) inputStream ).getBytes();
+ }
+
// read the stream contents into a buffer and return the complete byte[]
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
try {
@@ -116,4 +157,47 @@
}
return outputStream.toByteArray();
}
+
+ public static byte[] extractBytes(InputStream inputStream, long position, int length) {
+ if ( BinaryStream.class.isInstance( inputStream ) && Integer.MAX_VALUE > position ) {
+ byte[] data = ( (BinaryStream ) inputStream ).getBytes();
+ int size = Math.min( length, data.length );
+ byte[] result = new byte[size];
+ System.arraycopy( data, (int) position, result, 0, size );
+ return result;
+ }
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream( length );
+ try {
+ long skipped = inputStream.skip( position - 1 );
+ if ( skipped != position - 1 ) {
+ throw new HibernateException( "Unable to skip needed bytes" );
+ }
+ byte[] buffer = new byte[2048];
+ int bytesRead = 0;
+ while ( true ) {
+ int amountRead = inputStream.read( buffer );
+ if ( amountRead == -1 ) {
+ break;
+ }
+ outputStream.write( buffer, 0, amountRead );
+ if ( amountRead < buffer.length ) {
+ // we have read up to the end of stream
+ break;
+ }
+ bytesRead += amountRead;
+ if ( bytesRead >= length ) {
+ break;
+ }
+ }
+ }
+ catch ( IOException ioe ) {
+ throw new HibernateException( "IOException occurred reading a binary value", ioe );
+ }
+ return outputStream.toByteArray();
+ }
+
+ public static InputStream subStream(InputStream inputStream, long start, int length) {
+ return new BinaryStreamImpl( extractBytes( inputStream, start, length ) );
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -56,6 +56,11 @@
final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
}
+ else if ( byte[].class.isInstance( value ) ) {
+ // performance shortcut for binding BLOB data in byte[] format
+ final byte[] bytes = (byte[]) value;
+ st.setBytes( index, bytes );
+ }
else {
st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) );
}
Modified: core/trunk/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java
===================================================================
--- core/trunk/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java 2010-07-26 17:25:47 UTC (rev 20069)
+++ core/trunk/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java 2010-07-26 20:03:49 UTC (rev 20070)
@@ -45,14 +45,16 @@
* @author Steve Ebersole
*/
public class JdbcSupportTest extends TestCase {
+ private static class LobCreationContextImpl implements LobCreationContext {
+ public Object execute(Callback callback) {
+ fail( "Unexpected call to getConnection" );
+ return null;
+ }
+ }
+
+ private LobCreationContextImpl lobCreationContext = new LobCreationContextImpl();
+
public void testLobCreator() throws ClassNotFoundException, SQLException {
- final LobCreationContext lobCreationContext = new LobCreationContext() {
- public Object execute(Callback callback) {
- fail( "Unexpeted call to getConnection" );
- return null;
- }
- };
-
LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator( lobCreationContext );
Blob blob = lobCreator.createBlob( new byte[] {} );
@@ -69,6 +71,20 @@
assertTrue( nclob instanceof NClobImplementer );
nclob = lobCreator.wrap( nclob );
assertTrue( nclob instanceof WrappedClob );
+ }
+ public void testLobAccess() throws SQLException {
+ LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator( lobCreationContext );
+
+ Blob blob = lobCreator.createBlob( "Hi".getBytes() );
+ assertEquals( 2, blob.length() );
+ assertEquals( 2, blob.getBytes( 1, 5 ).length );
+ blob.getBinaryStream();
+
+ Clob clob = lobCreator.createClob( "Hi" );
+ assertEquals( 2, clob.length() );
+ assertEquals( 2, clob.getSubString( 1, 5 ).length() );
+ clob.getCharacterStream();
+ clob.getAsciiStream();
}
}
14 years, 5 months
Hibernate SVN: r20069 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-26 13:25:47 -0400 (Mon, 26 Jul 2010)
New Revision: 20069
Modified:
core/trunk/parent/pom.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
Log:
HHH-5416 - upgrade to h2 1.2.140
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2010-07-26 16:53:33 UTC (rev 20068)
+++ core/trunk/parent/pom.xml 2010-07-26 17:25:47 UTC (rev 20069)
@@ -542,7 +542,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.2.139</version>
+ <version>1.2.140</version>
</dependency>
</dependencies>
</dependencyManagement>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java 2010-07-26 16:53:33 UTC (rev 20068)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java 2010-07-26 17:25:47 UTC (rev 20069)
@@ -833,6 +833,7 @@
catch ( AssertionFailedError afe ) {
if ( H2Dialect.class.isInstance( getDialect() ) ) {
// http://groups.google.com/group/h2-database/t/5548ff9fd3abdb7
+ // this is fixed in H2 1.2.140
count = s.createQuery( "delete Vehicle" ).executeUpdate();
assertEquals( "incorrect count", 4, count );
}
14 years, 5 months
Hibernate SVN: r20068 - core/trunk/core/src/main/java/org/hibernate/type/descriptor/java.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-26 12:53:33 -0400 (Mon, 26 Jul 2010)
New Revision: 20068
Modified:
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
Log:
HHH-5415 - org.hibernate.type.descriptor.java.DataHelper dumping "NClob not found" exception to stderr
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java 2010-07-26 16:47:20 UTC (rev 20067)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java 2010-07-26 16:53:33 UTC (rev 20068)
@@ -35,7 +35,7 @@
import org.hibernate.util.ReflectHelper;
/**
- * TODO : javadoc
+ * A help for dealing with BLOB and CLOB data
*
* @author Steve Ebersole
*/
@@ -49,7 +49,7 @@
nClobClass = ReflectHelper.classForName( "java.sql.NClob", DataHelper.class );
}
catch ( ClassNotFoundException e ) {
- e.printStackTrace();
+ log.info( "Could not locate 'java.sql.NClob' class; assuming JDBC 3" );
}
}
14 years, 5 months
Hibernate SVN: r20067 - in core/trunk/testsuite/src/test/java/org/hibernate/test: lob and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-07-26 12:47:20 -0400 (Mon, 26 Jul 2010)
New Revision: 20067
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java
Log:
HHH-5400 - Blob persistence fails with Hibernate 3.6.0-SNAPSHOT, works with 3.5.3-Final
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobEntity.java 2010-07-26 16:47:20 UTC (rev 20067)
@@ -0,0 +1,79 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.annotations.lob;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class MaterializedBlobEntity {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.SEQUENCE)
+ private Long id;
+
+ private String name;
+
+ @Lob
+ private byte[] theBytes;
+
+ public MaterializedBlobEntity() {
+ }
+
+ public MaterializedBlobEntity(String name, byte[] theBytes) {
+ this.name = name;
+ this.theBytes = theBytes;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public byte[] getTheBytes() {
+ return theBytes;
+ }
+
+ public void setTheBytes(byte[] theBytes) {
+ this.theBytes = theBytes;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/lob/MaterializedBlobTest.java 2010-07-26 16:47:20 UTC (rev 20067)
@@ -0,0 +1,80 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.annotations.lob;
+
+import java.util.Arrays;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.testing.junit.DialectChecks;
+import org.hibernate.testing.junit.RequiresDialectFeature;
+import org.hibernate.type.MaterializedBlobType;
+import org.hibernate.type.Type;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+(a)RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
+public class MaterializedBlobTest extends TestCase {
+ @Override
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
+ }
+
+ @Override
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class<?>[] { MaterializedBlobEntity.class };
+ }
+
+ public void testTypeSelection() {
+ int index = sfi().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getPropertyIndex( "theBytes" );
+ Type type = sfi().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getProperties()[index].getType();
+ assertEquals( MaterializedBlobType.INSTANCE, type );
+ }
+
+ public void testSaving() {
+ byte[] testData = "test data".getBytes();
+
+ Session session = openSession();
+ session.beginTransaction();
+ MaterializedBlobEntity entity = new MaterializedBlobEntity( "test", testData );
+ session.save( entity );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ entity = ( MaterializedBlobEntity ) session.get( MaterializedBlobEntity.class, entity.getId() );
+ assertTrue( Arrays.equals( testData, entity.getTheBytes() ) );
+ session.delete( entity );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java 2010-07-26 14:05:03 UTC (rev 20066)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/LongByteArrayTest.java 2010-07-26 16:47:20 UTC (rev 20067)
@@ -88,6 +88,27 @@
s.close();
}
+ public void testSaving() {
+ byte[] value = buildRecursively( ARRAY_SIZE, true );
+
+ Session s = openSession();
+ s.beginTransaction();
+ LongByteArrayHolder entity = new LongByteArrayHolder();
+ entity.setLongByteArray( value );
+ s.persist( entity );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ entity = ( LongByteArrayHolder ) s.get( LongByteArrayHolder.class, entity.getId() );
+ assertEquals( ARRAY_SIZE, entity.getLongByteArray().length );
+ assertEquals( value, entity.getLongByteArray() );
+ s.delete( entity );
+ s.getTransaction().commit();
+ s.close();
+ }
+
private byte[] buildRecursively(int size, boolean on) {
byte[] data = new byte[size];
data[0] = mask( on );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java 2010-07-26 14:05:03 UTC (rev 20066)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/lob/MaterializedBlobTest.java 2010-07-26 16:47:20 UTC (rev 20067)
@@ -50,6 +50,16 @@
return new FunctionalTestClassTestSuite( MaterializedBlobTest.class );
}
+ @Override
+ public void testBoundedLongByteArrayAccess() {
+ super.testBoundedLongByteArrayAccess();
+ }
+
+ @Override
+ public void testSaving() {
+ super.testSaving();
+ }
+
public boolean appliesTo(Dialect dialect) {
if ( ! dialect.supportsExpectedLobUsagePattern() ) {
reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
14 years, 5 months
Hibernate SVN: r20066 - in core/branches/Branch_3_2_4_SP1_CP: test/org/hibernate/test/idgen/enhanced/table and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-26 10:05:03 -0400 (Mon, 26 Jul 2010)
New Revision: 20066
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.hbm.xml
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.java
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java
Log:
JBPAPP-4599 HHH-3231 org.hibernate.id.enhanced.TableGenerator throws IllegalArgumentException: alias not found: tbl under Oracle
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java 2010-07-26 11:23:01 UTC (rev 20065)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/id/enhanced/TableGenerator.java 2010-07-26 14:05:03 UTC (rev 20066)
@@ -5,6 +5,8 @@
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.Map;
import java.util.Properties;
import java.util.HashMap;
import java.io.Serializable;
@@ -27,10 +29,27 @@
import org.hibernate.util.CollectionHelper;
/**
- * A "segmented" version of the enhanced table generator. The term "segmented"
- * refers to the fact that this table can hold multiple value generators,
- * segmented by a key.
+ * An enhanced version of table-based id generation.
* <p/>
+ * Unlike the simplistic legacy one (which, btw, was only ever intended for subclassing
+ * support) we "segment" the table into multiple values. Thus a single table can
+ * actually serve as the persistent storage for multiple independent generators. One
+ * approach would be to segment the values by the name of the entity for which we are
+ * performing generation, which would mean that we would have a row in the generator
+ * table for each entity name. Or any configuration really; the setup is very flexible.
+ * <p/>
+ * In this respect it is very simliar to the legacy
+ * {@link org.hibernate.id.MultipleHiLoPerTableGenerator} in terms of the
+ * underlying storage structure (namely a single table capable of holding
+ * multiple generator values). The differentiator is, as with
+ * {@link SequenceStyleGenerator} as well, the externalized notion
+ * of an optimizer.
+ * <p/>
+ * <b>NOTE</b> that by default we use a single row for all genertators (based
+ * on {@link #DEF_SEGMENT_VALUE}). The configuration parameter
+ * {@link #CONFIG_PREFER_SEGMENT_PER_ENTITY} can be used to change that to
+ * instead default to using a row for each entity name.
+ * <p/>
* Configuration parameters:
* <table>
* <tr>
@@ -84,7 +103,7 @@
*/
public class TableGenerator extends TransactionHelper implements PersistentIdentifierGenerator, Configurable {
private static final Log log = LogFactory.getLog( TableGenerator.class );
-
+ public static final String CONFIG_PREFER_SEGMENT_PER_ENTITY = "hibernate.id.enhanced.table.prefer_segment_per_entity";
public static final String TABLE_PARAM = "table_name";
public static final String DEF_TABLE = "hibernate_sequences";
@@ -119,91 +138,260 @@
private Type identifierType;
- private String query;
- private String insert;
- private String update;
+ private String selectQuery;
+ private String insertQuery;
+ private String updateQuery;
private Optimizer optimizer;
private long accessCount = 0;
- public String getTableName() {
+ /**
+ * {@inheritDoc}
+ */
+ public Object generatorKey() {
return tableName;
}
- public String getSegmentColumnName() {
+ /**
+ * Type mapping for the identifier.
+ *
+ * @return The identifier type mapping.
+ */
+ public final Type getIdentifierType() {
+ return identifierType;
+ }
+
+ /**
+ * The name of the table in which we store this generator's persistent state.
+ *
+ * @return The table name.
+ */
+ public final String getTableName() {
+ return tableName;
+ }
+
+ /**
+ * The name of the column in which we store the segment to which each row
+ * belongs. The value here acts as PK.
+ *
+ * @return The segment column name
+ */
+ public final String getSegmentColumnName() {
return segmentColumnName;
}
- public String getSegmentValue() {
+ /**
+ * The value in {@link #getSegmentColumnName segment column} which
+ * corresponding to this generator instance. In other words this value
+ * indicates the row in which this generator instance will store values.
+ *
+ * @return The segment value for this generator instance.
+ */
+ public final String getSegmentValue() {
return segmentValue;
}
-
- public int getSegmentValueLength() {
+ /**
+ * The size of the {@link #getSegmentColumnName segment column} in the
+ * underlying table.
+ * <p/>
+ * <b>NOTE</b> : should really have been called 'segmentColumnLength' or
+ * even better 'segmentColumnSize'
+ *
+ * @return the column size.
+ */
+ public final int getSegmentValueLength() {
return segmentValueLength;
}
- public String getValueColumnName() {
+ /**
+ * The name of the column in which we store our persistent generator value.
+ *
+ * @return The name of the value column.
+ */
+ public final String getValueColumnName() {
return valueColumnName;
}
- public Type getIdentifierType() {
- return identifierType;
- }
-
- public int getInitialValue() {
+ /**
+ * The initial value to use when we find no previous state in the
+ * generator table corresponding to our sequence.
+ *
+ * @return The initial value to use.
+ */
+ public final int getInitialValue() {
return initialValue;
}
- public int getIncrementSize() {
+ /**
+ * The amount of increment to use. The exact implications of this
+ * depends on the {@link #getOptimizer() optimizer} being used.
+ *
+ * @return The increment amount.
+ */
+ public final int getIncrementSize() {
return incrementSize;
}
- public Optimizer getOptimizer() {
+ /**
+ * The optimizer being used by this generator.
+ *
+ * @return Out optimizer.
+ */
+ public final Optimizer getOptimizer() {
return optimizer;
}
- public long getTableAccessCount() {
+ /**
+ * Getter for property 'tableAccessCount'. Only really useful for unit test
+ * assertions.
+ *
+ * @return Value for property 'tableAccessCount'.
+ */
+ public final long getTableAccessCount() {
return accessCount;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
+ identifierType = type;
- public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
- tableName = PropertiesHelper.getString( TABLE_PARAM, params, DEF_TABLE );
- if ( tableName.indexOf( '.' ) < 0 ) {
+ tableName = determneGeneratorTableName( params );
+ segmentColumnName = determineSegmentColumnName( params );
+ valueColumnName = determineValueColumnName( params );
+
+ segmentValue = determineSegmentValue( params );
+
+ segmentValueLength = determineSegmentColumnSize( params );
+ initialValue = determineInitialValue( params );
+ incrementSize = determineIncrementSize( params );
+
+ this.selectQuery = buildSelectQuery( dialect );
+ this.updateQuery = buildUpdateQuery();
+ this.insertQuery = buildInsertQuery();
+
+ String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
+ String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
+ optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
+ }
+
+ /**
+ * Determine the table name to use for the generator values.
+ * <p/>
+ * Called during {@link #configure configuration}.
+ *
+ * @see #getTableName()
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The table name to use.
+ */
+ protected String determneGeneratorTableName(Properties params) {
+ String name = PropertiesHelper.getString( TABLE_PARAM, params, DEF_TABLE );
+ boolean isGivenNameUnqualified = name.indexOf( '.' ) < 0;
+ if ( isGivenNameUnqualified ) {
+ // if the given name is un-qualified we may neen to qualify it
String schemaName = params.getProperty( SCHEMA );
String catalogName = params.getProperty( CATALOG );
- tableName = Table.qualify( catalogName, schemaName, tableName );
+ name = Table.qualify( catalogName, schemaName, name );
}
+ return name;
+ }
+ /**
+ * Determine the name of the column used to indicate the segment for each
+ * row. This column acts as the primary key.
+ * <p/>
+ * Called during {@link #configure configuration}.
+ *
+ * @see #getSegmentColumnName()
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The name of the segment column
+ */
+ protected String determineSegmentColumnName(Properties params) {
+ return PropertiesHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
+ }
- segmentColumnName = PropertiesHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
- segmentValue = params.getProperty( SEGMENT_VALUE_PARAM );
+ /**
+ * Determine the name of the column in which we will store the generator persistent value.
+ * <p/>
+ * Called during {@link #configure configuration}.
+ *
+ * @see #getValueColumnName()
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The name of the value column
+ */
+ protected String determineValueColumnName(Properties params) {
+ return PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
+ }
+
+ /**
+ * Determine the segment value corresponding to this generator instance.
+ * <p/>
+ * Called during {@link #configure configuration}.
+ *
+ * @see #getSegmentValue()
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The name of the value column
+ */
+ protected String determineSegmentValue(Properties params) {
+ String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM );
if ( StringHelper.isEmpty( segmentValue ) ) {
- log.debug( "explicit segment value for id generator [" + tableName + '.' + segmentColumnName + "] suggested; using default [" + DEF_SEGMENT_VALUE + "]" );
- segmentValue = DEF_SEGMENT_VALUE;
+ segmentValue = determineDefaultSegmentValue( params );
}
- segmentValueLength = PropertiesHelper.getInt( SEGMENT_LENGTH_PARAM, params, DEF_SEGMENT_LENGTH );
- valueColumnName = PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
- initialValue = PropertiesHelper.getInt( INITIAL_PARAM, params, DEFAULT_INITIAL_VALUE );
- incrementSize = PropertiesHelper.getInt( INCREMENT_PARAM, params, DEFAULT_INCREMENT_SIZE );
- identifierType = type;
+ return segmentValue;
+ }
- String query = "select " + valueColumnName +
- " from " + tableName + " tbl" +
- " where tbl." + segmentColumnName + "=?";
+ /**
+ * Used in the cases where {@link #determineSegmentValue} is unable to
+ * determine the value to use.
+ *
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The default segment value to use.
+ */
+ protected String determineDefaultSegmentValue(Properties params) {
+ boolean preferSegmentPerEntity = PropertiesHelper.getBoolean( CONFIG_PREFER_SEGMENT_PER_ENTITY, params, false );
+ String defaultToUse = preferSegmentPerEntity ? params.getProperty( TABLE ) : DEF_SEGMENT_VALUE;
+ log.info( "explicit segment value for id generator [" + tableName + '.' + segmentColumnName + "] suggested; using default [" + defaultToUse + "]" );
+ return defaultToUse;
+ }
+
+ /**
+ * Determine the size of the {@link #getSegmentColumnName segment column}
+ * <p/>
+ * Called during {@link #configure configuration}.
+ *
+ * @see #getSegmentValueLength()
+ * @param params The params supplied in the generator config (plus some standard useful extras).
+ * @return The size of the segment column
+ */
+ protected int determineSegmentColumnSize(Properties params) {
+ return PropertiesHelper.getInt( SEGMENT_LENGTH_PARAM, params, DEF_SEGMENT_LENGTH );
+ }
+
+ protected int determineInitialValue(Properties params) {
+ return PropertiesHelper.getInt( INITIAL_PARAM, params, DEFAULT_INITIAL_VALUE );
+ }
+
+ protected int determineIncrementSize(Properties params) {
+ return PropertiesHelper.getInt( INCREMENT_PARAM, params, DEFAULT_INCREMENT_SIZE );
+ }
+ protected String buildSelectQuery(Dialect dialect) {
+ final String alias = "tbl";
+ String query = "select " + StringHelper.qualify( alias, valueColumnName ) +
+ " from " + tableName + ' ' + alias +
+ " where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
HashMap lockMap = new HashMap();
- lockMap.put( "tbl", LockMode.UPGRADE );
- this.query = dialect.applyLocksToSql( query, lockMap, CollectionHelper.EMPTY_MAP );
+ lockMap.put( alias, LockMode.UPGRADE );
+ Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
+ return dialect.applyLocksToSql( query, lockMap, updateTargetColumnsMap );
+ }
- update = "update " + tableName +
+ protected String buildUpdateQuery() {
+ return "update " + tableName +
" set " + valueColumnName + "=? " +
" where " + valueColumnName + "=? and " + segmentColumnName + "=?";
-
- insert = "insert into " + tableName + " (" + segmentColumnName + ", " + valueColumnName + ") " + " values (?,?)";
-
- String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
- String optimizationStrategy = PropertiesHelper.getString( OPT_PARAM, params, defOptStrategy );
- optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize );
}
-
+ protected String buildInsertQuery() {
+ return "insert into " + tableName + " (" + segmentColumnName + ", " + valueColumnName + ") " + " values (?,?)";
+ }
public synchronized Serializable generate(final SessionImplementor session, Object obj) {
return optimizer.generate(
new AccessCallback() {
@@ -214,23 +402,24 @@
);
}
+ /**
+ * {@inheritDoc}
+ */
public Serializable doWorkInCurrentTransaction(Connection conn, String sql) throws SQLException {
int result;
int rows;
do {
- sql = query;
- SQL.debug( sql );
- PreparedStatement queryPS = conn.prepareStatement( query );
+ SQL.debug( selectQuery );
+ PreparedStatement selectPS = conn.prepareStatement( selectQuery );
try {
- queryPS.setString( 1, segmentValue );
- ResultSet queryRS = queryPS.executeQuery();
- if ( !queryRS.next() ) {
+ selectPS.setString( 1, segmentValue );
+ ResultSet selectRS = selectPS.executeQuery();
+ if ( !selectRS.next() ) {
PreparedStatement insertPS = null;
try {
result = initialValue;
- sql = insert;
- SQL.debug( sql );
- insertPS = conn.prepareStatement( insert );
+ SQL.debug( insertQuery );
+ insertPS = conn.prepareStatement( insertQuery );
insertPS.setString( 1, segmentValue );
insertPS.setLong( 2, result );
insertPS.execute();
@@ -242,21 +431,20 @@
}
}
else {
- result = queryRS.getInt( 1 );
+ result = selectRS.getInt( 1 );
}
- queryRS.close();
+ selectRS.close();
}
catch ( SQLException sqle ) {
log.error( "could not read or init a hi value", sqle );
throw sqle;
}
finally {
- queryPS.close();
+ selectPS.close();
}
- sql = update;
- SQL.debug( sql );
- PreparedStatement updatePS = conn.prepareStatement( update );
+ SQL.debug( updateQuery );
+ PreparedStatement updatePS = conn.prepareStatement( updateQuery );
try {
long newValue = optimizer.applyIncrementSizeToSourceValues()
? result + incrementSize : result + 1;
@@ -266,7 +454,7 @@
rows = updatePS.executeUpdate();
}
catch ( SQLException sqle ) {
- log.error( "could not update hi value in: " + tableName, sqle );
+ log.error( "could not updateQuery hi value in: " + tableName, sqle );
throw sqle;
}
finally {
@@ -294,7 +482,9 @@
.append( valueColumnName )
.append( ' ' )
.append( dialect.getTypeName( Types.BIGINT ) )
- .append( " ) " )
+ .append( ", primary key ( " )
+ .append( segmentColumnName )
+ .append( " ) ) " )
.toString()
};
}
@@ -311,7 +501,4 @@
return new String[] { sqlDropString.toString() };
}
- public Object generatorKey() {
- return tableName;
- }
}
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java 2010-07-26 11:23:01 UTC (rev 20065)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/BasicTableTest.java 2010-07-26 14:05:03 UTC (rev 20066)
@@ -19,13 +19,22 @@
}
public String[] getMappings() {
- return new String[] { "idgen/enhanced/table/Basic.hbm.xml" };
+ return new String[] { "idgen/enhanced/table/Basic.hbm.xml","idgen/enhanced/table/Person.hbm.xml" };
}
public static Test suite() {
return new FunctionalTestClassTestSuite( BasicTableTest.class );
}
-
+ public void testHHH3231(){
+ Session s = openSession();
+ s.beginTransaction();
+ Person p = new Person();
+ p.setName( "stliu" );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ }
public void testNormalBoundary() {
EntityPersister persister = sfi().getEntityPersister( Entity.class.getName() );
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.hbm.xml 2010-07-26 14:05:03 UTC (rev 20066)
@@ -0,0 +1,19 @@
+<?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.idgen.enhanced.table">
+ <class name="Person" table="PERSON">
+ <id name="id" type="long" column="PID">
+
+ <generator
+ class="org.hibernate.id.enhanced.TableGenerator" >
+<!--
+ <generator
+ class="org.hibernate.id.enhanced.TableGeneratorModified" >
+-->
+ <param name="segment_value">sq_person_pid</param>
+ </generator>
+ </id>
+ <property name="name" type="string" length="50" column="NAME" />
+ </class>
+</hibernate-mapping>
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/idgen/enhanced/table/Person.java 2010-07-26 14:05:03 UTC (rev 20066)
@@ -0,0 +1,51 @@
+package org.hibernate.test.idgen.enhanced.table;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+public class Person {
+
+ private Long id;
+ private String name;
+
+ public Person() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public static void main(String[] args) {
+
+ SessionFactory sessionFactory = new Configuration().configure()
+ .buildSessionFactory();
+
+ Session session = sessionFactory.getCurrentSession();
+ session.beginTransaction();
+
+ Person thePerson = new Person();
+ thePerson.setName("Foo Bar");
+
+ session.save(thePerson);
+
+ session.getTransaction().commit();
+
+ Long personId = thePerson.getId();
+ System.out.println("Added person " + personId);
+
+ sessionFactory.close();
+ }
+}
\ No newline at end of file
14 years, 5 months
Hibernate SVN: r20065 - in search/trunk: hibernate-search and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-07-26 07:23:01 -0400 (Mon, 26 Jul 2010)
New Revision: 20065
Modified:
search/trunk/hibernate-search-archetype/pom.xml
search/trunk/hibernate-search-integrationtest/pom.xml
search/trunk/hibernate-search-testing/pom.xml
search/trunk/hibernate-search/pom.xml
search/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: search/trunk/hibernate-search/pom.xml
===================================================================
--- search/trunk/hibernate-search/pom.xml 2010-07-26 11:22:48 UTC (rev 20064)
+++ search/trunk/hibernate-search/pom.xml 2010-07-26 11:23:01 UTC (rev 20065)
@@ -28,7 +28,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.3.0.Alpha1</version>
+ <version>3.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Modified: search/trunk/hibernate-search-archetype/pom.xml
===================================================================
--- search/trunk/hibernate-search-archetype/pom.xml 2010-07-26 11:22:48 UTC (rev 20064)
+++ search/trunk/hibernate-search-archetype/pom.xml 2010-07-26 11:23:01 UTC (rev 20065)
@@ -10,7 +10,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.3.0.Alpha1</version>
+ <version>3.3.0-SNAPSHOT</version>
</parent>
<groupId>com.example</groupId>
Modified: search/trunk/hibernate-search-integrationtest/pom.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/pom.xml 2010-07-26 11:22:48 UTC (rev 20064)
+++ search/trunk/hibernate-search-integrationtest/pom.xml 2010-07-26 11:23:01 UTC (rev 20065)
@@ -6,7 +6,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.3.0.Alpha1</version>
+ <version>3.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Modified: search/trunk/hibernate-search-testing/pom.xml
===================================================================
--- search/trunk/hibernate-search-testing/pom.xml 2010-07-26 11:22:48 UTC (rev 20064)
+++ search/trunk/hibernate-search-testing/pom.xml 2010-07-26 11:23:01 UTC (rev 20065)
@@ -28,7 +28,7 @@
<parent>
<artifactId>hibernate-search-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>3.3.0.Alpha1</version>
+ <version>3.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-07-26 11:22:48 UTC (rev 20064)
+++ search/trunk/pom.xml 2010-07-26 11:23:01 UTC (rev 20065)
@@ -27,7 +27,7 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-parent</artifactId>
- <version>3.3.0.Alpha1</version>
+ <version>3.3.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Hibernate Search Aggregator</name>
@@ -49,9 +49,9 @@
</issueManagement>
<scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/hibernate/search/tags/v3_3_0_Alpha1</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/hibernate/search/tags/v3_3_0_Alpha1</developerConnection>
- <url>http://fisheye.jboss.com/browse/Hibernate/search/tags/v3_3_0_Alpha1</url>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/hibernate/search/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/hibernate/search/trunk</developerConnection>
+ <url>http://fisheye.jboss.com/browse/Hibernate/search/trunk</url>
</scm>
<organization>
14 years, 5 months