From: Kevin W. <kev...@us...> - 2004-12-31 20:58:09
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26346 Modified Files: Loader.cs OneToManyLoader.cs OuterJoinLoader.cs SimpleEntityLoader.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: OuterJoinLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/OuterJoinLoader.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** OuterJoinLoader.cs 22 Nov 2004 03:53:07 -0000 1.16 --- OuterJoinLoader.cs 31 Dec 2004 20:57:56 -0000 1.17 *************** *** 1,9 **** using System; using System.Collections; - using System.Data; using System.Text; - using NHibernate.Collection; - using NHibernate.Dialect; using NHibernate.Engine; using NHibernate.Persister; --- 1,6 ---- *************** *** 12,41 **** using NHibernate.Util; ! namespace NHibernate.Loader { ! ! public enum OuterJoinLoaderType { ! Lazy = -1, Auto = 0, Eager = 1 } ! ! public class OuterJoinLoader : Loader { ! ! protected static readonly IType[] NoTypes = new IType[0]; ! protected static readonly string[][] NoStringArrays = new string[0][]; ! protected static readonly string[] NoStrings = new string[0]; ! protected static readonly ILoadable[] NoPersisters = new ILoadable[0]; ! ! private ILoadable[] classPersisters; ! private LockMode[] lockModeArray; ! private SqlString sqlString; ! private string[] suffixes; ! ! public OuterJoinLoader(Dialect.Dialect dialect) : base(dialect) { } --- 9,51 ---- using NHibernate.Util; ! namespace NHibernate.Loader { ! /// <summary></summary> ! public enum OuterJoinLoaderType { ! /// <summary></summary> ! Lazy = -1, ! /// <summary></summary> Auto = 0, + /// <summary></summary> Eager = 1 } ! ! /// <summary></summary> ! public class OuterJoinLoader : Loader { ! /// <summary></summary> ! protected static readonly IType[ ] NoTypes = new IType[0]; ! ! /// <summary></summary> ! protected static readonly string[ ][ ] NoStringArrays = new string[0][ ]; ! ! /// <summary></summary> ! protected static readonly string[ ] NoStrings = new string[0]; ! ! /// <summary></summary> ! protected static readonly ILoadable[ ] NoPersisters = new ILoadable[0]; ! ! private ILoadable[ ] classPersisters; ! private LockMode[ ] lockModeArray; ! private SqlString sqlString; ! private string[ ] suffixes; ! /// <summary> ! /// ! /// </summary> ! /// <param name="dialect"></param> ! public OuterJoinLoader( Dialect.Dialect dialect ) : base( dialect ) { } *************** *** 49,59 **** /// <param name="foreignKeyColumns"></param> /// <returns></returns> ! protected virtual bool EnableJoinedFetch(bool mappingDefault, string path, string table, string[] foreignKeyColumns) { return mappingDefault; } ! public sealed class OuterJoinableAssociation { public ILoadable Subpersister; ! public string[] ForeignKeyColumns; public string Subalias; } --- 59,75 ---- /// <param name="foreignKeyColumns"></param> /// <returns></returns> ! protected virtual bool EnableJoinedFetch( bool mappingDefault, string path, string table, string[ ] foreignKeyColumns ) ! { return mappingDefault; } ! /// <summary></summary> ! public sealed class OuterJoinableAssociation // struct? ! { ! /// <summary></summary> public ILoadable Subpersister; ! /// <summary></summary> ! public string[ ] ForeignKeyColumns; ! /// <summary></summary> public string Subalias; } *************** *** 66,73 **** /// <param name="session"></param> /// <returns></returns> ! public IList WalkTree(ILoadable persister, string alias, ISessionFactoryImplementor session) { IList associations = new ArrayList(); ! WalkClassTree(persister, alias, associations, new ArrayList(), String.Empty, session); return associations; } --- 82,89 ---- /// <param name="session"></param> /// <returns></returns> ! public IList WalkTree( ILoadable persister, string alias, ISessionFactoryImplementor session ) { IList associations = new ArrayList(); ! WalkClassTree( persister, alias, associations, new ArrayList(), String.Empty, session ); return associations; } *************** *** 80,103 **** /// <param name="session"></param> /// <returns></returns> ! protected IList WalkCollectionTree(CollectionPersister persister, string alias, ISessionFactoryImplementor session) { IList associations = new ArrayList(); ! if ( session.EnableJoinedFetch ) { IType type = persister.ElementType; ! if (type.IsEntityType) { ! EntityType etype = (EntityType) type; // we do NOT need to call this.EnableJoinedFetch() here ! if ( AutoEager( persister.EnableJoinFetch, etype, session) ) { ! string[] columns = StringHelper.Prefix( persister.ElementColumnNames, alias + StringHelper.Dot); ! WalkAssociationTree(etype, columns, persister, alias, associations, new ArrayList(), String.Empty, session); } ! } ! else if (type.IsComponentType) { ! WalkCompositeElementTree( (IAbstractComponentType) type, persister.ElementColumnNames, persister, alias, associations, new ArrayList(), String.Empty, session); } } --- 96,119 ---- /// <param name="session"></param> /// <returns></returns> ! protected IList WalkCollectionTree( CollectionPersister persister, string alias, ISessionFactoryImplementor session ) { IList associations = new ArrayList(); ! if( session.EnableJoinedFetch ) { IType type = persister.ElementType; ! if( type.IsEntityType ) { ! EntityType etype = ( EntityType ) type; // we do NOT need to call this.EnableJoinedFetch() here ! if( AutoEager( persister.EnableJoinFetch, etype, session ) ) { ! string[ ] columns = StringHelper.Prefix( persister.ElementColumnNames, alias + StringHelper.Dot ); ! WalkAssociationTree( etype, columns, persister, alias, associations, new ArrayList(), String.Empty, session ); } ! } ! else if( type.IsComponentType ) { ! WalkCompositeElementTree( ( IAbstractComponentType ) type, persister.ElementColumnNames, persister, alias, associations, new ArrayList(), String.Empty, session ); } } *************** *** 119,123 **** private void WalkAssociationTree( EntityType type, ! string[] columns, object persister, string alias, --- 135,139 ---- private void WalkAssociationTree( EntityType type, ! string[ ] columns, object persister, string alias, *************** *** 125,147 **** IList classPersisters, string path, ! ISessionFactoryImplementor session) { ! ! ILoadable subpersister = (ILoadable)session.GetPersister(type.PersistentClass); // to avoid navigating back up bidirectional associations (and circularities) ! if(!classPersisters.Contains(subpersister)) { OuterJoinableAssociation assoc = new OuterJoinableAssociation(); ! associations.Add(assoc); ! classPersisters.Add(persister); assoc.Subpersister = subpersister; assoc.ForeignKeyColumns = columns; ! string subalias = ToAlias(subpersister.ClassName, associations.Count); assoc.Subalias = subalias; ! WalkClassTree(subpersister, subalias, associations, classPersisters, path, session); ! } ! } --- 141,163 ---- IList classPersisters, string path, ! ISessionFactoryImplementor session ) { ! ILoadable subpersister = ( ILoadable ) session.GetPersister( type.PersistentClass ); // to avoid navigating back up bidirectional associations (and circularities) ! if( !classPersisters.Contains( subpersister ) ) ! { OuterJoinableAssociation assoc = new OuterJoinableAssociation(); ! associations.Add( assoc ); ! classPersisters.Add( persister ); assoc.Subpersister = subpersister; assoc.ForeignKeyColumns = columns; ! string subalias = ToAlias( subpersister.ClassName, associations.Count ); assoc.Subalias = subalias; ! WalkClassTree( subpersister, subalias, associations, classPersisters, path, session ); ! } ! } *************** *** 157,161 **** /// <param name="path"></param> /// <param name="session"></param> ! private void WalkAssociationTree ( EntityType etype, ILoadable persister, --- 173,177 ---- /// <param name="path"></param> /// <param name="session"></param> ! private void WalkAssociationTree( EntityType etype, ILoadable persister, *************** *** 165,188 **** IList classPersisters, string path, ! ISessionFactoryImplementor session) { ! ! bool autoEager = AutoEager(persister.EnableJoinedFetch(propertyNumber), etype, session); ! string[] columns; ! if(etype.IsOneToOne) { //TODO: NOTE: workaround for problem with 1-to-1 defined on a subclass "accidently" picking up an object ! if(persister.IsDefinedOnSubclass(propertyNumber)) return; columns = StringHelper.Prefix( persister.IdentifierColumnNames, //The cast is safe because collections can't contain a 1-to-1 ! alias + StringHelper.Dot); } ! else { ! columns = persister.ToColumns(alias, propertyNumber); } - - string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber)); - bool enable = EnableJoinedFetch(autoEager, subpath, persister.GetSubclassPropertyTableName(propertyNumber), persister.GetSubclassPropertyColumnNames(propertyNumber) ); - if (enable) WalkAssociationTree(etype, columns, persister, alias, associations, classPersisters, subpath, session); } --- 181,212 ---- IList classPersisters, string path, ! ISessionFactoryImplementor session ) ! { ! bool autoEager = AutoEager( persister.EnableJoinedFetch( propertyNumber ), etype, session ); ! string[ ] columns; ! if( etype.IsOneToOne ) ! { //TODO: NOTE: workaround for problem with 1-to-1 defined on a subclass "accidently" picking up an object ! if( persister.IsDefinedOnSubclass( propertyNumber ) ) ! { ! return; ! } columns = StringHelper.Prefix( persister.IdentifierColumnNames, //The cast is safe because collections can't contain a 1-to-1 ! alias + StringHelper.Dot ); } ! else ! { ! columns = persister.ToColumns( alias, propertyNumber ); ! } ! ! string subpath = SubPath( path, persister.GetSubclassPropertyName( propertyNumber ) ); ! bool enable = EnableJoinedFetch( autoEager, subpath, persister.GetSubclassPropertyTableName( propertyNumber ), persister.GetSubclassPropertyColumnNames( propertyNumber ) ); ! if( enable ) ! { ! WalkAssociationTree( etype, columns, persister, alias, associations, classPersisters, subpath, session ); } } *************** *** 197,211 **** /// <param name="path"></param> /// <param name="session"></param> ! private void WalkClassTree(ILoadable persister, string alias, IList associations, IList classPersisters, string path, ISessionFactoryImplementor session) { ! if ( !session.EnableJoinedFetch ) return; int n = persister.CountSubclassProperties(); ! for (int i=0; i<n; i++) { ! IType type = persister.GetSubclassPropertyType(i); ! if (type.IsEntityType) { ! WalkAssociationTree ( ! (EntityType)type, persister, i, --- 221,239 ---- /// <param name="path"></param> /// <param name="session"></param> ! private void WalkClassTree( ILoadable persister, string alias, IList associations, IList classPersisters, string path, ISessionFactoryImplementor session ) { ! if( !session.EnableJoinedFetch ) ! { ! return; ! } int n = persister.CountSubclassProperties(); ! for( int i = 0; i < n; i++ ) { ! IType type = persister.GetSubclassPropertyType( i ); ! if( type.IsEntityType ) ! { ! WalkAssociationTree( ! ( EntityType ) type, persister, i, *************** *** 215,239 **** path, session ! ); ! ! } ! else if ( type.IsComponentType ) { ! string subpath = SubPath(path, persister.GetSubclassPropertyName(i) ); ! string[] columns = persister.GetSubclassPropertyColumnNames(i); ! string[] aliasedColumns = persister.ToColumns(alias, i); ! WalkComponentTree( ! (IAbstractComponentType) type, ! i, ! columns, aliasedColumns, ! persister, ! alias, ! associations, ! classPersisters, ! subpath, session ! ); } } --- 243,267 ---- path, session ! ); ! ! } ! else if( type.IsComponentType ) { ! string subpath = SubPath( path, persister.GetSubclassPropertyName( i ) ); ! string[ ] columns = persister.GetSubclassPropertyColumnNames( i ); ! string[ ] aliasedColumns = persister.ToColumns( alias, i ); ! WalkComponentTree( ! ( IAbstractComponentType ) type, ! i, ! columns, aliasedColumns, ! persister, ! alias, ! associations, ! classPersisters, ! subpath, session ! ); } } *************** *** 247,301 **** /// <param name="persister"></param> /// <param name="alias"></param> ! /// <param name="assocaitions"></param> /// <param name="classPersisters"></param> /// <param name="session"></param> private void WalkComponentTree( ! IAbstractComponentType act, ! int propertyNumber, ! string[] cols, ! string[] aliasedCols, ! ILoadable persister, ! string alias, ! IList associations, ! IList classPersisters, string path, ! ISessionFactoryImplementor session) { ! if (!session.EnableJoinedFetch ) return; ! ! IType[] types = act.Subtypes; ! string[] propertyNames = act.PropertyNames; int begin = 0; ! for (int i=0; i<types.Length; i++) { ! int length = types[i].GetColumnSpan(session); ! string[] range = ArrayHelper.Slice(cols, begin, length); ! string[] aliasedRange = ArrayHelper.Slice(aliasedCols, begin, length); ! if ( types[i].IsEntityType ) { ! EntityType etype = (EntityType) types[i]; ! //TODO: workaround for problem with 1-to-1 defined on a subclass ! if (etype.IsOneToOne) continue; ! ! string subpath = SubPath(path, propertyNames[i]); ! bool autoEager = AutoEager(act.EnableJoinedFetch(i), etype, session); ! ! bool enable = EnableJoinedFetch(autoEager, subpath, persister.GetSubclassPropertyTableName(propertyNumber), range); ! ! if(enable) ! WalkAssociationTree(etype, aliasedRange, persister, alias, associations, classPersisters, subpath, session); ! } ! else if ( types[i].IsComponentType ) { ! string subpath = SubPath(path, propertyNames[i]); ! WalkComponentTree ( (IAbstractComponentType) types[i], propertyNumber, range, aliasedRange, persister, alias, associations, classPersisters, subpath, session); } ! begin+=length; } } --- 275,339 ---- /// <param name="persister"></param> /// <param name="alias"></param> ! /// <param name="associations"></param> /// <param name="classPersisters"></param> /// <param name="session"></param> + /// <param name="aliasedCols"></param> + /// <param name="path"></param> + /// <param name="propertyNumber"></param> private void WalkComponentTree( ! IAbstractComponentType act, ! int propertyNumber, ! string[ ] cols, ! string[ ] aliasedCols, ! ILoadable persister, ! string alias, ! IList associations, ! IList classPersisters, string path, ! ISessionFactoryImplementor session ) { + if( !session.EnableJoinedFetch ) + { + return; + } ! IType[ ] types = act.Subtypes; ! string[ ] propertyNames = act.PropertyNames; int begin = 0; ! for( int i = 0; i < types.Length; i++ ) { ! int length = types[ i ].GetColumnSpan( session ); ! string[ ] range = ArrayHelper.Slice( cols, begin, length ); ! string[ ] aliasedRange = ArrayHelper.Slice( aliasedCols, begin, length ); ! if( types[ i ].IsEntityType ) { ! EntityType etype = ( EntityType ) types[ i ]; ! //TODO: workaround for problem with 1-to-1 defined on a subclass ! if( etype.IsOneToOne ) ! { ! continue; ! } ! string subpath = SubPath( path, propertyNames[ i ] ); ! bool autoEager = AutoEager( act.EnableJoinedFetch( i ), etype, session ); ! ! bool enable = EnableJoinedFetch( autoEager, subpath, persister.GetSubclassPropertyTableName( propertyNumber ), range ); ! ! if( enable ) ! { ! WalkAssociationTree( etype, aliasedRange, persister, alias, associations, classPersisters, subpath, session ); ! } ! ! } ! else if( types[ i ].IsComponentType ) { ! string subpath = SubPath( path, propertyNames[ i ] ); ! WalkComponentTree( ( IAbstractComponentType ) types[ i ], propertyNumber, range, aliasedRange, persister, alias, associations, classPersisters, subpath, session ); } ! begin += length; } } *************** *** 312,318 **** /// <param name="path"></param> /// <param name="session"></param> ! private void WalkCompositeElementTree ( IAbstractComponentType act, ! string[] cols, CollectionPersister persister, string alias, --- 350,356 ---- /// <param name="path"></param> /// <param name="session"></param> ! private void WalkCompositeElementTree( IAbstractComponentType act, ! string[ ] cols, CollectionPersister persister, string alias, *************** *** 320,354 **** IList classPersisters, string path, ! ISessionFactoryImplementor session ) { ! if(!session.EnableJoinedFetch) return; ! IType[] types = act.Subtypes; ! string[] propertyNames = act.PropertyNames; int begin = 0; ! for(int i=0; i < types.Length; i++) { ! int length = types[i].GetColumnSpan(session); ! string[] range = ArrayHelper.Slice(cols, begin, length); ! ! if(types[i].IsEntityType) { ! EntityType etype = (EntityType) types[i]; ! string subpath = SubPath(path, propertyNames[i]); ! bool autoEager = AutoEager(act.EnableJoinedFetch(i), etype, session ); ! bool enable = EnableJoinedFetch(autoEager, subpath, persister.QualifiedTableName, range); ! if(enable) { ! string[] columns = StringHelper.Prefix(range, alias + StringHelper.Dot); ! WalkAssociationTree(etype, columns, persister, alias, associations, classPersisters, subpath, session); } } ! else if(types[i].IsComponentType) { ! string subpath = SubPath(path, propertyNames[i]); WalkCompositeElementTree( ! (IAbstractComponentType) types[i], range, persister, --- 358,395 ---- IList classPersisters, string path, ! ISessionFactoryImplementor session ) { ! if( !session.EnableJoinedFetch ) ! { ! return; ! } ! IType[ ] types = act.Subtypes; ! string[ ] propertyNames = act.PropertyNames; int begin = 0; ! for( int i = 0; i < types.Length; i++ ) { ! int length = types[ i ].GetColumnSpan( session ); ! string[ ] range = ArrayHelper.Slice( cols, begin, length ); ! ! if( types[ i ].IsEntityType ) { ! EntityType etype = ( EntityType ) types[ i ]; ! string subpath = SubPath( path, propertyNames[ i ] ); ! bool autoEager = AutoEager( act.EnableJoinedFetch( i ), etype, session ); ! bool enable = EnableJoinedFetch( autoEager, subpath, persister.QualifiedTableName, range ); ! if( enable ) { ! string[ ] columns = StringHelper.Prefix( range, alias + StringHelper.Dot ); ! WalkAssociationTree( etype, columns, persister, alias, associations, classPersisters, subpath, session ); } } ! else if( types[ i ].IsComponentType ) { ! string subpath = SubPath( path, propertyNames[ i ] ); WalkCompositeElementTree( ! ( IAbstractComponentType ) types[ i ], range, persister, *************** *** 358,379 **** subpath, session ! ); ! } ! begin+=length; } - - } ! protected bool AutoEager(OuterJoinLoaderType config, EntityType type, ISessionFactoryImplementor session) { ! if (config==OuterJoinLoaderType.Eager) return true; ! if (config==OuterJoinLoaderType.Lazy) return false; IClassPersister persister = session.GetPersister( type.PersistentClass ); ! return !persister.HasProxy || ( type.IsOneToOne && ((OneToOneType) type).IsNullable ); } ! protected internal override SqlString SqlString { get { return sqlString; } --- 399,433 ---- subpath, session ! ); ! } ! begin += length; } + } ! /// <summary> ! /// ! /// </summary> ! /// <param name="config"></param> ! /// <param name="type"></param> ! /// <param name="session"></param> ! /// <returns></returns> ! protected bool AutoEager( OuterJoinLoaderType config, EntityType type, ISessionFactoryImplementor session ) { ! if( config == OuterJoinLoaderType.Eager ) ! { ! return true; ! } ! if( config == OuterJoinLoaderType.Lazy ) ! { ! return false; ! } IClassPersister persister = session.GetPersister( type.PersistentClass ); ! return !persister.HasProxy || ( type.IsOneToOne && ( ( OneToOneType ) type ).IsNullable ); } ! /// <summary></summary> ! protected internal override SqlString SqlString { get { return sqlString; } *************** *** 381,391 **** } ! protected override ILoadable[] Persisters { ! get { return classPersisters; } set { classPersisters = value; } } ! protected LockMode[] LockModeArray { get { return lockModeArray; } --- 435,447 ---- } ! /// <summary></summary> ! protected override ILoadable[ ] Persisters { ! get { return classPersisters; } set { classPersisters = value; } } ! /// <summary></summary> ! protected LockMode[ ] LockModeArray { get { return lockModeArray; } *************** *** 398,408 **** /// <param name="associations"></param> /// <returns></returns> ! public string SelectString(IList associations) { ! StringBuilder buf = new StringBuilder( associations.Count * 100 ); ! for (int i=0; i<associations.Count; i++) { ! OuterJoinableAssociation join = (OuterJoinableAssociation) associations[i]; ! AppendSelectString( buf, join.Subpersister, join.Subalias, Suffixes[i] ); ! if ( i<associations.Count-1) buf.Append(StringHelper.CommaSpace); } return buf.ToString(); --- 454,468 ---- /// <param name="associations"></param> /// <returns></returns> ! public string SelectString( IList associations ) ! { ! StringBuilder buf = new StringBuilder( associations.Count*100 ); ! for( int i = 0; i < associations.Count; i++ ) { ! OuterJoinableAssociation join = ( OuterJoinableAssociation ) associations[ i ]; ! AppendSelectString( buf, join.Subpersister, join.Subalias, Suffixes[ i ] ); ! if( i < associations.Count - 1 ) ! { ! buf.Append( StringHelper.CommaSpace ); ! } } return buf.ToString(); *************** *** 416,423 **** /// <param name="suffix"></param> /// <returns></returns> ! protected static string SelectString(ILoadable persister, string alias, string suffix) { ! StringBuilder buf = new StringBuilder(30); ! AppendSelectString(buf, persister, alias, suffix); return buf.ToString(); } --- 476,483 ---- /// <param name="suffix"></param> /// <returns></returns> ! protected static string SelectString( ILoadable persister, string alias, string suffix ) { ! StringBuilder buf = new StringBuilder( 30 ); ! AppendSelectString( buf, persister, alias, suffix ); return buf.ToString(); } *************** *** 430,442 **** /// <param name="alias"></param> /// <param name="suffix"></param> ! private static void AppendSelectString(StringBuilder buf, ILoadable persister, string alias, string suffix) { // doing a ToString is okay because SelectFragments will have no parameters // and will be just straight strings cotaining sql. ! buf.Append( persister.IdentifierSelectFragment(alias,suffix).ToString() ) ! .Append( persister.PropertySelectFragment(alias, suffix).ToString() ); } ! protected override string[] Suffixes { get { return suffixes; } --- 490,503 ---- /// <param name="alias"></param> /// <param name="suffix"></param> ! private static void AppendSelectString( StringBuilder buf, ILoadable persister, string alias, string suffix ) { // doing a ToString is okay because SelectFragments will have no parameters // and will be just straight strings cotaining sql. ! buf.Append( persister.IdentifierSelectFragment( alias, suffix ).ToString() ) ! .Append( persister.PropertySelectFragment( alias, suffix ).ToString() ); } ! /// <summary></summary> ! protected override string[ ] Suffixes { get { return suffixes; } *************** *** 444,460 **** } ! protected string ToAlias(string tableName, int n) { // H2.0.3 - was called Alias, but changed it to ToAlias because I wanted to have // a protected property named Alias ! //TODO: this is broken if we have quoted identifier with a "." ! tableName = StringHelper.Unqualify(tableName); //TODO: H2.0.3 - changes tableName to lower case - don't know why it is needed... ! return ( new Alias(10, n.ToString() + StringHelper.Underscore) ).ToAliasString( tableName, Dialect ); } ! protected override CollectionPersister CollectionPersister { get { return null; } --- 505,528 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="tableName"></param> ! /// <param name="n"></param> ! /// <returns></returns> ! protected string ToAlias( string tableName, int n ) { // H2.0.3 - was called Alias, but changed it to ToAlias because I wanted to have // a protected property named Alias ! //TODO: this is broken if we have quoted identifier with a "." ! tableName = StringHelper.Unqualify( tableName ); //TODO: H2.0.3 - changes tableName to lower case - don't know why it is needed... ! return ( new Alias( 10, n.ToString() + StringHelper.Underscore ) ).ToAliasString( tableName, Dialect ); } ! /// <summary></summary> ! protected override CollectionPersister CollectionPersister { get { return null; } *************** *** 466,473 **** /// <param name="associations"></param> /// <returns></returns> ! public JoinFragment OuterJoins(IList associations) { JoinFragment outerjoin = Dialect.CreateOuterJoinFragment(); ! foreach(OuterJoinLoader.OuterJoinableAssociation oj in associations) { outerjoin.AddJoin( --- 534,541 ---- /// <param name="associations"></param> /// <returns></returns> ! public JoinFragment OuterJoins( IList associations ) { JoinFragment outerjoin = Dialect.CreateOuterJoinFragment(); ! foreach( OuterJoinableAssociation oj in associations ) { outerjoin.AddJoin( *************** *** 478,485 **** JoinType.LeftOuterJoin ); ! outerjoin.AddJoins( ! oj.Subpersister.FromJoinFragment(oj.Subalias, false, true), ! oj.Subpersister.WhereJoinFragment(oj.Subalias, false, true) ); } --- 546,553 ---- JoinType.LeftOuterJoin ); ! outerjoin.AddJoins( ! oj.Subpersister.FromJoinFragment( oj.Subalias, false, true ), ! oj.Subpersister.WhereJoinFragment( oj.Subalias, false, true ) ); } *************** *** 487,517 **** } ! protected override LockMode[] GetLockModes(IDictionary lockModes) { return lockModeArray; } ! protected LockMode[] CreateLockModeArray(int length, LockMode lockMode) { ! LockMode[] lmArray = new LockMode[length]; ! for(int i = 0 ; i < length; i++) { ! lmArray[i] = lockMode; } return lmArray; } ! private string SubPath(string path, string property) { ! if(path==null || path.Length==0) { return property; } ! else { return path + StringHelper.Dot + property; } } ! } ! } --- 555,596 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="lockModes"></param> ! /// <returns></returns> ! protected override LockMode[ ] GetLockModes( IDictionary lockModes ) { return lockModeArray; } ! /// <summary> ! /// ! /// </summary> ! /// <param name="length"></param> ! /// <param name="lockMode"></param> ! /// <returns></returns> ! protected LockMode[ ] CreateLockModeArray( int length, LockMode lockMode ) { ! LockMode[ ] lmArray = new LockMode[length]; ! for( int i = 0; i < length; i++ ) { ! lmArray[ i ] = lockMode; } return lmArray; } ! private string SubPath( string path, string property ) { ! if( path == null || path.Length == 0 ) { return property; } ! else { return path + StringHelper.Dot + property; } } ! } ! } \ No newline at end of file Index: OneToManyLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/OneToManyLoader.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** OneToManyLoader.cs 22 Nov 2004 03:53:07 -0000 1.12 --- OneToManyLoader.cs 31 Dec 2004 20:57:56 -0000 1.13 *************** *** 1,6 **** using System; - using System.Text; using System.Collections; - using NHibernate.Collection; using NHibernate.Engine; --- 1,4 ---- *************** *** 10,104 **** using NHibernate.Util; ! namespace NHibernate.Loader { /// <summary> /// Loads one-to-many associations /// </summary> ! public class OneToManyLoader : OuterJoinLoader, ICollectionInitializer { private CollectionPersister collectionPersister; private IType idType; ! ! protected override bool EnableJoinedFetch(bool mappingDefault, string path, string table, string[] foreignKeyColumns) { return mappingDefault && ( ! !table.Equals(collectionPersister.QualifiedTableName) || ! !ArrayHelper.Equals(foreignKeyColumns, collectionPersister.KeyColumnNames) ! ); } ! public OneToManyLoader(CollectionPersister collPersister, ISessionFactoryImplementor factory) : base ( factory.Dialect ) { collectionPersister = collPersister; idType = collectionPersister.KeyType; ! ILoadable persister = (ILoadable) factory.GetPersister( ! ((EntityType) collPersister.ElementType).PersistentClass); - string alias = ToAlias(collectionPersister.QualifiedTableName, 0); - SqlString whereSqlString = null; ! if (collectionPersister.HasWhere) ! whereSqlString = new SqlString(collectionPersister.GetSQLWhereString(alias)); ! ! IList associations = WalkTree(persister, alias, factory); ! int joins=associations.Count; ! Suffixes = new string[joins+1]; ! for (int i=0; i<=joins; i++) Suffixes[i] = (joins==0) ? String.Empty : i.ToString() + StringHelper.Underscore; ! JoinFragment ojf = OuterJoins(associations); - SqlSelectBuilder selectBuilder = new SqlSelectBuilder(factory); - selectBuilder.SetSelectClause( ! collectionPersister.SelectClauseFragment(alias) + ! (joins==0 ? String.Empty : "," + SelectString(associations) ) + ! ", " + ! SelectString( persister, alias, Suffixes[joins] ) ); selectBuilder.SetFromClause( ! persister.FromTableFragment(alias).Append( ! persister.FromJoinFragment(alias, true, true) ! ) ! ); ! selectBuilder.SetWhereClause(alias, collectionPersister.KeyColumnNames, collectionPersister.KeyType); ! if(collectionPersister.HasWhere) selectBuilder.AddWhereClause(whereSqlString); selectBuilder.SetOuterJoins( ojf.ToFromFragmentString, ojf.ToWhereFragmentString.Append( ! persister.WhereJoinFragment(alias, true, true) ! ) ! ); ! if(collectionPersister.HasOrdering) selectBuilder.SetOrderByClause( collectionPersister.GetSQLOrderByString(alias) ); this.SqlString = selectBuilder.ToSqlString(); ! Persisters = new ILoadable[joins+1]; ! LockModeArray = CreateLockModeArray(joins+1, LockMode.None); ! for (int i=0; i<joins; i++) { ! Persisters[i] = ((OuterJoinableAssociation) associations[i]).Subpersister; } ! Persisters[joins] = persister; ! PostInstantiate(); } ! protected override CollectionPersister CollectionPersister { get { return collectionPersister; } } ! public void Initialize(object id, PersistentCollection collection, object owner, ISessionImplementor session) { ! LoadCollection(session, id, idType, owner, collection); } } ! } --- 8,136 ---- using NHibernate.Util; ! namespace NHibernate.Loader { /// <summary> /// Loads one-to-many associations /// </summary> ! public class OneToManyLoader : OuterJoinLoader, ICollectionInitializer { private CollectionPersister collectionPersister; private IType idType; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="mappingDefault"></param> ! /// <param name="path"></param> ! /// <param name="table"></param> ! /// <param name="foreignKeyColumns"></param> ! /// <returns></returns> ! protected override bool EnableJoinedFetch( bool mappingDefault, string path, string table, string[ ] foreignKeyColumns ) { return mappingDefault && ( ! !table.Equals( collectionPersister.QualifiedTableName ) || ! !ArrayHelper.Equals( foreignKeyColumns, collectionPersister.KeyColumnNames ) ! ); } ! /// <summary> ! /// ! /// </summary> ! /// <param name="collPersister"></param> ! /// <param name="factory"></param> ! public OneToManyLoader( CollectionPersister collPersister, ISessionFactoryImplementor factory ) : base( factory.Dialect ) { collectionPersister = collPersister; idType = collectionPersister.KeyType; ! ILoadable persister = ( ILoadable ) factory.GetPersister( ! ( ( EntityType ) collPersister.ElementType ).PersistentClass ); ! ! string alias = ToAlias( collectionPersister.QualifiedTableName, 0 ); SqlString whereSqlString = null; ! if( collectionPersister.HasWhere ) ! { ! whereSqlString = new SqlString( collectionPersister.GetSQLWhereString( alias ) ); ! } ! IList associations = WalkTree( persister, alias, factory ); ! ! int joins = associations.Count; ! Suffixes = new string[joins + 1]; ! for( int i = 0; i <= joins; i++ ) ! { ! Suffixes[ i ] = ( joins == 0 ) ? String.Empty : i.ToString() + StringHelper.Underscore; ! } ! JoinFragment ojf = OuterJoins( associations ); ! ! SqlSelectBuilder selectBuilder = new SqlSelectBuilder( factory ); selectBuilder.SetSelectClause( ! collectionPersister.SelectClauseFragment( alias ) + ! ( joins == 0 ? String.Empty : "," + SelectString( associations ) ) + ! ", " + ! SelectString( persister, alias, Suffixes[ joins ] ) ); selectBuilder.SetFromClause( ! persister.FromTableFragment( alias ).Append( ! persister.FromJoinFragment( alias, true, true ) ! ) ! ); ! selectBuilder.SetWhereClause( alias, collectionPersister.KeyColumnNames, collectionPersister.KeyType ); ! if( collectionPersister.HasWhere ) ! { ! selectBuilder.AddWhereClause( whereSqlString ); ! } selectBuilder.SetOuterJoins( ojf.ToFromFragmentString, ojf.ToWhereFragmentString.Append( ! persister.WhereJoinFragment( alias, true, true ) ! ) ! ); ! if( collectionPersister.HasOrdering ) ! { ! selectBuilder.SetOrderByClause( collectionPersister.GetSQLOrderByString( alias ) ); ! } this.SqlString = selectBuilder.ToSqlString(); ! Persisters = new ILoadable[joins + 1]; ! LockModeArray = CreateLockModeArray( joins + 1, LockMode.None ); ! for( int i = 0; i < joins; i++ ) { ! Persisters[ i ] = ( ( OuterJoinableAssociation ) associations[ i ] ).Subpersister; } ! Persisters[ joins ] = persister; ! PostInstantiate(); } ! /// <summary></summary> ! protected override CollectionPersister CollectionPersister ! { get { return collectionPersister; } } ! /// <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 ) ! { ! LoadCollection( session, id, idType, owner, collection ); } } ! } \ No newline at end of file Index: Loader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/Loader.cs,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Loader.cs 27 Dec 2004 03:53:52 -0000 1.44 --- Loader.cs 31 Dec 2004 20:57:56 -0000 1.45 *************** *** 2,6 **** using System.Collections; using System.Data; ! using NHibernate.Collection; using NHibernate.Engine; --- 2,6 ---- using System.Collections; using System.Data; ! using log4net; using NHibernate.Collection; [...1372 lines suppressed...] { int size = persister.PropertyNames.Length; ! string[ ][ ] result = new string[size][ ]; ! for( int i = 0; i < size; i++ ) { ! result[ i ] = new Alias( suffix ).ToUnquotedAliasStrings( persister.GetPropertyColumnNames( i ), dialect ); } return result; } ! private string GetDiscriminatorAliases( string suffix, ILoadable persister ) { return persister.HasSubclasses ? ! new Alias( suffix ).ToUnquotedAliasString( persister.DiscriminatorColumnName, dialect ) : null; } } ! } \ No newline at end of file Index: SimpleEntityLoader.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Loader/SimpleEntityLoader.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SimpleEntityLoader.cs 22 Nov 2004 03:53:07 -0000 1.9 --- SimpleEntityLoader.cs 31 Dec 2004 20:57:56 -0000 1.10 *************** *** 2,7 **** using System.Collections; using System.Data; - using System.Text; - using NHibernate.Collection; using NHibernate.Engine; --- 2,5 ---- *************** *** 9,38 **** using NHibernate.SqlCommand; using NHibernate.Type; - using NHibernate.Util; ! namespace NHibernate.Loader { /// <summary> /// Loads entity instances one instance per select (ie without outerjoin fetching) /// </summary> ! public class SimpleEntityLoader : Loader, IUniqueEntityLoader { ! private ILoadable[] persister; ! private IType[] idType; private SqlString sqlString; ! private LockMode[] lockMode; ! ! private string[] NoSuffix = new string[] { String.Empty }; ! public SimpleEntityLoader(ILoadable persister, SqlString sqlString, LockMode lockMode, Dialect.Dialect d) : base(d) { ! this.persister = new ILoadable[] { persister }; ! this.idType = new IType[] { persister.IdentifierType }; this.sqlString = sqlString; ! this.lockMode = new LockMode[] {lockMode}; PostInstantiate(); } ! protected internal override SqlString SqlString { get { return sqlString; } --- 7,43 ---- using NHibernate.SqlCommand; using NHibernate.Type; ! namespace NHibernate.Loader { /// <summary> /// Loads entity instances one instance per select (ie without outerjoin fetching) /// </summary> ! public class SimpleEntityLoader : Loader, IUniqueEntityLoader { ! private ILoadable[ ] persister; ! private IType[ ] idType; private SqlString sqlString; ! private LockMode[ ] lockMode; ! private string[ ] NoSuffix = new string[ ] {String.Empty}; ! ! /// <summary> ! /// ! /// </summary> ! /// <param name="persister"></param> ! /// <param name="sqlString"></param> ! /// <param name="lockMode"></param> ! /// <param name="d"></param> ! public SimpleEntityLoader( ILoadable persister, SqlString sqlString, LockMode lockMode, Dialect.Dialect d ) : base( d ) { ! this.persister = new ILoadable[ ] {persister}; ! this.idType = new IType[ ] {persister.IdentifierType}; this.sqlString = sqlString; ! this.lockMode = new LockMode[ ] {lockMode}; PostInstantiate(); } ! /// <summary></summary> ! protected internal override SqlString SqlString { get { return sqlString; } *************** *** 40,44 **** } ! protected override ILoadable[] Persisters { get { return persister; } --- 45,50 ---- } ! /// <summary></summary> ! protected override ILoadable[ ] Persisters { get { return persister; } *************** *** 46,55 **** } ! protected override CollectionPersister CollectionPersister { get { return null; } } ! protected override string[] Suffixes { get { return NoSuffix; } --- 52,63 ---- } ! /// <summary></summary> ! protected override CollectionPersister CollectionPersister { get { return null; } } ! /// <summary></summary> ! protected override string[ ] Suffixes { get { return NoSuffix; } *************** *** 57,90 **** } ! public object Load(ISessionImplementor session, object id, object obj) { ! IList list = LoadEntity(session, new object[] { id }, idType, obj, id, false); ! if (list.Count==1) { ! return list[0]; //return ( (object[]) list[0] )[0]; ! } ! else if (list.Count==0) { return null; ! } ! else { ! throw new HibernateException("More than one row with the given identifier was found: " + id + ", for class: " + persister[0].ClassName ); } } ! protected override LockMode[] GetLockModes(IDictionary lockModes) { return lockMode; } protected override Object GetResultColumnOrRow( ! Object[] row, IDataReader rs, ! ISessionImplementor session) { ! ! return row[0]; } } ! } --- 65,118 ---- } ! /// <summary> ! /// ! /// </summary> ! /// <param name="session"></param> ! /// <param name="id"></param> ! /// <param name="obj"></param> ! /// <returns></returns> ! public object Load( ISessionImplementor session, object id, object obj ) { ! IList list = LoadEntity( session, new object[ ] {id}, idType, obj, id, false ); ! if( list.Count == 1 ) { ! return list[ 0 ]; //return ( (object[]) list[0] )[0]; ! } ! else if( list.Count == 0 ) { return null; ! } ! else { ! throw new HibernateException( "More than one row with the given identifier was found: " + id + ", for class: " + persister[ 0 ].ClassName ); } } ! /// <summary> ! /// ! /// </summary> ! /// <param name="lockModes"></param> ! /// <returns></returns> ! protected override LockMode[ ] GetLockModes( IDictionary lockModes ) ! { return lockMode; } + /// <summary> + /// + /// </summary> + /// <param name="row"></param> + /// <param name="rs"></param> + /// <param name="session"></param> + /// <returns></returns> protected override Object GetResultColumnOrRow( ! Object[ ] row, IDataReader rs, ! ISessionImplementor session ) ! { ! return row[ 0 ]; } } ! } \ No newline at end of file |