From: Paul H. <pha...@us...> - 2005-03-06 12:44:58
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21577/nhibernate/src/NHibernate/Loader Modified Files: AbstractEntityLoader.cs CollectionLoader.cs ICollectionInitializer.cs Loader.cs OneToManyLoader.cs OuterJoinLoader.cs Added Files: BatchingCollectionInitializer.cs Log Message: Refactored SessionImpl as per 2.1 for Save/Update Index: ICollectionInitializer.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/ICollectionInitializer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ICollectionInitializer.cs 31 Dec 2004 20:57:44 -0000 1.3 --- ICollectionInitializer.cs 6 Mar 2005 12:44:43 -0000 1.4 *************** *** 17,20 **** --- 17,27 ---- /// <param name="session"></param> void Initialize( object id, PersistentCollection collection, object owner, ISessionImplementor session ); + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="session"></param> + void Initialize( object id, ISessionImplementor session); } } \ No newline at end of file Index: CollectionLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/CollectionLoader.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CollectionLoader.cs 1 Mar 2005 16:24:48 -0000 1.13 --- CollectionLoader.cs 6 Mar 2005 12:44:43 -0000 1.14 *************** *** 15,20 **** public class CollectionLoader : OuterJoinLoader, ICollectionInitializer { ! private ICollectionPersister collectionPersister; ! private IType idType; /// <summary> --- 15,20 ---- public class CollectionLoader : OuterJoinLoader, ICollectionInitializer { ! private IQueryableCollection collectionPersister; ! private IType keyType; /// <summary> *************** *** 23,29 **** /// <param name="persister"></param> /// <param name="factory"></param> ! public CollectionLoader( IQueryableCollection persister, ISessionFactoryImplementor factory ) : base( factory.Dialect ) { ! idType = persister.KeyType; string alias = ToAlias( persister.TableName, 0 ); --- 23,39 ---- /// <param name="persister"></param> /// <param name="factory"></param> ! public CollectionLoader( IQueryableCollection persister, ISessionFactoryImplementor factory ) : this( persister, 1, factory ) { ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="persister"></param> ! /// <param name="batchSize"></param> ! /// <param name="factory"></param> ! public CollectionLoader( IQueryableCollection persister, int batchSize, ISessionFactoryImplementor factory ) : base( factory.Dialect ) ! { ! keyType = persister.KeyType; string alias = ToAlias( persister.TableName, 0 ); *************** *** 97,101 **** public void Initialize( object id, PersistentCollection collection, object owner, ISessionImplementor session ) { ! LoadCollection( session, id, idType, owner, collection ); } } --- 107,121 ---- public void Initialize( object id, PersistentCollection collection, object owner, ISessionImplementor session ) { ! LoadCollection( session, id, keyType, owner, collection ); ! } ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="id"></param> ! /// <param name="session"></param> ! public void Initialize( object id, ISessionImplementor session ) ! { ! LoadCollection( session, id, keyType ); } } Index: OneToManyLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/OneToManyLoader.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** OneToManyLoader.cs 1 Mar 2005 16:24:48 -0000 1.14 --- OneToManyLoader.cs 6 Mar 2005 12:44:43 -0000 1.15 *************** *** 142,145 **** --- 142,155 ---- LoadCollection( session, id, idType, owner, collection ); } + + /// <summary> + /// + /// </summary> + /// <param name="id"></param> + /// <param name="session"></param> + public void Initialize( object id, ISessionImplementor session ) + { + LoadCollection( session, id, idType ); + } } } \ No newline at end of file --- NEW FILE: BatchingCollectionInitializer.cs --- using NHibernate.Collection; using NHibernate.Engine; using log4net; namespace NHibernate.Loader { /// <summary> /// "Batch" loads collections, using multiple foreign key values in the SQL Where clause /// </summary> public class BatchingCollectionInitializer : ICollectionInitializer { private static readonly ILog log = LogManager.GetLogger( typeof( BatchingCollectionInitializer ) ); private readonly Loader nonBatchLoader; private readonly Loader batchLoader; private readonly Loader smallBatchLoader; private readonly int batchSize; private readonly int smallBatchSize; private readonly ICollectionPersister collectionPersister; /// <summary> /// /// </summary> /// <param name="collPersister"></param> /// <param name="batchSize"></param> /// <param name="batchLoader"></param> /// <param name="smallBatchSize"></param> /// <param name="smallBatchLoader"></param> /// <param name="nonBatchLoader"></param> public BatchingCollectionInitializer( ICollectionPersister collPersister, int batchSize, Loader batchLoader, int smallBatchSize, Loader smallBatchLoader, Loader nonBatchLoader) { this.batchLoader = batchLoader; this.nonBatchLoader = nonBatchLoader; this.batchSize = batchSize; this.collectionPersister = collPersister; this.smallBatchLoader = smallBatchLoader; this.smallBatchSize = smallBatchSize; } #region ICollectionInitializer Members /// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="collection"></param> /// <param name="owner"></param> /// <param name="session"></param> public void Initialize(object id, PersistentCollection collection, object owner, ISessionImplementor session) { // TODO: Add BatchingCollectionInitializer.Initialize implementation } /// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="session"></param> public void Initialize( object id, ISessionImplementor session ) { object[] batch = session.GetCollectionBatch( collectionPersister, id, batchSize ); if ( smallBatchSize == 1 || batch[ smallBatchSize - 1 ] == null ) { nonBatchLoader.LoadCollection( session, id, collectionPersister.KeyType ); } else if ( batch[ batchSize - 1 ] == null ) { if ( log.IsDebugEnabled ) { log.Debug( string.Format( "batch loading collection role (small batch): {0} ", collectionPersister.Role ) ); } // TODO: (2.1) BatchLoader - Copy the array from batch object[] smallBatch = new object[ smallBatchSize ]; smallBatchLoader.LoadCollectionBatch( session, smallBatch, collectionPersister.KeyType ); log.Debug( "done batch load"); } else { if ( log.IsDebugEnabled ) { log.Debug( string.Format( "batch loading collection role (small batch): {0} ", collectionPersister.Role ) ); } batchLoader.LoadCollectionBatch( session, batch, collectionPersister.KeyType ); log.Debug( "done batch load"); } } #endregion } } Index: OuterJoinLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** OuterJoinLoader.cs 1 Mar 2005 16:24:48 -0000 1.18 --- OuterJoinLoader.cs 6 Mar 2005 12:44:44 -0000 1.19 *************** *** 119,123 **** IList associations = new ArrayList(); ! if( session.EnableJoinedFetch ) { IType type = persister.ElementType; --- 119,123 ---- IList associations = new ArrayList(); ! if( session.IsOuterJoinedFetchEnabled ) { IType type = persister.ElementType; *************** *** 242,246 **** private void WalkClassTree( ILoadable persister, string alias, IList associations, IList classPersisters, string path, ISessionFactoryImplementor session ) { ! if( !session.EnableJoinedFetch ) { return; --- 242,246 ---- private void WalkClassTree( ILoadable persister, string alias, IList associations, IList classPersisters, string path, ISessionFactoryImplementor session ) { ! if( !session.IsOuterJoinedFetchEnabled ) { return; *************** *** 312,316 **** ISessionFactoryImplementor session ) { ! if( !session.EnableJoinedFetch ) { return; --- 312,316 ---- ISessionFactoryImplementor session ) { ! if( !session.IsOuterJoinedFetchEnabled ) { return; *************** *** 379,383 **** ISessionFactoryImplementor session ) { ! if( !session.EnableJoinedFetch ) { return; --- 379,383 ---- ISessionFactoryImplementor session ) { ! if( !session.IsOuterJoinedFetchEnabled ) { return; Index: Loader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/Loader.cs,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** Loader.cs 1 Mar 2005 16:24:48 -0000 1.48 --- Loader.cs 6 Mar 2005 12:44:43 -0000 1.49 *************** *** 909,912 **** --- 909,913 ---- } + /// <summary> /// *************** *** 933,936 **** --- 934,979 ---- /// </summary> /// <param name="session"></param> + /// <param name="id"></param> + /// <param name="type"></param> + internal void LoadCollection( + ISessionImplementor session, + object id, + IType type ) + { + LoadCollection( session, new object[] { id }, new IType[] { type } ); + } + + /// <summary> + /// + /// </summary> + /// <param name="session"></param> + /// <param name="ids"></param> + /// <param name="type"></param> + internal void LoadCollectionBatch( + ISessionImplementor session, + object[] ids, + IType type ) + { + IType[] idTypes = new IType[ ids.Length ]; + for( int i = 0; i < idTypes.Length; i++ ) + { + idTypes[ i ] = type; + } + LoadCollection( session, ids, idTypes ); + } + + private void LoadCollection( + ISessionImplementor session, + object[] ids, + IType[] types ) + { + QueryParameters qp = new QueryParameters( types, ids ); + DoFindAndInitializeNonLazyCollections( session, qp, null, null, null, ids, true ); + } + + /// <summary> + /// + /// </summary> + /// <param name="session"></param> /// <param name="queryParameters"></param> /// <param name="querySpaces"></param> Index: AbstractEntityLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/AbstractEntityLoader.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** AbstractEntityLoader.cs 1 Mar 2005 16:24:47 -0000 1.14 --- AbstractEntityLoader.cs 6 Mar 2005 12:44:43 -0000 1.15 *************** *** 10,14 **** { /// <summary></summary> ! public class AbstractEntityLoader : OuterJoinLoader { private ILoadable persister; --- 10,14 ---- { /// <summary></summary> ! public abstract class AbstractEntityLoader : OuterJoinLoader { private ILoadable persister; |