HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)

This commit is contained in:
Strong Liu 2013-08-16 19:12:18 +08:00 committed by Steve Ebersole
parent 712fb95b8a
commit 7d2867bf53
2 changed files with 19 additions and 12 deletions

View File

@ -231,10 +231,11 @@ public abstract class AbstractLoadPlanBasedEntityLoader implements UniqueEntityL
} }
persistenceContext.beforeLoad(); persistenceContext.beforeLoad();
try { try {
List results; List results = null;
final String sql = loadQueryDetails.getSqlStatement(); final String sql = loadQueryDetails.getSqlStatement();
SqlStatementWrapper wrapper = null;
try { try {
final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session );
results = loadQueryDetails.getResultSetProcessor().extractResults( results = loadQueryDetails.getResultSetProcessor().extractResults(
wrapper.getResultSet(), wrapper.getResultSet(),
session, session,
@ -252,6 +253,12 @@ public abstract class AbstractLoadPlanBasedEntityLoader implements UniqueEntityL
); );
} }
finally { finally {
if ( wrapper != null ) {
session.getTransactionCoordinator().getJdbcCoordinator().release(
wrapper.getResultSet(),
wrapper.getStatement()
);
}
persistenceContext.afterLoad(); persistenceContext.afterLoad();
} }
persistenceContext.initializeNonLazyCollections(); persistenceContext.initializeNonLazyCollections();

View File

@ -2479,8 +2479,8 @@ public class FooBarTest extends LegacyTestCase {
public void testPersistCollections() throws Exception { public void testPersistCollections() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction txn = s.beginTransaction(); Transaction txn = s.beginTransaction();
assertEquals( 0, ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue() ); assertEquals( 0l, s.createQuery( "select count(*) from Bar" ).iterate().next() );
assertTrue( s.createQuery( "select count(*) from Bar b" ).iterate().next().equals( new Long(0) ) ); assertEquals( 0l, s.createQuery( "select count(*) from Bar b" ).iterate().next() );
assertFalse( s.createQuery( "from Glarch g" ).iterate().hasNext() ); assertFalse( s.createQuery( "from Glarch g" ).iterate().hasNext() );
Baz baz = new Baz(); Baz baz = new Baz();
@ -2583,7 +2583,7 @@ public class FooBarTest extends LegacyTestCase {
baz.setTopGlarchez( new TreeMap() ); baz.setTopGlarchez( new TreeMap() );
GlarchProxy g = new Glarch(); GlarchProxy g = new Glarch();
s.save(g); s.save(g);
baz.getTopGlarchez().put( new Character('G'), g ); baz.getTopGlarchez().put( 'G', g );
HashMap map = new HashMap(); HashMap map = new HashMap();
map.put(bar, g); map.put(bar, g);
map.put(bar2, g); map.put(bar2, g);
@ -2633,9 +2633,9 @@ public class FooBarTest extends LegacyTestCase {
); );
Glarch g2 = new Glarch(); Glarch g2 = new Glarch();
s.save(g2); s.save(g2);
g = (GlarchProxy) baz.getTopGlarchez().get( new Character('G') ); g = (GlarchProxy) baz.getTopGlarchez().get( 'G' );
baz.getTopGlarchez().put( new Character('H'), g ); baz.getTopGlarchez().put( 'H', g );
baz.getTopGlarchez().put( new Character('G'), g2 ); baz.getTopGlarchez().put( 'G', g2 );
txn.commit(); txn.commit();
s.close(); s.close();
@ -2662,8 +2662,8 @@ public class FooBarTest extends LegacyTestCase {
baz = (Baz) s3.load(Baz.class, baz.getCode()); baz = (Baz) s3.load(Baz.class, baz.getCode());
assertEquals( 3, ((Long) s3.createQuery( "select count(*) from Bar" ).iterate().next()).longValue() ); assertEquals( 3, ((Long) s3.createQuery( "select count(*) from Bar" ).iterate().next()).longValue() );
s3.delete(baz); s3.delete(baz);
s3.delete( baz.getTopGlarchez().get( Character.valueOf('G') ) ); s3.delete( baz.getTopGlarchez().get( 'G' ) );
s3.delete( baz.getTopGlarchez().get( Character.valueOf('H') ) ); s3.delete( baz.getTopGlarchez().get( 'H' ) );
int rows = s3.doReturningWork( int rows = s3.doReturningWork(
new AbstractReturningWork<Integer>() { new AbstractReturningWork<Integer>() {
@Override @Override
@ -4312,10 +4312,10 @@ public class FooBarTest extends LegacyTestCase {
); );
s.refresh(foo); s.refresh(foo);
assertEquals( Long.valueOf( -3l ), foo.getLong() ); assertEquals( Long.valueOf( -3l ), foo.getLong() );
assertEquals( LockMode.READ, s.getCurrentLockMode(foo) ); assertEquals( LockMode.READ, s.getCurrentLockMode( foo ) );
s.refresh(foo, LockMode.UPGRADE); s.refresh(foo, LockMode.UPGRADE);
if ( getDialect().supportsOuterJoinForUpdate() ) { if ( getDialect().supportsOuterJoinForUpdate() ) {
assertEquals( LockMode.UPGRADE, s.getCurrentLockMode(foo) ); assertEquals( LockMode.UPGRADE, s.getCurrentLockMode( foo ) );
} }
s.delete(foo); s.delete(foo);
s.getTransaction().commit(); s.getTransaction().commit();