From 7d2867bf5380909167aeb8ab70ce0ade0da0a602 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Fri, 16 Aug 2013 19:12:18 +0800 Subject: [PATCH] HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC) --- .../AbstractLoadPlanBasedEntityLoader.java | 11 ++++++++-- .../org/hibernate/test/legacy/FooBarTest.java | 20 +++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/AbstractLoadPlanBasedEntityLoader.java b/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/AbstractLoadPlanBasedEntityLoader.java index 27cc1b5798..5ac8cddb2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/AbstractLoadPlanBasedEntityLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/entity/plan/AbstractLoadPlanBasedEntityLoader.java @@ -231,10 +231,11 @@ public abstract class AbstractLoadPlanBasedEntityLoader implements UniqueEntityL } persistenceContext.beforeLoad(); try { - List results; + List results = null; final String sql = loadQueryDetails.getSqlStatement(); + SqlStatementWrapper wrapper = null; try { - final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); + wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); results = loadQueryDetails.getResultSetProcessor().extractResults( wrapper.getResultSet(), session, @@ -252,6 +253,12 @@ public abstract class AbstractLoadPlanBasedEntityLoader implements UniqueEntityL ); } finally { + if ( wrapper != null ) { + session.getTransactionCoordinator().getJdbcCoordinator().release( + wrapper.getResultSet(), + wrapper.getStatement() + ); + } persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java index 35da814ffa..e4f95498bc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java @@ -2479,8 +2479,8 @@ public class FooBarTest extends LegacyTestCase { public void testPersistCollections() throws Exception { Session s = openSession(); Transaction txn = s.beginTransaction(); - assertEquals( 0, ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue() ); - assertTrue( s.createQuery( "select count(*) from Bar b" ).iterate().next().equals( new Long(0) ) ); + assertEquals( 0l, s.createQuery( "select count(*) from Bar" ).iterate().next() ); + assertEquals( 0l, s.createQuery( "select count(*) from Bar b" ).iterate().next() ); assertFalse( s.createQuery( "from Glarch g" ).iterate().hasNext() ); Baz baz = new Baz(); @@ -2583,7 +2583,7 @@ public class FooBarTest extends LegacyTestCase { baz.setTopGlarchez( new TreeMap() ); GlarchProxy g = new Glarch(); s.save(g); - baz.getTopGlarchez().put( new Character('G'), g ); + baz.getTopGlarchez().put( 'G', g ); HashMap map = new HashMap(); map.put(bar, g); map.put(bar2, g); @@ -2633,9 +2633,9 @@ public class FooBarTest extends LegacyTestCase { ); Glarch g2 = new Glarch(); s.save(g2); - g = (GlarchProxy) baz.getTopGlarchez().get( new Character('G') ); - baz.getTopGlarchez().put( new Character('H'), g ); - baz.getTopGlarchez().put( new Character('G'), g2 ); + g = (GlarchProxy) baz.getTopGlarchez().get( 'G' ); + baz.getTopGlarchez().put( 'H', g ); + baz.getTopGlarchez().put( 'G', g2 ); txn.commit(); s.close(); @@ -2662,8 +2662,8 @@ public class FooBarTest extends LegacyTestCase { baz = (Baz) s3.load(Baz.class, baz.getCode()); assertEquals( 3, ((Long) s3.createQuery( "select count(*) from Bar" ).iterate().next()).longValue() ); s3.delete(baz); - s3.delete( baz.getTopGlarchez().get( Character.valueOf('G') ) ); - s3.delete( baz.getTopGlarchez().get( Character.valueOf('H') ) ); + s3.delete( baz.getTopGlarchez().get( 'G' ) ); + s3.delete( baz.getTopGlarchez().get( 'H' ) ); int rows = s3.doReturningWork( new AbstractReturningWork() { @Override @@ -4312,10 +4312,10 @@ public class FooBarTest extends LegacyTestCase { ); s.refresh(foo); assertEquals( Long.valueOf( -3l ), foo.getLong() ); - assertEquals( LockMode.READ, s.getCurrentLockMode(foo) ); + assertEquals( LockMode.READ, s.getCurrentLockMode( foo ) ); s.refresh(foo, LockMode.UPGRADE); if ( getDialect().supportsOuterJoinForUpdate() ) { - assertEquals( LockMode.UPGRADE, s.getCurrentLockMode(foo) ); + assertEquals( LockMode.UPGRADE, s.getCurrentLockMode( foo ) ); } s.delete(foo); s.getTransaction().commit();