From: Peter S. <sz...@us...> - 2004-04-29 17:46:50
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11993/NHibernate/Cfg Modified Files: Configuration.cs Log Message: Cfg/Configuration Index: Configuration.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cfg/Configuration.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Configuration.cs 15 Apr 2004 21:07:17 -0000 1.12 --- Configuration.cs 29 Apr 2004 17:46:37 -0000 1.13 *************** *** 100,103 **** --- 100,105 ---- /// Get the mapping for a particular collection role /// </summary> + /// <param name="role">role a collection role</param> + /// <returns>collection</returns> public Mapping.Collection GetCollectionMapping(string role) { return (Mapping.Collection) collections[role]; *************** *** 109,115 **** /// <param name="xmlFile">The name of the file (url or file system) that contains the Xml.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlFile(string xmlFile) { log.Debug("Mapping file: " + xmlFile); ! try { AddXmlReader(new XmlTextReader(xmlFile)); // XmlDocument doc = new XmlDocument(); --- 111,119 ---- /// <param name="xmlFile">The name of the file (url or file system) that contains the Xml.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlFile(string xmlFile) ! { log.Debug("Mapping file: " + xmlFile); ! try ! { AddXmlReader(new XmlTextReader(xmlFile)); // XmlDocument doc = new XmlDocument(); *************** *** 117,121 **** // Add ( doc ); } ! catch (Exception e) { log.Error("Could not configure datastore from file: " + xmlFile, e); throw new MappingException(e); --- 121,126 ---- // Add ( doc ); } ! catch (Exception e) ! { log.Error("Could not configure datastore from file: " + xmlFile, e); throw new MappingException(e); *************** *** 129,135 **** /// <param name="xml">A string that contains the Mappings for the Xml</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlString(string xml) { if ( log.IsDebugEnabled ) log.Debug("Mapping XML:\n" + xml); ! try { // make a StringReader for the string passed in - the StringReader --- 134,142 ---- /// <param name="xml">A string that contains the Mappings for the Xml</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlString(string xml) ! { if ( log.IsDebugEnabled ) log.Debug("Mapping XML:\n" + xml); ! try ! { // make a StringReader for the string passed in - the StringReader *************** *** 142,146 **** // Add ( doc ); } ! catch (Exception e) { log.Error("Could not configure datastore from XML", e); } --- 149,154 ---- // Add ( doc ); } ! catch (Exception e) ! { log.Error("Could not configure datastore from XML", e); } *************** *** 153,163 **** /// <param name="doc">A loaded XmlDocument that contains the Mappings.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddDocument(XmlDocument doc) { if ( log.IsDebugEnabled ) log.Debug("Mapping XML:\n" + doc.OuterXml); ! try { AddXmlReader(new XmlNodeReader(doc)); // Add ( doc ); } ! catch (Exception e) { log.Error("Could not configure datastore from XML document", e); throw new MappingException(e); --- 161,174 ---- /// <param name="doc">A loaded XmlDocument that contains the Mappings.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddDocument(XmlDocument doc) ! { if ( log.IsDebugEnabled ) log.Debug("Mapping XML:\n" + doc.OuterXml); ! try ! { AddXmlReader(new XmlNodeReader(doc)); // Add ( doc ); } ! catch (Exception e) ! { log.Error("Could not configure datastore from XML document", e); throw new MappingException(e); *************** *** 173,179 **** private void Add(XmlDocument doc) { ! try { Binder.dialect = Dialect.Dialect.GetDialect(properties); - //StringHelper.Dialect = Dialect.Dialect.GetDialect(properties); Binder.BindRoot( doc, CreateMappings()); } --- 184,190 ---- private void Add(XmlDocument doc) { ! try ! { Binder.dialect = Dialect.Dialect.GetDialect(properties); Binder.BindRoot( doc, CreateMappings()); } *************** *** 189,193 **** /// </summary> /// <returns></returns> ! public Mappings CreateMappings() { return new Mappings(classes, collections, tables, namedQueries, imports, secondPasses); } --- 200,205 ---- /// </summary> /// <returns></returns> ! public Mappings CreateMappings() ! { return new Mappings(classes, collections, tables, namedQueries, imports, secondPasses); } *************** *** 198,203 **** /// <param name="xmlInputStream">The Stream to read Xml from.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddInputStream(Stream xmlInputStream) { ! try { AddXmlReader(new XmlTextReader(xmlInputStream)); --- 210,217 ---- /// <param name="xmlInputStream">The Stream to read Xml from.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddInputStream(Stream xmlInputStream) ! { ! try ! { AddXmlReader(new XmlTextReader(xmlInputStream)); *************** *** 207,214 **** return this; } ! catch (MappingException me) { throw me; } ! catch (Exception e) { log.Error("Could not configure datastore from input stream", e); throw new MappingException(e); --- 221,230 ---- return this; } ! catch (MappingException me) ! { throw me; } ! catch (Exception e) ! { log.Error("Could not configure datastore from input stream", e); throw new MappingException(e); *************** *** 222,226 **** /// <param name="hbmReader">The XmlReader that contains the mapping.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlReader(XmlReader hbmReader) { XmlValidatingReader validatingReader = new XmlValidatingReader(hbmReader); --- 238,243 ---- /// <param name="hbmReader">The XmlReader that contains the mapping.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddXmlReader(XmlReader hbmReader) ! { XmlValidatingReader validatingReader = new XmlValidatingReader(hbmReader); *************** *** 241,245 **** /// <param name="assembly">The Assembly that contains the Resource file.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddResource(string path, Assembly assembly) { log.Info("mapping resource: " + path); Stream rsrc = assembly.GetManifestResourceStream(path); --- 258,263 ---- /// <param name="assembly">The Assembly that contains the Resource file.</param> /// <returns>This Configuration object.</returns> ! public Configuration AddResource(string path, Assembly assembly) ! { log.Info("mapping resource: " + path); Stream rsrc = assembly.GetManifestResourceStream(path); *************** *** 258,262 **** /// the same naming convention then this can not be used. /// </remarks> ! public Configuration AddClass(System.Type persistentClass) { string fileName = persistentClass.FullName + ".hbm.xml"; log.Info("Mapping resource: " + fileName); --- 276,281 ---- /// the same naming convention then this can not be used. /// </remarks> ! public Configuration AddClass(System.Type persistentClass) ! { string fileName = persistentClass.FullName + ".hbm.xml"; log.Info("Mapping resource: " + fileName); *************** *** 275,299 **** /// Assembly can be loaded by name. /// </remarks> ! public Configuration AddAssembly(string assemblyName) { log.Info("searching for mapped documents in assembly: " + assemblyName); Assembly assembly = null; ! try { assembly = Assembly.Load(assemblyName); } ! catch (Exception e) { log.Error("Could not configure datastore from assembly", e); throw new MappingException(e); } ! foreach(string fileName in assembly.GetManifestResourceNames() ) { ! if ( fileName.EndsWith(".hbm.xml") ) { log.Info( "Found mapping documents in assembly: " + fileName ); ! try { AddInputStream( assembly.GetManifestResourceStream(fileName) ); } ! catch (MappingException me) { throw me; } ! catch (Exception e) { log.Error("Could not configure datastore from assembly", e); throw new MappingException(e); --- 294,326 ---- /// Assembly can be loaded by name. /// </remarks> ! public Configuration AddAssembly(string assemblyName) ! { log.Info("searching for mapped documents in assembly: " + assemblyName); Assembly assembly = null; ! try ! { assembly = Assembly.Load(assemblyName); } ! catch (Exception e) ! { log.Error("Could not configure datastore from assembly", e); throw new MappingException(e); } ! foreach(string fileName in assembly.GetManifestResourceNames() ) ! { ! if ( fileName.EndsWith(".hbm.xml") ) ! { log.Info( "Found mapping documents in assembly: " + fileName ); ! try ! { AddInputStream( assembly.GetManifestResourceStream(fileName) ); } ! catch (MappingException me) ! { throw me; } ! catch (Exception e) ! { log.Error("Could not configure datastore from assembly", e); throw new MappingException(e); *************** *** 326,332 **** ArrayList script = new ArrayList(50); ! if ( dialect.DropConstraints ) { ! foreach(Table table in TableMappings) { ! foreach(ForeignKey fk in table.ForeignKeyCollection) { script.Add(fk.SqlDropString(dialect)); } --- 353,362 ---- ArrayList script = new ArrayList(50); ! if ( dialect.DropConstraints ) ! { ! foreach(Table table in TableMappings) ! { ! foreach(ForeignKey fk in table.ForeignKeyCollection) ! { script.Add(fk.SqlDropString(dialect)); } *************** *** 334,342 **** } ! foreach(Table table in TableMappings) { script.Add( table.SqlDropString(dialect) ); } ! foreach(IPersistentIdentifierGenerator idGen in CollectionGenerators(dialect) ) { string dropString = idGen.SqlDropString(dialect); if (dropString!=null) script.Add( dropString ); --- 364,374 ---- } ! foreach(Table table in TableMappings) ! { script.Add( table.SqlDropString(dialect) ); } ! foreach(IPersistentIdentifierGenerator idGen in CollectionGenerators(dialect) ) ! { string dropString = idGen.SqlDropString(dialect); if (dropString!=null) script.Add( dropString ); *************** *** 349,371 **** /// Generate DDL for creating tables /// </summary> ! public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect) { SecondPassCompile(); ArrayList script = new ArrayList(50); ! foreach(Table table in TableMappings) { script.Add( table.SqlCreateString(dialect, this) ); } ! foreach(Table table in TableMappings) { ! foreach(ForeignKey fk in table.ForeignKeyCollection) { ! script.Add( fk.SqlCreateString(dialect, this) ); ! } ! foreach(Index index in table.IndexCollection) { script.Add( index.SqlCreateString(dialect, this) ); } } ! foreach(IPersistentIdentifierGenerator idGen in CollectionGenerators(dialect)) { string[] lines = idGen.SqlCreateStrings(dialect); for (int i=0; i<lines.Length; i++ ) script.Add( lines[i] ); --- 381,410 ---- /// Generate DDL for creating tables /// </summary> ! public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect) ! { SecondPassCompile(); ArrayList script = new ArrayList(50); ! foreach(Table table in TableMappings) ! { script.Add( table.SqlCreateString(dialect, this) ); } ! foreach(Table table in TableMappings) ! { ! if (dialect.HasAlterTable) ! foreach(ForeignKey fk in table.ForeignKeyCollection) ! { ! script.Add( fk.SqlCreateString(dialect, this) ); ! } ! foreach(Index index in table.IndexCollection) ! { script.Add( index.SqlCreateString(dialect, this) ); } } ! foreach(IPersistentIdentifierGenerator idGen in CollectionGenerators(dialect)) ! { string[] lines = idGen.SqlCreateStrings(dialect); for (int i=0; i<lines.Length; i++ ) script.Add( lines[i] ); *************** *** 375,384 **** } ! ! ! private void SecondPassCompile() { ! foreach(Binder.SecondPass sp in secondPasses) { sp.DoSecondPass(classes); } --- 414,485 ---- } ! // ///<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> ! /// This method may be called many times!! ! /// </remarks> ! private void SecondPassCompile() ! { ! log.Info("processing one-to-many association mappings"); ! ! foreach(Binder.SecondPass sp in secondPasses) ! { sp.DoSecondPass(classes); } *************** *** 386,395 **** secondPasses.Clear(); ! foreach(Table table in TableMappings) { ! foreach(ForeignKey fk in table.ForeignKeyCollection) { ! if ( fk.ReferencedTable == null ) { PersistentClass referencedClass = (PersistentClass) classes[ fk.ReferencedClass ]; if ( referencedClass==null ) throw new MappingException( ! "An association refers to an unmapped class: " + fk.ReferencedClass.Name ); --- 487,506 ---- secondPasses.Clear(); ! //TODO: Somehow add the newly created foreign keys to the internal collection ! ! 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 ); *************** *** 403,407 **** /// The named queries /// </summary> ! public IDictionary NamedQueries { get { return namedQueries; } } --- 514,519 ---- /// The named queries /// </summary> ! public IDictionary NamedQueries ! { get { return namedQueries; } } *************** *** 410,448 **** [Serializable] ! private class EmptyInterceptorClass : IInterceptor { ! public void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types) { } ! public bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types) { return false; } ! public bool OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types) { return false; } ! public bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) { return false; } ! public void OnPostFlush(object entity, object id, object[] currentState, string[] propertyNames, IType[] types) { } ! public void PostFlush(ICollection entities) { } ! public void PreFlush(ICollection entitites) { } ! public object IsUnsaved(object entity) { return null; } ! public object Instantiate(System.Type clazz, object id) { return null; } ! public int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types) { return null; } --- 522,571 ---- [Serializable] ! private class EmptyInterceptorClass : IInterceptor ! { ! public void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types) ! { } ! public bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types) ! { return false; } ! public bool OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types) ! { return false; } ! public bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) ! { return false; } ! public void OnPostFlush(object entity, object id, object[] currentState, string[] propertyNames, IType[] types) ! { } ! public void PostFlush(ICollection entities) ! { } ! public void PreFlush(ICollection entitites) ! { } ! public object IsUnsaved(object entity) ! { return null; } ! public object Instantiate(System.Type clazz, object id) ! { return null; } ! public int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types) ! { return null; } *************** *** 455,462 **** /// </summary> /// <returns></returns> ! public ISessionFactory BuildSessionFactory() { SecondPassCompile(); Hashtable copy = new Hashtable(); ! foreach(DictionaryEntry de in properties) { copy.Add(de.Key, de.Value); } --- 578,587 ---- /// </summary> /// <returns></returns> ! public ISessionFactory BuildSessionFactory() ! { SecondPassCompile(); Hashtable copy = new Hashtable(); ! foreach(DictionaryEntry de in properties) ! { copy.Add(de.Key, de.Value); } *************** *** 464,479 **** } ! public IInterceptor Interceptor { ! get { return interceptor; } ! set { this.interceptor = value; } } ! public IDictionary Properties { ! get { return properties; } ! set { this.properties = value; } } ! public Configuration AddProperties(IDictionary properties) { ! foreach(DictionaryEntry de in properties) { this.properties.Add(de.Key, de.Value); } --- 589,620 ---- } ! public IInterceptor Interceptor ! { ! get ! { ! return interceptor; ! } ! set ! { ! this.interceptor = value; ! } } ! public IDictionary Properties ! { ! get ! { ! return properties; ! } ! set ! { ! this.properties = value; ! } } ! public Configuration AddProperties(IDictionary properties) ! { ! foreach(DictionaryEntry de in properties) ! { this.properties.Add(de.Key, de.Value); } *************** *** 481,494 **** } ! public void SetProperty(string name, string value) { properties[name] = value; } ! public string GetProperty(string name) { return properties[name] as string; } ! private void AddProperties(XmlNode parent) { ! foreach(XmlNode node in parent.SelectNodes("property")) { string name = node.Attributes["name"].Value; string value = node.FirstChild.Value; --- 622,640 ---- } ! public Configuration SetProperty(string name, string value) ! { properties[name] = value; + return this; } ! public string GetProperty(string name) ! { return properties[name] as string; } ! private void AddProperties(XmlNode parent) ! { ! foreach(XmlNode node in parent.SelectNodes("property")) ! { string name = node.Attributes["name"].Value; string value = node.FirstChild.Value; *************** *** 499,514 **** } ! ! public Configuration Configure() { Configure("hibernate.cfg.xml"); return this; } ! public Configuration Configure(string resource) { XmlDocument doc = new XmlDocument(); ! try { doc.Load(resource); ! } catch (Exception e) { log.Error("Problem parsing configuraiton " + resource, e); throw new HibernateException("problem parsing configuration " + resource + ": " + e); --- 645,664 ---- } ! public Configuration Configure() ! { Configure("hibernate.cfg.xml"); return this; } ! public Configuration Configure(string resource) ! { XmlDocument doc = new XmlDocument(); ! try ! { doc.Load(resource); ! } ! catch (Exception e) ! { log.Error("Problem parsing configuraiton " + resource, e); throw new HibernateException("problem parsing configuration " + resource + ": " + e); *************** *** 520,536 **** AddProperties(sfNode); ! foreach(XmlNode mapElement in sfNode.ChildNodes) { string elemname = mapElement.Name; ! if ( "mapping".Equals(elemname) ) { XmlAttribute rsrc = mapElement.Attributes["resource"]; XmlAttribute file = mapElement.Attributes["file"]; XmlAttribute assembly = mapElement.Attributes["assembly"]; ! if (rsrc!=null) { log.Debug(name + "<-" + rsrc); AddResource( rsrc.Value, Assembly.GetExecutingAssembly() ); ! } else if ( assembly!=null) { log.Debug(name + "<-" + assembly); AddAssembly(assembly.Value); ! } else { if (file==null) throw new MappingException("<mapping> element in configuration specifies no attributes"); log.Debug(name + "<-" + file); --- 670,693 ---- AddProperties(sfNode); ! foreach(XmlNode mapElement in sfNode.ChildNodes) ! { string elemname = mapElement.Name; ! if ( "mapping".Equals(elemname) ) ! { XmlAttribute rsrc = mapElement.Attributes["resource"]; XmlAttribute file = mapElement.Attributes["file"]; XmlAttribute assembly = mapElement.Attributes["assembly"]; ! if (rsrc!=null) ! { log.Debug(name + "<-" + rsrc); AddResource( rsrc.Value, Assembly.GetExecutingAssembly() ); ! } ! else if ( assembly!=null) ! { log.Debug(name + "<-" + assembly); AddAssembly(assembly.Value); ! } ! else ! { if (file==null) throw new MappingException("<mapping> element in configuration specifies no attributes"); log.Debug(name + "<-" + file); *************** *** 550,555 **** /// </summary> /// <returns></returns> ! public IDictionary Imports { ! get { return imports; } } } --- 707,716 ---- /// </summary> /// <returns></returns> ! public IDictionary Imports ! { ! get ! { ! return imports; ! } } } |