From: <fab...@us...> - 2009-12-01 15:44:23
|
Revision: 4882 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4882&view=rev Author: fabiomaulo Date: 2009-12-01 15:44:13 +0000 (Tue, 01 Dec 2009) Log Message: ----------- binders refactoring -removed duplicated code Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmTimestamp.cs trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs Modified: trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmTimestamp.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmTimestamp.cs 2009-12-01 14:26:29 UTC (rev 4881) +++ trunk/nhibernate/src/NHibernate/Cfg/MappingSchema/HbmTimestamp.cs 2009-12-01 15:44:13 UTC (rev 4882) @@ -1,10 +1,35 @@ +using System; +using System.Collections.Generic; + namespace NHibernate.Cfg.MappingSchema { - partial class HbmTimestamp : AbstractDecoratable + partial class HbmTimestamp : AbstractDecoratable, IColumnsMapping { protected override HbmMeta[] Metadatas { get { return meta ?? new HbmMeta[0]; } } + + #region Implementation of IColumnsMapping + + public IEnumerable<HbmColumn> Columns + { + get + { + if (string.IsNullOrEmpty(column)) + { + yield break; + } + else + { + yield return new HbmColumn + { + name = column, + }; + } + } + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-01 14:26:29 UTC (rev 4881) +++ trunk/nhibernate/src/NHibernate/Cfg/XmlHbmBinding/RootClassBinder.cs 2009-12-01 15:44:13 UTC (rev 4882) @@ -16,7 +16,7 @@ public void Bind(HbmClass classSchema, IDictionary<string, MetaAttribute> inheritedMetas) { - RootClass rootClass = new RootClass(); + var rootClass = new RootClass(); BindClass(classSchema, rootClass, inheritedMetas); // OPTIMISTIC LOCK MODE rootClass.OptimisticLockMode = classSchema.optimisticlock.ToOptimisticLock(); @@ -104,10 +104,12 @@ return; string propertyName = timestampSchema.name; - SimpleValue simpleValue = new SimpleValue(table); + var simpleValue = new SimpleValue(table); + new ColumnsBinder(simpleValue, Mappings).Bind(timestampSchema.Columns, false, + () => + new HbmColumn + {name = mappings.NamingStrategy.PropertyToColumnName(propertyName)}); - BindColumns(timestampSchema, simpleValue, propertyName); - if (!simpleValue.IsTypeSpecified) { switch (timestampSchema.source) @@ -138,42 +140,6 @@ rootClass.AddProperty(property); } - private void BindColumns(HbmTimestamp timestampSchema, SimpleValue model, string propertyPath) - { - Table table = model.Table; - - if (timestampSchema.column != null) - { - Column col = new Column(); - col.Value = model; - BindColumn(col, false); - col.Name = mappings.NamingStrategy.ColumnName(timestampSchema.column); - - if (table != null) - table.AddColumn(col); - - model.AddColumn(col); - } - - if (model.ColumnSpan == 0) - { - Column col = new Column(); - col.Value = model; - BindColumn(col, false); - col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath); - model.Table.AddColumn(col); - model.AddColumn(col); - } - } - - private static void BindColumn(Column column, bool isNullable) - { - column.IsNullable = isNullable; - column.IsUnique = false; - column.CheckConstraint = string.Empty; - column.SqlType = null; - } - private void BindProperty(HbmTimestamp timestampSchema, Property property, IDictionary<string, MetaAttribute> inheritedMetas) { property.Name = timestampSchema.name; @@ -230,9 +196,13 @@ return; string propertyName = versionSchema.name; - SimpleValue simpleValue = new SimpleValue(table); + var simpleValue = new SimpleValue(table); BindVersionType(versionSchema.type, simpleValue); - BindColumns(versionSchema, simpleValue, false, propertyName); + new ColumnsBinder(simpleValue, Mappings).Bind(versionSchema.Columns, false, + () => + new HbmColumn + {name = mappings.NamingStrategy.PropertyToColumnName(propertyName)}); + if (!simpleValue.IsTypeSpecified) simpleValue.TypeName = NHibernateUtil.Int32.Name; @@ -258,43 +228,6 @@ BindTypeDef(versionTypeName, versionTypeName, new Dictionary<string, string>(), simpleValue); } - private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath) - { - Table table = model.Table; - if (versionSchema.column1 != null) - { - var col = new Column {Value = model}; - BindColumn(col, isNullable); - col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column1); - - if (table != null) - table.AddColumn(col); - - model.AddColumn(col); - } - else if (versionSchema.column != null) - { - foreach (HbmColumn hbmColumn in versionSchema.column) - { - var col = new Column {Value = model}; - BindColumn(hbmColumn, col, isNullable); - if (table != null) - table.AddColumn(col); - - model.AddColumn(col); - } - } - - if (model.ColumnSpan == 0) - { - var col = new Column {Value = model}; - BindColumn(col, isNullable); - col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath); - model.Table.AddColumn(col); - model.AddColumn(col); - } - } - private void BindProperty(HbmVersion versionSchema, Property property, IDictionary<string, MetaAttribute> inheritedMetas) { property.Name = versionSchema.name; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |