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/03/13 21:09:19 UTC

svn commit: r385645 - in /ibatis/trunk/cs/mapper/IBatisNet.DataMapper: Configuration/DomSqlMapBuilder.cs Configuration/ResultMapping/ResultMap.cs Configuration/Statements/Statement.cs Scope/ConfigurationScope.cs SqlMapper.cs

Author: gbayon
Date: Mon Mar 13 12:09:18 2006
New Revision: 385645

URL: http://svn.apache.org/viewcvs?rev=385645&view=rev
Log:
- Begin to use ObjectFactory

Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?rev=385645&r1=385644&r2=385645&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Mon Mar 13 12:09:18 2006
@@ -2,7 +2,7 @@
 #region Apache Notice
 /*****************************************************************************
  * $Header: $
- * $Revision: $
+ * $Revision$
  * $Date$
  * 
  * iBATIS.NET Data Mapper
@@ -39,6 +39,7 @@
 using IBatisNet.Common.Exceptions;
 using IBatisNet.Common.Logging;
 using IBatisNet.Common.Utilities;
+using IBatisNet.Common.Utilities.Objects;
 using IBatisNet.Common.Xml;
 using IBatisNet.DataMapper.Configuration.Alias;
 using IBatisNet.DataMapper.Configuration.Cache;
@@ -648,8 +649,10 @@
 		private void Initialize()
 		{
 			Reset();
-			
-			_configScope.SqlMapper = new SqlMapper( new TypeHandlerFactory() );
+
+            // To do, analyse config file to set allowCodeGeneration on object factory
+			_configScope.SqlMapper = new SqlMapper( new ObjectFactory(false), new TypeHandlerFactory() );
+
 
 			#region Cache Alias
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs?rev=385645&r1=385644&r2=385645&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultMap.cs Mon Mar 13 12:09:18 2006
@@ -1,12 +1,12 @@
 
 #region Apache Notice
 /*****************************************************************************
- * $Header: $
- * $Revision: $
- * $Date$
+ * $Revision$
+ * $LastChangedDate$
+ * $LastChangedBy$
  * 
  * iBATIS.NET Data Mapper
- * Copyright (C) 2004 - Gilles Bayon
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
  *  
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
  ********************************************************************************/
 #endregion
 
-#region Imports
+#region Using
 
 using System;
 using System.Collections;
@@ -63,6 +63,8 @@
 		/// </summary>
 		private const string XML_SUBMAP = "subMap";
 
+        private IFactory _objectFactory = null;
+
 		#region Fields
 		[NonSerialized]
 		private string _id = string.Empty;
