You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2006/07/24 20:41:30 UTC

svn commit: r425143 - in /ibatis/trunk/cs/mapper: IBatisNet.Common/IBatisNet.Common.2005.csproj IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs IBatisNet.Common/Utilities/Objects/ObjectFactory.cs IBatisNet.DataMapper/ChangeLog.txt

Author: gbayon
Date: Mon Jul 24 11:41:30 2006
New Revision: 425143

URL: http://svn.apache.org/viewvc?rev=425143&view=rev
Log:
Cosmetic changes

- Updated change log
- Added logging for IFactory

Added:
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs   (with props)
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
    ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj?rev=425143&r1=425142&r2=425143&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj Mon Jul 24 11:41:30 2006
@@ -196,6 +196,7 @@
     <Compile Include="Utilities\Objects\DelegateFactory.cs" />
     <Compile Include="Utilities\Objects\EmitObjectFactory.cs" />
     <Compile Include="Utilities\Objects\FactoryBuilder.cs" />
+    <Compile Include="Utilities\Objects\FactoryLogAdapter.cs" />
     <Compile Include="Utilities\Objects\IFactory.cs" />
     <Compile Include="Utilities\Objects\IObjectFactory.cs" />
     <Compile Include="Utilities\Objects\Members\AccessorFactory.cs" />

Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs?rev=425143&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs Mon Jul 24 11:41:30 2006
@@ -0,0 +1,109 @@
+using System;
+using System.Reflection;
+using System.Text;
+using IBatisNet.Common.Logging;
+
+namespace IBatisNet.Common.Utilities.Objects
+{
+	/// <summary>
+    /// A wrapper arround an <see cref="IFactory"/> implementation which logs argument type and value
+    /// when CreateInstance is called.
+	/// </summary>
+	public class FactoryLogAdapter : IFactory
+	{
+		private IFactory _factory = null;
+		private string _typeName = string.Empty;
+		private string _parametersTypeName = string.Empty;
+		
+		private static readonly ILog _logger = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="FactoryLogAdapter"/> class.
+        /// </summary>
+        /// <param name="type">The type.</param>
+        /// <param name="paramtersTypes">The paramters types.</param>
+        /// <param name="factory">The factory.</param>
+		public FactoryLogAdapter(Type type, Type[] paramtersTypes, IFactory factory)
+		{
+			_factory = factory;
+			_typeName = type.FullName;
+			_parametersTypeName = GenerateParametersName(paramtersTypes);
+		}
+		
+		#region IFactory Members
+
+        /// <summary>
+        /// Create a new instance with the specified parameters
+        /// </summary>
+        /// <param name="parameters">An array of values that matches the number, order and type
+        /// of the parameters for this constructor.</param>
+        /// <returns>A new instance</returns>
+        /// <remarks>
+        /// If you call a constructor with no parameters, pass null.
+        /// Anyway, what you pass will be ignore.
+        /// </remarks>
+		public object CreateInstance(object[] parameters)
+		{
+			object newObject = null;
+
+			try
+			{
+				newObject = _factory.CreateInstance(parameters);
+			}
+			catch
+			{
+				_logger.Debug("Enabled to create instance for type '" + _typeName);
+				_logger.Debug("  using parameters type : " + _parametersTypeName );
+				_logger.Debug("  using parameters value : " + GenerateLogInfoForParameterValue(parameters) );
+				throw;
+			}
+            			
+			return newObject;
+		}
+
+		#endregion
+		
+		/// <summary>
+		/// Generates the a string containing all parameter type names.
+		/// </summary>
+		/// <param name="arguments">The types of the constructor arguments</param>
+		/// <returns>The string.</returns>
+		private string GenerateParametersName(object[] arguments)
+		{
+			StringBuilder names = new StringBuilder();
+			if ((arguments != null) && (arguments.Length != 0)) 
+			{
+				for (int i=0; i<arguments.Length; i++) 
+				{
+					names.Append("[").Append(arguments[i]).Append("] ");
+				}
+			}
+			return names.ToString();
+		}
+		
+		/// <summary>
+		/// Generates the a string containing all parameters value.
+		/// </summary>
+		/// <param name="arguments">The arguments</param>
+		/// <returns>The string.</returns>
+		private string GenerateLogInfoForParameterValue(object[] arguments)
+		{
+			StringBuilder values = new StringBuilder();
+			if ((arguments != null) && (arguments.Length != 0)) 
+			{
+				for (int i=0; i<arguments.Length; i++) 
+				{
+					if (arguments[i]!=null)
+					{
+						values.Append("[").Append(arguments[i].ToString()).Append("] ");
+					}
+					else
+					{
+						values.Append("[null] ");
+					}
+				}
+			}
+			return values.ToString();
+		}
+	}
+}

Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/FactoryLogAdapter.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs?rev=425143&r1=425142&r2=425143&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/ObjectFactory.cs Mon Jul 24 11:41:30 2006
@@ -24,6 +24,8 @@
 #endregion
 
 using System;
+using System.Reflection;
+using IBatisNet.Common.Logging;
 
 namespace IBatisNet.Common.Utilities.Objects
 {
@@ -33,6 +35,7 @@
 	public class ObjectFactory : IObjectFactory
 	{
 		private IObjectFactory _objectFactory = null;
+        private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
 		/// <summary>
 		/// Constructor
@@ -70,7 +73,14 @@
 		/// <returns>Returns a new instance factory</returns>
 		public IFactory CreateFactory(Type typeToCreate, Type[] types)
 		{
-			return _objectFactory.CreateFactory(typeToCreate, types);
+            if (_logger.IsDebugEnabled)
+            {
+                return new FactoryLogAdapter(typeToCreate, types, _objectFactory.CreateFactory(typeToCreate, types));
+            }
+		    else
+            {
+                return _objectFactory.CreateFactory(typeToCreate, types);
+            }
 		}
 
 		#endregion

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt?rev=425143&r1=425142&r2=425143&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/ChangeLog.txt Mon Jul 24 11:41:30 2006
@@ -4,6 +4,9 @@
 1.5.1 - BETA
 ------------------------------
 Issues
+- IBATISNET-175 : Support discriminators when used via the "resultMapping" attribute  
+- IBATISNET-174 : Issue with a result map constructor in a result property  
+- IBATISNET-173 : Issue with constructor tag where an argument use another constructor tag  
 - IBATISNET-172 : Issue with QueryForList with constructor resultMap and select argument  
 - IBATISNET-170 : auto-result-map Bug  
 - IBATISNET-169 : SqlMap.xsd Correction