From: John M. <joh...@us...> - 2005-03-23 00:39:45
|
Update of /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3700/src/NHibernate.Tool.Net2Hbm Modified Files: ClassPolymorphismType.cs IdAttribute.cs ListAttribute.cs ManyToOneAttribute.cs MapGenerator.cs PropertyAttribute.cs SetAttribute.cs VersionAttribute.cs Log Message: Added more support for the access strategy in NHibernate. Fixed an issue with recursive type walking. Index: ListAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/ListAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ListAttribute.cs 30 Dec 2004 16:54:02 -0000 1.1 --- ListAttribute.cs 23 Mar 2005 00:39:35 -0000 1.2 *************** *** 17,20 **** --- 17,21 ---- private CascadeType m_Cascade = CascadeType.None; private string m_SqlWhere; + private string m_Access = MapGenerator.DefaultAccessStrategy; #endregion *************** *** 81,84 **** --- 82,103 ---- set { m_SqlWhere = value; } } + + /// <summary> + /// Gets and sets the Access. + /// </summary> + public string Access + { + get { return m_Access; } + set { m_Access = value; } + } + + /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } } } Index: PropertyAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/PropertyAttribute.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PropertyAttribute.cs 13 Feb 2005 03:40:44 -0000 1.2 --- PropertyAttribute.cs 23 Mar 2005 00:39:35 -0000 1.3 *************** *** 13,17 **** private string m_Column; private System.Type m_Type; ! private string m_Access = "property"; private bool m_Update = true; private bool m_Insert = true; --- 13,17 ---- private string m_Column; private System.Type m_Type; ! private string m_Access = MapGenerator.DefaultAccessStrategy; private bool m_Update = true; private bool m_Insert = true; *************** *** 104,107 **** --- 104,116 ---- /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } + + /// <summary> /// Gets and sets the Column. /// </summary> Index: IdAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/IdAttribute.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IdAttribute.cs 13 Feb 2005 03:40:44 -0000 1.2 --- IdAttribute.cs 23 Mar 2005 00:39:35 -0000 1.3 *************** *** 12,16 **** private string m_Column; ! private string m_Access = "property"; private UnsavedValueType m_UnsavedValueType = UnsavedValueType.Null; private string m_UnsavedValue; --- 12,16 ---- private string m_Column; ! private string m_Access = MapGenerator.DefaultAccessStrategy; private UnsavedValueType m_UnsavedValueType = UnsavedValueType.Null; private string m_UnsavedValue; *************** *** 47,50 **** --- 47,59 ---- /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } + + /// <summary> /// Gets and sets the UnsavedValueType. /// </summary> Index: ClassPolymorphismType.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/ClassPolymorphismType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassPolymorphismType.cs 30 Dec 2004 16:54:02 -0000 1.1 --- ClassPolymorphismType.cs 23 Mar 2005 00:39:35 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Xml.Serialization; namespace NHibernate.Tool.Net2Hbm *************** *** 8,12 **** --- 9,16 ---- public enum ClassPolymorphismType { + [XmlEnum("implicit")] Implicit = 0, + + [XmlEnum("explicit")] Explicit = 1 } Index: ManyToOneAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/ManyToOneAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ManyToOneAttribute.cs 30 Dec 2004 16:54:02 -0000 1.1 --- ManyToOneAttribute.cs 23 Mar 2005 00:39:35 -0000 1.2 *************** *** 18,21 **** --- 18,22 ---- private CascadeType m_Cascade; private bool m_Inheritable = true; + private string m_Access = MapGenerator.DefaultAccessStrategy; #endregion *************** *** 109,112 **** --- 110,130 ---- } + /// <summary> + /// Gets and sets the Access. + /// </summary> + public string Access + { + get { return m_Access; } + set { m_Access = value; } + } + + /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } } } Index: MapGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/MapGenerator.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MapGenerator.cs 13 Feb 2005 03:40:44 -0000 1.4 --- MapGenerator.cs 23 Mar 2005 00:39:35 -0000 1.5 *************** *** 14,22 **** public sealed class MapGenerator { #region Member Variables private SortedList m_Types; - private Regex m_AssemblyQualifiedNameRegex; - private const string AssemblyQualifiedPattern = @"^(?<type>[\w\.\[\]]+),\s(?<assembly>[\w\.]+),\sVersion=(?<version>[\d\.]+),\sCulture=(?<culture>[\w\.]+),\sPublicKeyToken=(?<key>[\w]+)$"; #endregion --- 14,26 ---- public sealed class MapGenerator { + #region Constants + + public const string DefaultAccessStrategy = "property"; + + #endregion + #region Member Variables private SortedList m_Types; #endregion *************** *** 28,32 **** { m_Types = new SortedList(); - m_AssemblyQualifiedNameRegex = new Regex( MapGenerator.AssemblyQualifiedPattern, RegexOptions.None ); } --- 32,35 ---- *************** *** 145,151 **** /// <param name="writer"></param> /// <param name="type"></param> ! private void WriteCollections( XmlWriter writer, System.Type type, bool declaredOnly ) { ! PropertyInfo[] listProps = FindAttributedProperties( typeof(ListAttribute), type, declaredOnly ); foreach( PropertyInfo listProp in listProps ) { --- 148,154 ---- /// <param name="writer"></param> /// <param name="type"></param> ! private void WriteCollections( XmlWriter writer, System.Type type ) { ! PropertyInfo[] listProps = FindAttributedProperties( typeof(ListAttribute), type ); foreach( PropertyInfo listProp in listProps ) { *************** *** 153,157 **** } ! PropertyInfo[] setProps = FindAttributedProperties( typeof(SetAttribute), type, declaredOnly ); foreach( PropertyInfo setProp in setProps ) { --- 156,160 ---- } ! PropertyInfo[] setProps = FindAttributedProperties( typeof(SetAttribute), type ); foreach( PropertyInfo setProp in setProps ) { *************** *** 172,175 **** --- 175,179 ---- writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "table", attribute.Table ); + writer.WriteAttributeString( "access", attribute.Access ); if( attribute.IsLazy ) writer.WriteAttributeString( "lazy", "true" ); if( attribute.IsInverse ) writer.WriteAttributeString( "inverse", "true" ); *************** *** 193,196 **** --- 197,201 ---- writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "table", attribute.Table ); + writer.WriteAttributeString( "access", attribute.Access ); if( attribute.IsLazy ) writer.WriteAttributeString( "lazy", "true" ); WriteCollectionKey( writer, property ); *************** *** 265,269 **** writer.WriteStartElement( "composite-element" ); writer.WriteAttributeString( "class", GetShortTypeName( attribute.Type ) ); ! WriteProperties( writer, attribute.Type, false ); writer.WriteEndElement(); //</composite-element> } --- 270,274 ---- writer.WriteStartElement( "composite-element" ); writer.WriteAttributeString( "class", GetShortTypeName( attribute.Type ) ); ! WriteProperties( writer, attribute.Type ); writer.WriteEndElement(); //</composite-element> } *************** *** 321,327 **** writer.WriteAttributeString( "dynamic-update", "true" ); ! WriteProperties( writer, type, true ); ! WriteCollections( writer, type, true ); ! WriteAssociations( writer, type, true ); foreach( TypeNode childNode in node.Nodes ) --- 326,332 ---- writer.WriteAttributeString( "dynamic-update", "true" ); ! WriteProperties( writer, type ); ! WriteCollections( writer, type ); ! WriteAssociations( writer, type ); foreach( TypeNode childNode in node.Nodes ) *************** *** 343,346 **** --- 348,354 ---- writer.WriteAttributeString( "table", attribute.Table ); + if( attribute.Polymorphism != ClassPolymorphismType.Implicit ) + writer.WriteAttributeString( "polymorphism", GetXmlEnumValue( typeof(ClassPolymorphismType), attribute.Polymorphism ) ); + if( attribute.DiscriminatorValue != null ) writer.WriteAttributeString( "discriminator-value", attribute.DiscriminatorValue ); *************** *** 352,358 **** WriteDiscriminator( writer, type ); WriteVersion( writer, type ); ! WriteProperties( writer, type, false ); ! WriteCollections( writer, type, false ); ! WriteAssociations( writer, type, false ); foreach( TypeNode childNode in node.Nodes ) --- 360,366 ---- WriteDiscriminator( writer, type ); WriteVersion( writer, type ); ! WriteProperties( writer, type ); ! WriteCollections( writer, type ); ! WriteAssociations( writer, type ); foreach( TypeNode childNode in node.Nodes ) *************** *** 409,415 **** /// <param name="writer"></param> /// <param name="parentNode"></param> ! private void WriteProperties( XmlWriter writer, System.Type type, bool declaredOnly ) { ! PropertyInfo[] properties = FindAttributedProperties( typeof(PropertyAttribute), type, declaredOnly ); foreach( PropertyInfo property in properties ) { --- 417,423 ---- /// <param name="writer"></param> /// <param name="parentNode"></param> ! private void WriteProperties( XmlWriter writer, System.Type type ) { ! PropertyInfo[] properties = FindAttributedProperties( typeof(PropertyAttribute), type ); foreach( PropertyInfo property in properties ) { *************** *** 423,429 **** /// <param name="writer"></param> /// <param name="type"></param> ! private void WriteAssociations( XmlWriter writer, System.Type type, bool declaredOnly ) { ! PropertyInfo[] properties = FindAttributedProperties( typeof(ManyToOneAttribute), type, declaredOnly ); foreach( PropertyInfo property in properties ) { --- 431,437 ---- /// <param name="writer"></param> /// <param name="type"></param> ! private void WriteAssociations( XmlWriter writer, System.Type type ) { ! PropertyInfo[] properties = FindAttributedProperties( typeof(ManyToOneAttribute), type ); foreach( PropertyInfo property in properties ) { *************** *** 445,449 **** writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "column", attribute.Column == null ? property.Name : attribute.Column ); ! string typeName = null; if( attribute.Type != null ) --- 453,458 ---- writer.WriteAttributeString( "name", property.Name ); writer.WriteAttributeString( "column", attribute.Column == null ? property.Name : attribute.Column ); ! writer.WriteAttributeString( "access", attribute.Access ); ! string typeName = null; if( attribute.Type != null ) *************** *** 485,488 **** --- 494,498 ---- writer.WriteAttributeString( "column", attribute.Column ); writer.WriteAttributeString( "type", GetShortTypeName( property.PropertyType ) ); + writer.WriteAttributeString( "access", attribute.Access ); writer.WriteEndElement(); //</version> } *************** *** 545,551 **** writer.WriteAttributeString( "table", attribute.Table ); WriteJoinedSubclassKey( writer, type ); ! WriteProperties( writer, type, true ); ! WriteCollections( writer, type, true ); ! WriteAssociations( writer, type, true ); foreach( TypeNode childNode in node.Nodes ) --- 555,561 ---- writer.WriteAttributeString( "table", attribute.Table ); WriteJoinedSubclassKey( writer, type ); ! WriteProperties( writer, type ); ! WriteCollections( writer, type ); ! WriteAssociations( writer, type ); foreach( TypeNode childNode in node.Nodes ) *************** *** 608,618 **** { System.Type type = classType; ! while( ( type == classType ) || ! ( ( type != null ) && ! ( !type.IsDefined( typeof(ClassAttribute), false ) ) && ! ( !type.IsDefined( typeof(SubclassAttribute), false ) ) && ! ( !type.IsDefined( typeof(JoinedSubclassAttribute), false ) ) ) ) { ! PropertyInfo[] properties = type.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); foreach( PropertyInfo property in properties ) { --- 618,624 ---- { System.Type type = classType; ! while( ( type == classType ) || ( type != null ) ) { ! PropertyInfo[] properties = type.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); foreach( PropertyInfo property in properties ) { *************** *** 633,648 **** /// <param name="classType"></param> /// <returns></returns> ! private PropertyInfo[] FindAttributedProperties( System.Type attrType, System.Type classType, bool declaredOnly ) { ArrayList list = new ArrayList(); ! BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; ! /*if( declaredOnly )*/ bindings = bindings | BindingFlags.DeclaredOnly; System.Type type = classType; ! while( ( type == classType ) || ! ( ( type != null ) && ! ( !type.IsDefined( typeof(ClassAttribute), false ) ) && ! ( !type.IsDefined( typeof(SubclassAttribute), false ) ) && ! ( !type.IsDefined( typeof(JoinedSubclassAttribute), false ) ) ) ) { PropertyInfo[] properties = type.GetProperties( bindings ); --- 639,649 ---- /// <param name="classType"></param> /// <returns></returns> ! private PropertyInfo[] FindAttributedProperties( System.Type attrType, System.Type classType ) { ArrayList list = new ArrayList(); ! BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; System.Type type = classType; ! while( ( type == classType ) || ( type != null ) ) { PropertyInfo[] properties = type.GetProperties( bindings ); *************** *** 669,675 **** private string GetShortTypeName( System.Type type ) { ! Match name = m_AssemblyQualifiedNameRegex.Match( type.AssemblyQualifiedName ); ! string typeName = name.Groups["type"].Value; ! string assemblyName = name.Groups["assembly"].Value; if( assemblyName == "mscorlib" && --- 670,675 ---- private string GetShortTypeName( System.Type type ) { ! string typeName = type.FullName; ! string assemblyName = type.Assembly.GetName().Name; if( assemblyName == "mscorlib" && Index: SetAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/SetAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SetAttribute.cs 30 Dec 2004 16:54:02 -0000 1.1 --- SetAttribute.cs 23 Mar 2005 00:39:35 -0000 1.2 *************** *** 16,19 **** --- 16,20 ---- private CascadeType m_Cascade = CascadeType.None; private string m_SqlWhere; + private string m_Access = MapGenerator.DefaultAccessStrategy; #endregion *************** *** 47,51 **** /// <summary> /// Gets and sets the IsLazy. ! /// </summary> public bool IsLazy { --- 48,52 ---- /// <summary> /// Gets and sets the IsLazy. ! /// </summary public bool IsLazy { *************** *** 71,74 **** --- 72,93 ---- set { m_SqlWhere = value; } } + + /// <summary> + /// Gets and sets the Access. + /// </summary> + public string Access + { + get { return m_Access; } + set { m_Access = value; } + } + + /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } } } Index: VersionAttribute.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/NHibernate.Tool.Net2Hbm/VersionAttribute.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VersionAttribute.cs 30 Dec 2004 16:54:02 -0000 1.1 --- VersionAttribute.cs 23 Mar 2005 00:39:35 -0000 1.2 *************** *** 12,16 **** private string m_Column; ! #endregion --- 12,17 ---- private string m_Column; ! private string m_Access = MapGenerator.DefaultAccessStrategy; ! #endregion *************** *** 31,34 **** --- 32,53 ---- set { m_Column = value; } } + + /// <summary> + /// Gets and sets the Access. + /// </summary> + public string Access + { + get { return m_Access; } + set { m_Access = value; } + } + + /// <summary> + /// Get and sets the access type. + /// </summary> + public Type AccessType + { + get { return Type.GetType( m_Access ); } + set { m_Access = String.Format( "{0}, {1}", value.FullName, value.Assembly.GetName().Name ); } + } } } |