From: Paul H. <pha...@us...> - 2005-03-06 12:45:35
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21577/nhibernate/src/NHibernate/Cfg Modified Files: Binder.cs Configuration.cs Environment.cs Settings.cs SettingsFactory.cs Log Message: Refactored SessionImpl as per 2.1 for Save/Update Index: Environment.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Environment.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Environment.cs 23 Jan 2005 15:41:39 -0000 1.23 --- Environment.cs 6 Mar 2005 12:44:36 -0000 1.24 *************** *** 26,32 **** public sealed class Environment { ! private static readonly ILog log = LogManager.GetLogger( typeof( Environment ) ); ! ! private static IDictionary properties = new Hashtable(); /// <summary></summary> --- 26,31 ---- public sealed class Environment { ! /// <summary></summary> ! public const string Version = "0.8.0.0"; /// <summary></summary> *************** *** 47,51 **** public const string ShowSql = "hibernate.show_sql"; /// <summary></summary> ! public const string OuterJoin = "hibernate.use_outer_join"; /// <summary></summary> public const string OutputStylesheet = "hibernate.xml.output_stylesheet"; --- 46,60 ---- public const string ShowSql = "hibernate.show_sql"; /// <summary></summary> ! public const string UseOuterJoin = "hibernate.use_outer_join"; ! /// <summary></summary> ! public const string MaxFetchDepth = "hibernate.max_fetch_depth"; ! /// <summary></summary> ! public const string UseGetGeneratedKeys = "hibernate.jdbc.use_get_generated_keys"; ! /// <summary></summary> ! public const string StatementFetchSize = "hibernate.jdbc.fetch_size"; ! /// <summary></summary> ! public const string StatementBatchSize = "hibernate.jdbc.batch_size"; ! /// <summary></summary> ! public const string BatchVersionedData = "hibernate.jdbc.batch_versioned_data"; /// <summary></summary> public const string OutputStylesheet = "hibernate.xml.output_stylesheet"; *************** *** 63,66 **** --- 72,79 ---- public const string PrepareSql = "hibernate.prepare_sql"; + private static readonly ILog log = LogManager.GetLogger( typeof( Environment ) ); + + private static IDictionary properties = new Hashtable(); + /// <summary></summary> static Environment() *************** *** 79,84 **** properties[ key ] = props[ key ]; } - - } --- 92,95 ---- *************** *** 112,115 **** --- 123,136 ---- get { return true; } } + + /// <summary> + /// Issue warnings to user when any obsolete property names are used. + /// </summary> + /// <param name="props"></param> + /// <returns></returns> + public static bool VerifyProperties( IDictionary props ) + { + return false; + } } } \ No newline at end of file Index: Binder.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Binder.cs,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Binder.cs 1 Mar 2005 16:24:43 -0000 1.39 --- Binder.cs 6 Mar 2005 12:44:35 -0000 1.40 *************** *** 1269,1273 **** } ! public static void BindRoot(XmlDocument doc, Mappings model) { XmlNode hmNode = doc.DocumentElement; --- 1269,1273 ---- } ! public static void BindRoot( XmlDocument doc, Mappings model ) { XmlNode hmNode = doc.DocumentElement; *************** *** 1286,1305 **** // build the XPath and the nsmgr takes care of translating our prefix into // the user defined prefix... ! nsmgr.AddNamespace(nsPrefix, Configuration.MappingSchemaXMLNS); ! foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":class", nsmgr) ) { RootClass rootclass = new RootClass(); ! Binder.BindRootClass(n, rootclass, model); ! model.AddClass(rootclass); } ! foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":subclass", nsmgr) ) { ! PersistentClass superModel = GetSuperclass(model, n); HandleSubclass(superModel, model, n); } ! foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":joined-subclass", nsmgr) ) { PersistentClass superModel = GetSuperclass(model, n); --- 1286,1305 ---- // build the XPath and the nsmgr takes care of translating our prefix into // the user defined prefix... ! nsmgr.AddNamespace( nsPrefix, Configuration.MappingSchemaXMLNS ); ! foreach(XmlNode n in hmNode.SelectNodes( nsPrefix + ":class", nsmgr ) ) { RootClass rootclass = new RootClass(); ! Binder.BindRootClass( n, rootclass, model ); ! model.AddClass( rootclass ); } ! foreach(XmlNode n in hmNode.SelectNodes( nsPrefix + ":subclass", nsmgr ) ) { ! PersistentClass superModel = GetSuperclass( model, n ); HandleSubclass(superModel, model, n); } ! foreach(XmlNode n in hmNode.SelectNodes( nsPrefix + ":joined-subclass", nsmgr ) ) { PersistentClass superModel = GetSuperclass(model, n); *************** *** 1307,1311 **** } ! foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":query", nsmgr) ) { string qname = n.Attributes["name"].Value; --- 1307,1311 ---- } ! foreach(XmlNode n in hmNode.SelectNodes( nsPrefix + ":query", nsmgr ) ) { string qname = n.Attributes["name"].Value; *************** *** 1315,1331 **** } ! foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":sql-query", nsmgr) ) { string qname = n.Attributes["name"].Value; NamedSQLQuery namedQuery = new NamedSQLQuery( n.FirstChild.Value ); ! foreach(XmlNode returns in n.SelectNodes(nsPrefix + ":return", nsmgr) ) { string alias = returns.Attributes["alias"].Value; ! object clazz; try { ! //clazz = ReflectorHelper.ClassForName( returns.Attributes["class"] ); ! clazz = null; } catch (Exception) --- 1315,1330 ---- } ! foreach(XmlNode n in hmNode.SelectNodes( nsPrefix + ":sql-query", nsmgr ) ) { string qname = n.Attributes["name"].Value; NamedSQLQuery namedQuery = new NamedSQLQuery( n.FirstChild.Value ); ! foreach(XmlNode returns in n.SelectNodes( nsPrefix + ":return", nsmgr ) ) { string alias = returns.Attributes["alias"].Value; ! System.Type clazz; try { ! clazz = ReflectHelper.ClassForName( returns.Attributes["class"].Value ); } catch (Exception) *************** *** 1336,1339 **** --- 1335,1343 ---- } + foreach( XmlNode table in n.SelectNodes( nsPrefix + ":synchronise", nsmgr ) ) + { + namedQuery.AddSynchronizedTable( table.Attributes["table"].Value ); + } + log.Debug("Named sql query: " + qname + " -> " + namedQuery.QueryString ); model.AddSQLQuery(qname, namedQuery); Index: Configuration.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Configuration.cs,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Configuration.cs 1 Mar 2005 16:24:43 -0000 1.32 --- Configuration.cs 6 Mar 2005 12:44:35 -0000 1.33 *************** *** 6,9 **** --- 6,10 ---- using System.Xml.Schema; using log4net; + using Iesi.Collections; using NHibernate.Cache; using NHibernate.Engine; *************** *** 31,37 **** public class Configuration : IMapping { - private static readonly ILog log = LogManager.GetLogger( typeof( Configuration ) ); - private static readonly IInterceptor emptyInterceptor = new EmptyInterceptor(); - private Hashtable classes = new Hashtable(); private Hashtable imports = new Hashtable(); --- 32,35 ---- *************** *** 51,54 **** --- 49,91 ---- private XmlSchema cfgSchema; + private static readonly ILog log = LogManager.GetLogger( typeof( Configuration ) ); + private static readonly IInterceptor emptyInterceptor = new EmptyInterceptor(); + + private class Mapping : IMapping + { + private Hashtable classes; + + public Mapping( Hashtable classes ) + { + this.classes = classes; + } + + public Hashtable Classes + { + set { classes = value; } + } + + #region IMapping Members + + public IType GetIdentifierType( System.Type persistentClass ) + { + return ( (PersistentClass) classes[ persistentClass ] ).Identifier.Type; + } + + public string GetIdentifierPropertyName( System.Type persistentClass ) + { + return ( (PersistentClass) classes[ persistentClass ] ).IdentifierProperty.Name; + } + + public IType GetPropertyType( System.Type persistentClass, string propertyName ) + { + return ( (PersistentClass) classes[ persistentClass ] ).GetProperty( propertyName ).Type; + } + + #endregion + } + + private Mapping mapping; + /// <summary> /// The XML Namespace for the nhibernate-mapping *************** *** 78,81 **** --- 115,119 ---- interceptor = emptyInterceptor; properties = Environment.Properties; + mapping = new Mapping( classes ); } *************** *** 135,141 **** /// <param name="role">role a collection role</param> /// <returns>collection</returns> ! public Mapping.Collection GetCollectionMapping( string role ) { ! return ( Mapping.Collection ) collections[ role ]; } --- 173,179 ---- /// <param name="role">role a collection role</param> /// <returns>collection</returns> ! public NHibernate.Mapping.Collection GetCollectionMapping( string role ) { ! return ( NHibernate.Mapping.Collection ) collections[ role ]; } *************** *** 561,564 **** --- 599,606 ---- foreach( Table table in TableMappings ) { + foreach( Index index in table.IndexCollection ) + { + script.Add( index.SqlCreateString( dialect, this ) ); + } if( dialect.HasAlterTable ) { *************** *** 568,575 **** } } - foreach( Index index in table.IndexCollection ) - { - script.Add( index.SqlCreateString( dialect, this ) ); - } } --- 610,613 ---- *************** *** 586,646 **** } ! // ///<summary> ! // /// Generate DDL for altering tables ! // ///</summary> ! // public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, DatabaseMetadata databaseMetadata) ! // { ! // secondPassCompile(); ! // ! // ArrayList script = new ArrayList(50); ! // ! // foreach(Table table in TableMappings) ! // { ! // TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.Name ); ! // if (tableInfo==null) ! // { ! // script.Add( table.SqlCreateString(dialect, this) ); ! // } ! // else ! // { ! // foreach(string alterString in table.SqlAlterStrings(dialect, this, tableInfo)) ! // script.Add(alterString); ! // } ! // } ! // ! // foreach(Table table in TableMappings) ! // { ! // TableMetadata tableInfo = databaseMetadata.getTableMetadata( table.Name ); ! // ! // if ( dialect.HasAlterTable) ! // { ! // foreach(ForeignKey fk in table.ForeignKeyCollection) ! // if ( tableInfo==null || tableInfo.getForeignKeyMetadata( fk.Name ) == null ) ! // { ! // script.Add( fk.SqlCreateString(dialect, mapping) ); ! // } ! // } ! // foreach(Index index in table.IndexCollection) ! // { ! // if ( tableInfo==null || tableInfo.getIndexMetadata( index.Name ) == null ) ! // { ! // script.Add( index.SqlCreateString(dialect, mapping) ); ! // } ! // } ! // } ! // ! // foreach(IPersistentIdentifierGenerator generator in CollectionGenerators(dialect)) ! // { ! // object key = generator.GeneratorKey(); ! // if ( !databaseMetadata.IsSequence(key) && !databaseMetadata.IsTable(key) ) ! // { ! // string[] lines = generator.SqlCreateStrings(dialect); ! // for (int i = 0; i < lines.Length; i++) script.Add( lines[i] ); ! // } ! // } ! // ! // return ArrayHelper.ToStringArray(script); ! // } ! //TODO: H2.0.3 After DatabaseMetadata is completed /// <remarks> --- 624,704 ---- } ! /* ! ///<summary> ! /// Generate DDL for altering tables ! ///</summary> ! public string[] GenerateSchemaUpdateScript(Dialect.Dialect dialect, DatabaseMetadata databaseMetadata) ! { ! secondPassCompile(); ! ! ArrayList script = new ArrayList(50); ! ! foreach(Table table in TableMappings) ! { ! TableMetadata tableInfo = databaseMetadata.GetTableMetadata( table.Name, table.Schema, null ); ! if (tableInfo == null) ! { ! script.Add( table.SqlCreateString( dialect, this ) ); ! } ! else ! { ! foreach(string alterString in table.SqlAlterStrings(dialect, this, tableInfo)) ! { ! script.Add( alterString ); ! } ! } ! } ! ! foreach(Table table in TableMappings) ! { ! TableMetadata tableInfo = databaseMetadata.GetTableMetadata( table.Name, table.Schema, null ); ! ! if ( dialect.HasAlterTable) ! { ! foreach(ForeignKey fk in table.ForeignKeyCollection) ! { ! bool create = tableInfo == null || ( tableInfo.getForeignKeyMetadata( fk.Name ) == null && ( ! // Icky workaround for MySQL bug: ! !( dialect is NHibernate.Dialect.MySQLDialect ) || table.GetIndex( fk.Name ) == null ) ! ); ! if ( create ) ! { ! script.Add( fk.SqlCreateString(dialect, mapping) ); ! } ! } ! } ! ! // Broken 'cos we don't generate these with names in SchemaExport ! foreach(Index index in table.IndexCollection) ! { ! if ( tableInfo == null || tableInfo.GetIndexMetadata( index.Name ) == null ) ! { ! script.Add( index.SqlCreateString( dialect, mapping ) ); ! } ! } ! ! // Broken 'cos we don't generate these with names in SchemaExport ! foreach(UniqueKey uk in table.UniqueKeyCollection) ! { ! if ( tableInfo == null || tableInfo.GetIndexMetadata( uk.Name ) == null ) ! { ! script.Add( uk.SqlCreateString( dialect, mapping ) ); ! } ! } ! } ! ! foreach(IPersistentIdentifierGenerator generator in CollectionGenerators(dialect)) ! { ! object key = generator.GeneratorKey(); ! if ( !databaseMetadata.IsSequence( key ) && !databaseMetadata.IsTable(key) ) ! { ! string[] lines = generator.SqlCreateStrings( dialect ); ! for (int i = 0; i < lines.Length; i++) script.Add( lines[i] ); ! } ! } ! ! return ArrayHelper.ToStringArray(script); ! } ! */ /// <remarks> *************** *** 662,687 **** log.Info( "processing foreign key constraints" ); foreach( Table table in TableMappings ) { ! foreach( ForeignKey fk in table.ForeignKeyCollection ) { ! if( fk.ReferencedTable == null ) { ! if( log.IsDebugEnabled ) ! { ! log.Debug( "resolving reference to class: " + fk.ReferencedClass.Name ); ! } ! PersistentClass referencedClass = ( PersistentClass ) classes[ fk.ReferencedClass ]; ! if( referencedClass == null ) ! { ! throw new MappingException( ! "An association from the table " + ! fk.Table.Name + ! " refers to an unmapped class: " + ! fk.ReferencedClass.Name ! ); ! } ! fk.ReferencedTable = referencedClass.Table; } } } --- 720,756 ---- log.Info( "processing foreign key constraints" ); + ISet done = new HashedSet(); foreach( Table table in TableMappings ) { ! SecondPassCompileForeignKeys( table, done ); ! } ! } ! ! private void SecondPassCompileForeignKeys( Table table, ISet done ) ! { ! foreach( ForeignKey fk in table.ForeignKeyCollection ) ! { ! if ( !done.Contains( fk ) ) { ! done.Add( fk ); ! if( log.IsDebugEnabled ) { ! log.Debug( "resolving reference to class: " + fk.ReferencedClass.Name ); } + PersistentClass referencedClass = ( PersistentClass ) classes[ fk.ReferencedClass ]; + if( referencedClass == null ) + { + throw new MappingException( + "An association from the table " + + fk.Table.Name + + " refers to an unmapped class: " + + fk.ReferencedClass.Name + ); + } + if ( referencedClass.IsJoinedSubclass ) + { + SecondPassCompileForeignKeys( referencedClass.Superclass.Table, done ); + } + fk.ReferencedTable = referencedClass.Table; } } *************** *** 721,730 **** { SecondPassCompile(); Hashtable copy = new Hashtable( properties ); - Settings settings = BuildSettings(); ConfigureCaches( settings ); ! return new SessionFactoryImpl( this, copy, interceptor, settings ); } --- 790,813 ---- { SecondPassCompile(); + Validate(); + Environment.VerifyProperties( properties ); Hashtable copy = new Hashtable( properties ); Settings settings = BuildSettings(); ConfigureCaches( settings ); ! return new SessionFactoryImpl( this, settings ); ! } ! ! private void Validate() ! { ! foreach( PersistentClass clazz in classes.Values ) ! { ! clazz.Validate( mapping ); ! } ! ! foreach( NHibernate.Mapping.Collection col in collections.Values ) ! { ! col.Validate( mapping ); ! } } *************** *** 902,906 **** } } - } --- 985,988 ---- *************** *** 1025,1029 **** strategy.Cache = cache; - } } --- 1107,1110 ---- Index: Settings.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Settings.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Settings.cs 31 Dec 2004 15:54:08 -0000 1.4 --- Settings.cs 6 Mar 2005 12:44:36 -0000 1.5 *************** *** 14,23 **** --- 14,31 ---- private bool _isShowSqlEnabled; private bool _isOuterJoinFetchEnabled; + private int maximumFetchDepth; private IDictionary _querySubstitutions; private Dialect.Dialect _dialect; + private int batchSize; + private bool scrollableResultSetsEnabled; + private bool getGeneratedKeysEnabled; + private int statementFetchSize; private IsolationLevel _isolationLevel; private IConnectionProvider _connectionProvider; private ITransactionFactory _transactionFactory; private string _sessionFactoryName; + private bool autoCreateSchema; + private bool autoDropSchema; + private bool autoUpdateSchema; private ICacheProvider _cacheProvider; private string _defaultSchemaName; *************** *** 39,42 **** --- 47,106 ---- /// <summary></summary> + public bool IsScrollableResultSetsEnabled + { + get { return scrollableResultSetsEnabled; } + set { scrollableResultSetsEnabled = value; } + } + + /// <summary></summary> + public bool IsGetGeneratedKeysEnabled + { + get { return getGeneratedKeysEnabled; } + set { getGeneratedKeysEnabled = value; } + } + + /// <summary></summary> + public int BatchSize + { + get { return batchSize; } + set { batchSize = value; } + } + + /// <summary></summary> + public int MaximumFetchDepth + { + get { return maximumFetchDepth; } + set { maximumFetchDepth = value; } + } + + /// <summary></summary> + public bool IsAutoCreateSchema + { + get { return autoCreateSchema; } + set { autoCreateSchema = value; } + } + + /// <summary></summary> + public bool IsAutoDropSchema + { + get { return autoDropSchema; } + set { autoDropSchema = value; } + } + + /// <summary></summary> + public bool IsAutoUpdateSchema + { + get { return autoCreateSchema; } + set { autoCreateSchema = value; } + } + + /// <summary></summary> + public int StatementFetchSize + { + get { return statementFetchSize; } + set { statementFetchSize = value; } + } + + /// <summary></summary> public IDictionary QuerySubstitutions { Index: SettingsFactory.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/SettingsFactory.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SettingsFactory.cs 31 Dec 2004 15:54:08 -0000 1.3 --- SettingsFactory.cs 6 Mar 2005 12:44:36 -0000 1.4 *************** *** 56,60 **** ! bool useOuterJoin = PropertiesHelper.GetBoolean( Environment.OuterJoin, properties, true ); log.Info( "use outer join fetching: " + useOuterJoin ); --- 56,60 ---- ! bool useOuterJoin = PropertiesHelper.GetBoolean( Environment.UseOuterJoin, properties, true ); log.Info( "use outer join fetching: " + useOuterJoin ); |