Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/AutoResultMap.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/AutoResultMap.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/AutoResultMap.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/AutoResultMap.cs Sun Jun 8 11:20:44 2008 @@ -33,7 +33,8 @@ using Apache.Ibatis.Common.Utilities; using Apache.Ibatis.Common.Utilities.Objects; using Apache.Ibatis.DataMapper.DataExchange; -using Apache.Ibatis.DataMapper.TypeHandlers; +using Apache.Ibatis.DataMapper.Model.Events; +using Apache.Ibatis.DataMapper.Model.Events.Listeners; #endregion @@ -65,6 +66,7 @@ /// <param name="resultClass">The result class.</param> /// <param name="resultClassFactory">The result class factory.</param> /// <param name="dataExchange">The data exchange.</param> + /// <param name="isSimpleType">if set to <c>true</c> [is simple type].</param> public AutoResultMap(Type resultClass, IFactory resultClassFactory, IDataExchange dataExchange, bool isSimpleType) { Contract.Require.That(resultClass, Is.Not.Null).When("retrieving argument resultClass in AutoResultMap constructor"); @@ -164,7 +166,14 @@ /// <returns>An object.</returns> public object CreateInstanceOfResult(object[] parameters) { - return CreateInstanceOfResultClass(); + if (!isSimpleType) + { + return resultClassFactory.CreateInstance(null); + } + else + { + return TypeUtils.InstantiatePrimitiveType(resultClass); + } } /// <summary> @@ -188,22 +197,6 @@ } /// <summary> - /// Create an instance of result class. - /// </summary> - /// <returns>An object.</returns> - public object CreateInstanceOfResultClass() - { - if (!isSimpleType) - { - return resultClassFactory.CreateInstance(null); - } - else - { - return TypeUtils.InstantiatePrimitiveType(resultClass); - } - } - - /// <summary> /// The Key (used for resolved circular reference). /// </summary> /// <value></value> @@ -220,6 +213,46 @@ { get { throw new NotImplementedException("The method or operation is not implemented."); } } + + /// <summary> + /// Handles event generated after creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + public IResultMapEventListener<PostCreateEvent>[] PostCreateEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated before creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + public IResultMapEventListener<PreCreateEvent>[] PreCreateEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated before setting the property value in an instance of a <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + public IResultMapEventListener<PrePropertyEvent>[] PrePropertyEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated after setting the property value in an instance of a <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + public IResultMapEventListener<PostPropertyEvent>[] PostPropertyEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } #endregion /// <summary> @@ -230,5 +263,7 @@ { return new AutoResultMap(resultClass, resultClassFactory, dataExchange, isSimpleType); } + + } }
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/IResultMap.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/IResultMap.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/IResultMap.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/IResultMap.cs Sun Jun 8 11:20:44 2008 @@ -29,6 +29,8 @@ using System.Collections.Generic; using System.Data; using Apache.Ibatis.DataMapper.DataExchange; +using Apache.Ibatis.DataMapper.Model.Events; +using Apache.Ibatis.DataMapper.Model.Events.Listeners; #endregion @@ -113,10 +115,22 @@ void SetValueOfProperty(ref object target, ResultProperty property, object dataBaseValue); /// <summary> - /// + /// Resolves the sub map. /// </summary> - /// <param name="dataReader"></param> + /// <param name="dataReader">The data reader.</param> /// <returns></returns> IResultMap ResolveSubMap(IDataReader dataReader); + + /// <summary> + /// Handles event generated before creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + IResultMapEventListener<PreCreateEvent>[] PreCreateEventListeners { get; set;} + + /// <summary> + /// Handles event generated after creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + IResultMapEventListener<PostCreateEvent>[] PostCreateEventListeners { get; set;} } } \ No newline at end of file Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/NullResultMap.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/NullResultMap.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/NullResultMap.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/NullResultMap.cs Sun Jun 8 11:20:44 2008 @@ -26,6 +26,8 @@ using System; using Apache.Ibatis.DataMapper.DataExchange; using System.Collections.Generic; +using Apache.Ibatis.DataMapper.Model.Events; +using Apache.Ibatis.DataMapper.Model.Events.Listeners; namespace Apache.Ibatis.DataMapper.Model.ResultMapping { @@ -191,5 +193,45 @@ { get { return keysProperties; } } + + /// <summary> + /// Handles event generated after creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + public IResultMapEventListener<PostCreateEvent>[] PostCreateEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated before creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + public IResultMapEventListener<PreCreateEvent>[] PreCreateEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated before setting the property value in an instance of a <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + public IResultMapEventListener<PrePropertyEvent>[] PrePropertyEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } + + /// <summary> + /// Handles event generated after setting the property value in an instance of a <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + public IResultMapEventListener<PostPropertyEvent>[] PostPropertyEventListeners + { + get { throw new Exception("The method or operation is not implemented."); } + set { throw new Exception("The method or operation is not implemented."); } + } } } Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultMap.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultMap.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultMap.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultMap.cs Sun Jun 8 11:20:44 2008 @@ -35,6 +35,8 @@ using Apache.Ibatis.Common.Utilities; using Apache.Ibatis.Common.Utilities.Objects; using Apache.Ibatis.DataMapper.DataExchange; +using Apache.Ibatis.DataMapper.Model.Events; +using Apache.Ibatis.DataMapper.Model.Events.Listeners; using Apache.Ibatis.DataMapper.TypeHandlers; #endregion @@ -82,6 +84,11 @@ [NonSerialized] private readonly ResultPropertyCollection keysProperties = new ResultPropertyCollection(); + [NonSerialized] + private IResultMapEventListener<PostCreateEvent>[] postCreateEventListeners = new IResultMapEventListener<PostCreateEvent>[] { }; + [NonSerialized] + private IResultMapEventListener<PreCreateEvent>[] preCreateEventListeners = new IResultMapEventListener<PreCreateEvent>[] { }; + #endregion #region Properties @@ -181,8 +188,6 @@ } #endregion - #region Constructor (s) / Destructor - /// <summary> /// Initializes a new instance of the <see cref="ResultMap"/> class. /// </summary> @@ -249,7 +254,7 @@ for (int i = 0; i < columns.Length; i++) { string column = columns[i].Trim(); - this.keyPropertyNames.Add(column); + keyPropertyNames.Add(column); } InitializeKeysProperties(); @@ -257,101 +262,8 @@ } } - #endregion - - #region Methods - - /// <summary> - /// Checks the key Column. - /// </summary> - private void CheckKeysProperties() - { - try - { - // Verify that that each key column element correspond to a class member - // of one of result property - for (int i = 0; i < keyPropertyNames.Count; i++) - { - string memberName = keyPropertyNames[i]; - if (!properties.Contains(memberName)) - { - if (!parameters.Contains(memberName)) - { - throw new ConfigurationException( - string.Format( - "Could not configure ResultMap named \"{0}\". Check the keyPropertyNames attribute. Cause: there's no result property or parameter constructor named \"{1}\".", - id, memberName)); - - } - } - } - } - catch (Exception e) - { - throw new ConfigurationException( - string.Format("Could not configure ResultMap named \"{0}\", Cause: {1}", id, e.Message) - , e); - } - } - - /// <summary> - /// Initializes the key Column properties. - /// </summary> - private void InitializeKeysProperties() - { - for (int i = 0; i < keyPropertyNames.Count; i++) - { - ResultProperty resultProperty = properties.FindByPropertyName(keyPropertyNames[i]); - if (resultProperty == null) - { - resultProperty = parameters.FindByPropertyName(keyPropertyNames[i]); - } - - KeysProperties.Add(resultProperty); - } - } - - /// <summary> - /// Checks the group by. - /// </summary> - private void CheckGroupBy() - { - try - { - // Verify that that each groupBy element correspond to a class member - // of one of result property - for (int i = 0; i < groupByProperties.Count; i++) - { - string memberName = GroupByPropertyNames[i]; - if (!properties.Contains(memberName)) - { - throw new ConfigurationException( - string.Format( - "Could not configure ResultMap named \"{0}\". Check the groupBy attribute. Cause: there's no result property named \"{1}\".", - id, memberName)); - } - } - } - catch (Exception e) - { - throw new ConfigurationException( - string.Format("Could not configure ResultMap named \"{0}\", Cause: {1}", id, e.Message) - , e); - } - } - - /// <summary> - /// Initializes the groupBy properties. - /// </summary> - private void InitializeGroupByProperties() - { - for (int i = 0; i < GroupByPropertyNames.Count; i++) - { - ResultProperty resultProperty = Properties.FindByPropertyName(this.GroupByPropertyNames[i]); - this.GroupByProperties.Add(resultProperty); - } - } + #region IResultMap Members /// <summary> /// Create an instance Of result. @@ -363,7 +275,32 @@ { if (!isSimpleType) { - return objectFactory.CreateInstance(parameters); + if (preCreateEventListeners.Length > 0) + { + PreCreateEvent evnt = new PreCreateEvent(); + evnt.ResultMap = this; + evnt.Parameters = parameters; + foreach (IResultMapEventListener<PreCreateEvent> listener in preCreateEventListeners) + { + evnt.Parameters = (object[])listener.OnEvent(evnt); + } + parameters = evnt.Parameters; + } + + object instance = objectFactory.CreateInstance(parameters); + + if (postCreateEventListeners.Length > 0) + { + PostCreateEvent evnt = new PostCreateEvent(); + evnt.ResultMap = this; + evnt.Instance = instance; + foreach (IResultMapEventListener<PostCreateEvent> listener in postCreateEventListeners) + { + evnt.Instance = listener.OnEvent(evnt); + } + instance = evnt.Instance; + } + return instance; } else { @@ -434,8 +371,120 @@ public ResultPropertyCollection KeysProperties { get { return keysProperties; } + } + + /// <summary> + /// Handles event generated after creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The post create events.</value> + public IResultMapEventListener<PostCreateEvent>[] PostCreateEventListeners + { + get { return postCreateEventListeners; } + set { postCreateEventListeners = value; } + } + + /// <summary> + /// Handles event generated before creating an instance of the <see cref="IResultMap"/> object. + /// </summary> + /// <value>The pre create events.</value> + public IResultMapEventListener<PreCreateEvent>[] PreCreateEventListeners + { + get { return preCreateEventListeners; } + set { preCreateEventListeners = value; } } #endregion + + + /// <summary> + /// Initializes the key Column properties. + /// </summary> + private void InitializeKeysProperties() + { + for (int i = 0; i < keyPropertyNames.Count; i++) + { + ResultProperty resultProperty = properties.FindByPropertyName(keyPropertyNames[i]); + if (resultProperty == null) + { + resultProperty = parameters.FindByPropertyName(keyPropertyNames[i]); + } + + KeysProperties.Add(resultProperty); + } + } + + /// <summary> + /// Checks the group by. + /// </summary> + private void CheckGroupBy() + { + try + { + // Verify that that each groupBy element correspond to a class member + // of one of result property + for (int i = 0; i < groupByProperties.Count; i++) + { + string memberName = GroupByPropertyNames[i]; + if (!properties.Contains(memberName)) + { + throw new ConfigurationException( + string.Format( + "Could not configure ResultMap named \"{0}\". Check the groupBy attribute. Cause: there's no result property named \"{1}\".", + id, memberName)); + } + } + } + catch (Exception e) + { + throw new ConfigurationException( + string.Format("Could not configure ResultMap named \"{0}\", Cause: {1}", id, e.Message) + , e); + } + } + + /// <summary> + /// Initializes the groupBy properties. + /// </summary> + private void InitializeGroupByProperties() + { + for (int i = 0; i < GroupByPropertyNames.Count; i++) + { + ResultProperty resultProperty = Properties.FindByPropertyName(GroupByPropertyNames[i]); + GroupByProperties.Add(resultProperty); + } + } + + /// <summary> + /// Checks the key Column. + /// </summary> + private void CheckKeysProperties() + { + try + { + // Verify that that each key column element correspond to a class member + // of one of result property + for (int i = 0; i < keyPropertyNames.Count; i++) + { + string memberName = keyPropertyNames[i]; + if (!properties.Contains(memberName)) + { + if (!parameters.Contains(memberName)) + { + throw new ConfigurationException( + string.Format( + "Could not configure ResultMap named \"{0}\". Check the keyPropertyNames attribute. Cause: there's no result property or parameter constructor named \"{1}\".", + id, memberName)); + + } + } + } + } + catch (Exception e) + { + throw new ConfigurationException( + string.Format("Could not configure ResultMap named \"{0}\", Cause: {1}", id, e.Message) + , e); + } + } } } Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ResultMapping/ResultProperty.cs Sun Jun 8 11:20:44 2008 @@ -42,7 +42,10 @@ using Apache.Ibatis.DataMapper.Exceptions; using Apache.Ibatis.DataMapper.MappedStatements.ArgumentStrategy; using Apache.Ibatis.DataMapper.MappedStatements.PropertyStrategy; +using Apache.Ibatis.DataMapper.Model.Events; +using Apache.Ibatis.DataMapper.Model.Events.Listeners; using Apache.Ibatis.DataMapper.Proxy; +using Apache.Ibatis.DataMapper.Scope; using Apache.Ibatis.DataMapper.TypeHandlers; #endregion @@ -102,12 +105,37 @@ private readonly IFactory listFactory = null; [NonSerialized] private static readonly IFactory arrayListFactory = new ArrayListFactory(); - + + [NonSerialized] + private IResultPropertyEventListener<PrePropertyEvent>[] prePropertyEventListeners = new IResultPropertyEventListener<PrePropertyEvent>[] { }; + [NonSerialized] + private IResultPropertyEventListener<PostPropertyEvent>[] postPropertyEventListeners = new IResultPropertyEventListener<PostPropertyEvent>[] { }; + #endregion #region Properties /// <summary> + /// Handles event generated before setting the property value of a <see cref="ResultProperty"/>. + /// </summary> + /// <value>The post create events.</value> + public IResultPropertyEventListener<PrePropertyEvent>[] PrePropertyEventListeners + { + get { return prePropertyEventListeners; } + set { prePropertyEventListeners = value; } + } + + /// <summary> + /// Handles event generated after setting the property value of a <see cref="ResultProperty"/>. + /// </summary> + /// <value>The pre create events.</value> + public IResultPropertyEventListener<PostPropertyEvent>[] PostPropertyEventListeners + { + get { return postPropertyEventListeners; } + set { postPropertyEventListeners = value; } + } + + /// <summary> /// Tell us if the member type implement generic Ilist interface. /// </summary> public bool IsGenericIList @@ -242,13 +270,13 @@ get { return propertyName; } } - /// <summary> + /// <summary> /// Defines a field/property <see cref="ISetAccessor"/> - /// </summary> - public ISetAccessor SetAccessor - { - get { return setAccessor; } - } + /// </summary> + public ISetAccessor SetAccessor + { + get {return setAccessor;} + } /// <summary> /// Get the field/property type @@ -511,11 +539,57 @@ #region Methods - /// <summary> - /// - /// </summary> - /// <param name="dataReader"></param> - /// <returns></returns> + /// <summary> + /// Sets the value for the field/property . + /// </summary> + /// <param name="target">Object to set the field/property on.</param> + /// <param name="value">Value.</param> + public void Set(object target, object value) + { + if (prePropertyEventListeners.Length > 0) + { + PrePropertyEvent evnt = new PrePropertyEvent(); + evnt.ResultProperty = this; + evnt.DataBaseValue = value; + evnt.Target = target; + foreach (IResultPropertyEventListener<PrePropertyEvent> listener in prePropertyEventListeners) + { + evnt.DataBaseValue = listener.OnEvent(evnt); + } + value = evnt.DataBaseValue; + } + + setAccessor.Set(target, value); + + if (postPropertyEventListeners.Length > 0) + { + PostPropertyEvent evnt = new PostPropertyEvent(); + evnt.ResultProperty = this; + evnt.Target = target; + foreach (IResultPropertyEventListener<PostPropertyEvent> listener in postPropertyEventListeners) + { + listener.OnEvent(evnt); + } + } + } + + /// <summary> + /// Gets a result argument value. + /// </summary> + /// <param name="request">The request.</param> + /// <param name="reader">The reader.</param> + /// <param name="keys">The keys.</param> + /// <returns></returns> + public object GetValue(RequestScope request, ref IDataReader reader, object keys) + { + return ArgumentStrategy.GetValue(request, this, ref reader, keys); + } + + /// <summary> + /// Gets the data base value. + /// </summary> + /// <param name="dataReader">The data reader.</param> + /// <returns></returns> public object GetDataBaseValue(IDataReader dataReader) { object value = null; @@ -552,11 +626,11 @@ return value; } - /// <summary> - /// - /// </summary> - /// <param name="value"></param> - /// <returns></returns> + /// <summary> + /// Translates the value tu null value if need + /// </summary> + /// <param name="value">The value.</param> + /// <returns></returns> public object TranslateValue(object value) { if (value == null) Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Scope/RequestScope.cs URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Scope/RequestScope.cs?rev=664536&r1=664535&r2=664536&view=diff ============================================================================== --- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Scope/RequestScope.cs (original) +++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Scope/RequestScope.cs Sun Jun 8 11:20:44 2008 @@ -185,7 +185,7 @@ /// <summary> /// The 'select' result property to process after having process the main properties. /// </summary> - public Queue<PostBindind> DeferredLoad + public Queue<PostBindind> DelayedLoad { get { return selects; } set { selects = value; }