@@ -200,6 +202,10 @@
 			try
 			{
 				_class = configScope.SqlMapper.TypeHandlerFactory.GetType(_className);
+				if (Type.GetTypeCode(_class) == TypeCode.Object)
+				{
+					_objectFactory = configScope.SqlMapper.ObjectFactory.CreateFactory(_class);
+				}
 
 				// Load the child node
 				GetChildNode(configScope);
@@ -278,7 +284,7 @@
 
 			if (typeCode == TypeCode.Object)
 			{
-				return Activator.CreateInstance(_class);
+                return _objectFactory.CreateInstance();
 			}
 			else
 			{

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs?rev=385645&r1=385644&r2=385645&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Statements/Statement.cs Mon Mar 13 12:09:18 2006
@@ -1,12 +1,12 @@
 
 #region Apache Notice
 /*****************************************************************************
- * $Header: $
- * $Revision: $
- * $Date$
+ * $Revision$
+ * $LastChangedDate$
+ * $LastChangedBy$
  * 
  * iBATIS.NET Data Mapper
- * Copyright (C) 2004 - Gilles Bayon
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
  *  
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,6 +31,7 @@
 using System.Data;
 using System.Xml.Serialization;
 using IBatisNet.Common.Utilities.TypesResolver;
+using IBatisNet.Common.Utilities.Objects;
 using IBatisNet.DataMapper.Configuration.Cache;
 using IBatisNet.DataMapper.Configuration.ParameterMapping;
 using IBatisNet.DataMapper.Configuration.ResultMapping;
@@ -90,6 +91,10 @@
 		private ISql _sql = null;
 		[NonSerialized]
 		private string _extendStatement = string.Empty;
+        [NonSerialized]
+        private IFactory _resultClassFactory = null;
+        private IFactory _listClassFactory = null;
+
 		#endregion
 
 		#region Properties
@@ -311,6 +316,11 @@
 			if (_resultClassName != string.Empty )
 			{
 				_resultClass = configurationScope.SqlMapper.TypeHandlerFactory.GetType(_resultClassName);
+				if (Type.GetTypeCode(_resultClass) == TypeCode.Object &&
+					(_resultClass.IsValueType == false))
+				{
+					_resultClassFactory = configurationScope.SqlMapper.ObjectFactory.CreateFactory(_resultClass);	
+				}
 			}
 			if (_parameterClassName != string.Empty )
 			{
@@ -319,6 +329,7 @@
 			if (_listClassName != string.Empty )
 			{
 				_listClass = configurationScope.SqlMapper.TypeHandlerFactory.GetType(_listClassName);
+                _listClassFactory = configurationScope.SqlMapper.ObjectFactory.CreateFactory(_listClass);
 			}
 		}
 
@@ -329,14 +340,22 @@
 		/// <returns>An object.</returns>
 		public object CreateInstanceOfResultClass()
 		{
-			if (_resultClass.IsPrimitive || _resultClass == typeof (string) )
+			if (_resultClass.IsPrimitive || _resultClass == typeof (string))
 			{
 				TypeCode typeCode = Type.GetTypeCode(_resultClass);
 				return TypeAliasResolver.InstantiatePrimitiveType(typeCode);
 			}
 			else
 			{
-				if (_resultClass == typeof (Guid))
+				if (_resultClass == typeof (DateTime))
+				{
+					return new DateTime();
+				}
+				else if (_resultClass == typeof (Decimal))				
+				{
+					return new Decimal();
+				}
+				else if (_resultClass == typeof (Guid))				
 				{
 					return Guid.Empty;
 				}
@@ -346,7 +365,7 @@
 				}
 				else
 				{
-					return Activator.CreateInstance(_resultClass);
+					return _resultClassFactory.CreateInstance();
 				}
 			}
 		}
@@ -358,7 +377,7 @@
 		/// <returns>An object which implment IList.</returns>
 		public IList CreateInstanceOfListClass()
 		{
-			return (IList)Activator.CreateInstance(_listClass);
+            return (IList)_listClassFactory.CreateInstance(); ;
 		}
 		#endregion
 

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs?rev=385645&r1=385644&r2=385645&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs Mon Mar 13 12:09:18 2006
@@ -2,7 +2,7 @@
 #region Apache Notice
 /*****************************************************************************
  * $Header: $
- * $Revision: $
+ * $Revision$
  * $Date$
  * 
  * iBATIS.NET Data Mapper
@@ -86,6 +86,14 @@
 		#endregion 
 
 		#region Properties
+
+        /// <summary>
+        /// The factory for object
+        /// </summary>
+        public IObjectFactory ObjectFactory
+        {
+            get { return _sqlMapper.ObjectFactory; }
+        }
 
 		/// <summary>
 		/// XmlNamespaceManager

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs?rev=385645&r1=385644&r2=385645&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs Mon Mar 13 12:09:18 2006
@@ -2,7 +2,7 @@
 #region Apache Notice
 /*****************************************************************************
  * $Header: $
- * $Revision: $
+ * $Revision$
  * $Date$
  * 
  * iBATIS.NET Data Mapper
@@ -37,6 +37,7 @@
 using System.Xml;
 using IBatisNet.Common;
 using IBatisNet.Common.Utilities;
+using IBatisNet.Common.Utilities.Objects;
 using IBatisNet.DataMapper.Configuration;
 using IBatisNet.DataMapper.Configuration.Cache;
 using IBatisNet.DataMapper.Configuration.ParameterMapping;
@@ -103,6 +104,7 @@
 		/// Container session unique for each thread. 
 		/// </summary>
 		private SessionHolder _sessionHolder = null;
+        private IObjectFactory _objectFactory = null;
 
 		#endregion
 
@@ -152,14 +154,23 @@
 		{
 			get { return _typeHandlerFactory; }
 		}
+
+        /// <summary>
+        /// The factory for object
+        /// </summary>
+        public IObjectFactory ObjectFactory
+        {
+            get { return _objectFactory; }
+        }
 		#endregion
 
 		#region Constructor (s) / Destructor
 		/// <summary>
 		/// Create a new SqlMap
 		/// </summary>
-		internal SqlMapper(TypeHandlerFactory typeHandlerFactory) 
+		internal SqlMapper(IObjectFactory objectFactory, TypeHandlerFactory typeHandlerFactory) 
 		{
+            _objectFactory = objectFactory;
 			_typeHandlerFactory = typeHandlerFactory;
 			_id = HashCodeProvider.GetIdentityHashCode(this).ToString();
 			_sessionHolder = new SessionHolder(_id);