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 2005/07/23 12:48:36 UTC

svn commit: r224454 - in /ibatis/trunk/cs/mapper/IBatisNet.DataAccess: Configuration/DaoSessionHandler.cs Configuration/DomDaoManagerBuilder.cs DaoSessionHandlers/DaoSessionHandlerFactory.cs IBatisNet.DataAccess.csproj Scope/ConfigurationScope.cs

Author: gbayon
Date: Sat Jul 23 03:48:24 2005
New Revision: 224454

URL: http://svn.apache.org/viewcvs?rev=224454&view=rev
Log:
- Verify IBATISNET-94 +  fixed incorrect initialisation of SessionHandler on the DaoManager

Removed:
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/DaoSessionHandlers/DaoSessionHandlerFactory.cs
Modified:
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DaoSessionHandler.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DomDaoManagerBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj
    ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Scope/ConfigurationScope.cs

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DaoSessionHandler.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DaoSessionHandler.cs?rev=224454&r1=224453&r2=224454&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DaoSessionHandler.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DaoSessionHandler.cs Sat Jul 23 03:48:24 2005
@@ -25,16 +25,11 @@
 #endregion
 
 #region Imports
+
 using System;
 using System.Xml.Serialization;
-using System.Reflection;
-
-using IBatisNet.Common;
-using IBatisNet.Common.Exceptions;    
 using IBatisNet.Common.Utilities;
 
-using IBatisNet.DataAccess.Interfaces;
-using IBatisNet.DataAccess.Exceptions;
 #endregion
 
 namespace IBatisNet.DataAccess.Configuration
@@ -46,13 +41,6 @@
 	[XmlRoot("handler", Namespace="http://ibatis.apache.org/dataAccess")]
 	public class DaoSessionHandler
 	{
-		#region Constants
-		/// <summary>
-		/// An empty object array.
-		/// </summary>
-		public static readonly object [] EmptyObjects = new object [] {};
-		#endregion
-
 		#region Fields
 		[NonSerialized]
 		private string _name = string.Empty;
@@ -92,6 +80,13 @@
 			}
 		}
 
+		/// <summary>
+		/// The impelmenattion type
+		/// </summary>
+		public Type TypeInstance
+		{
+			get { return Resources.TypeForName(_implementation); }
+		}
 
 		/// <summary>
 		/// 
@@ -134,31 +129,6 @@
 			_name = name;
 		}
 		#endregion
-
-		#region Methods
-		/// <summary>
-		/// Build an implementation of the IDaoSessionHandler
-		/// </summary>
-		/// <returns>An implementation</returns>
-		public IDaoSessionHandler GetIDaoSessionHandler()
-		{
-			Type type = null;
-			
-			try
-			{
-				type = Resources.TypeForName(_implementation);
-
-				return (IDaoSessionHandler)Activator.CreateInstance(type, EmptyObjects);
-			}
-			catch(Exception e)
-			{
-				throw new ConfigurationException(
-					string.Format("DaoManager could not configure DaoSessionHandler. DaoSessionHandler named \"{0}\", failed. Cause: {1}", _name, e.Message),e
-					);
-			}
-		}
-		#endregion
-
 
 	}
 }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DomDaoManagerBuilder.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DomDaoManagerBuilder.cs?rev=224454&r1=224453&r2=224454&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DomDaoManagerBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Configuration/DomDaoManagerBuilder.cs Sat Jul 23 03:48:24 2005
@@ -58,8 +58,11 @@
 		private const string PROVIDER_XML_NAMESPACE = "http://ibatis.apache.org/providers";
 		private const string DAO_XML_NAMESPACE = "http://ibatis.apache.org/dataAccess";
 
-		private const string PROPERTY_ELEMENT_KEY_ATTRIB = "key";
-		private const string PROPERTY_ELEMENT_VALUE_ATTRIB = "value";
+		private const string KEY_ATTRIBUTE = "key";
+		private const string VALUE_ATTRIBUTE = "value";
+		private const string ID_ATTRIBUTE = "id";
+
+		private readonly object [] EmptyObjects = new object [] {};
 
 		/// <summary>
 		/// Key for default config name
@@ -445,13 +448,13 @@
 					configurationScope.ErrorContext.ObjectId = daoSessionHandler.Name;
 					configurationScope.ErrorContext.MoreInfo = "build daoSession handler";
 
-					IDaoSessionHandler sessionHandler = daoSessionHandler.GetIDaoSessionHandler();
+					//IDaoSessionHandler sessionHandler = daoSessionHandler.GetIDaoSessionHandler();
 
-					configurationScope.DaoSectionHandlers[daoSessionHandler.Name] = sessionHandler;
+					configurationScope.DaoSectionHandlers[daoSessionHandler.Name] = daoSessionHandler.TypeInstance;
 
 					if (daoSessionHandler.IsDefault == true)
 					{
-						configurationScope.DaoSectionHandlers[DEFAULT_DAOSESSIONHANDLER_NAME] = sessionHandler;
+						configurationScope.DaoSectionHandlers[DEFAULT_DAOSESSIONHANDLER_NAME] = daoSessionHandler.TypeInstance;
 					}
 				}
 			}
@@ -538,12 +541,13 @@
 				resources.Add( "UseConfigFileWatcher", configurationScope.UseConfigFileWatcher);
 
 				IDaoSessionHandler sessionHandler = null;
+				Type typeSessionHandler = null;
 
 				if (nodeSessionHandler!= null)
 				{
 					configurationScope.ErrorContext.Resource = nodeSessionHandler.InnerXml.ToString();
 					
-					sessionHandler = (IDaoSessionHandler)configurationScope.DaoSectionHandlers[nodeSessionHandler.Attributes["id"].Value];
+					typeSessionHandler = configurationScope.DaoSectionHandlers[nodeSessionHandler.Attributes[ID_ATTRIBUTE].Value] as Type;
 
 					// Parse property node
 					foreach(XmlNode nodeProperty in nodeSessionHandler.SelectNodes( ApplyNamespacePrefix(XML_PROPERTY), configurationScope.XmlNamespaceManager ))
@@ -554,12 +558,23 @@
 				}
 				else
 				{
-					sessionHandler = (IDaoSessionHandler)configurationScope.DaoSectionHandlers[DEFAULT_DAOSESSIONHANDLER_NAME];
+					typeSessionHandler = configurationScope.DaoSectionHandlers[DEFAULT_DAOSESSIONHANDLER_NAME] as Type;
 				}
 
 				// Configure the sessionHandler
 				configurationScope.ErrorContext.ObjectId = sessionHandler.GetType().FullName;
 
+				try
+				{
+					sessionHandler =(IDaoSessionHandler)Activator.CreateInstance(typeSessionHandler, EmptyObjects);
+				}
+				catch(Exception e)
+				{
+					throw new ConfigurationException(
+						string.Format("DaoManager could not configure DaoSessionHandler. DaoSessionHandler of type \"{0}\", failed. Cause: {1}", typeSessionHandler.Name, e.Message),e
+						);
+				}
+
 				sessionHandler.Configure(configurationScope.Properties,  resources );
 
 				daoManager.DaoSessionHandler = sessionHandler;
@@ -605,8 +620,8 @@
 				{
 					foreach (XmlNode propertyNode in nodeProperties.SelectNodes(ApplyNamespacePrefix(XML_PROPERTY), configurationScope.XmlNamespaceManager))
 					{
-						XmlAttribute keyAttrib = propertyNode.Attributes[PROPERTY_ELEMENT_KEY_ATTRIB];
-						XmlAttribute valueAttrib = propertyNode.Attributes[PROPERTY_ELEMENT_VALUE_ATTRIB];
+						XmlAttribute keyAttrib = propertyNode.Attributes[KEY_ATTRIBUTE];
+						XmlAttribute valueAttrib = propertyNode.Attributes[VALUE_ATTRIBUTE];
 
 						if ( keyAttrib != null && valueAttrib!=null)
 						{
@@ -620,8 +635,8 @@
 							
 							foreach (XmlNode node in propertiesConfig.SelectNodes(XML_SETTINGS_ADD))
 							{
-								configurationScope.Properties[node.Attributes[PROPERTY_ELEMENT_KEY_ATTRIB].Value] = node.Attributes[PROPERTY_ELEMENT_VALUE_ATTRIB].Value;
-								_logger.Info( string.Format("Add property \"{0}\" value \"{1}\"",node.Attributes[PROPERTY_ELEMENT_KEY_ATTRIB].Value,node.Attributes[PROPERTY_ELEMENT_VALUE_ATTRIB].Value) );
+								configurationScope.Properties[node.Attributes[KEY_ATTRIBUTE].Value] = node.Attributes[VALUE_ATTRIBUTE].Value;
+								_logger.Info( string.Format("Add property \"{0}\" value \"{1}\"",node.Attributes[KEY_ATTRIBUTE].Value,node.Attributes[VALUE_ATTRIBUTE].Value) );
 							}
 						}
 					}
@@ -639,8 +654,8 @@
 
 					foreach (XmlNode node in propertiesConfig.SelectNodes(XML_SETTINGS_ADD))
 					{
-						configurationScope.Properties[node.Attributes[PROPERTY_ELEMENT_KEY_ATTRIB].Value] = node.Attributes[PROPERTY_ELEMENT_VALUE_ATTRIB].Value;
-						_logger.Info( string.Format("Add property \"{0}\" value \"{1}\"",node.Attributes[PROPERTY_ELEMENT_KEY_ATTRIB].Value,node.Attributes[PROPERTY_ELEMENT_VALUE_ATTRIB].Value) );
+						configurationScope.Properties[node.Attributes[KEY_ATTRIBUTE].Value] = node.Attributes[VALUE_ATTRIBUTE].Value;
+						_logger.Info( string.Format("Add property \"{0}\" value \"{1}\"",node.Attributes[KEY_ATTRIBUTE].Value,node.Attributes[VALUE_ATTRIBUTE].Value) );
 					}					
 				}
 //				// Load the file defined by the resource attribut

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj?rev=224454&r1=224453&r2=224454&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj Sat Jul 23 03:48:24 2005
@@ -173,11 +173,6 @@
                     BuildAction = "Compile"
                 />
                 <File
-                    RelPath = "DaoSessionHandlers\DaoSessionHandlerFactory.cs"
-                    SubType = "Code"
-                    BuildAction = "Compile"
-                />
-                <File
                     RelPath = "DaoSessionHandlers\SimpleDaoSession.cs"
                     SubType = "Code"
                     BuildAction = "Compile"

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Scope/ConfigurationScope.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Scope/ConfigurationScope.cs?rev=224454&r1=224453&r2=224454&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Scope/ConfigurationScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataAccess/Scope/ConfigurationScope.cs Sat Jul 23 03:48:24 2005
@@ -25,14 +25,12 @@
 #endregion
 
 #region Using
-using System;
-using System.Data;
-using System.Collections;
+
 using System.Collections.Specialized;
 using System.Xml;
-
-using IBatisNet.DataAccess.DaoSessionHandlers;
 using IBatisNet.DataAccess.Configuration;
+using IBatisNet.DataAccess.DaoSessionHandlers;
+
 #endregion
 
 namespace IBatisNet.DataAccess.Scope
@@ -67,9 +65,9 @@
 			_providers.Clear();
 			_daoSectionHandlers.Clear();
 
-			_daoSectionHandlers.Add(DomDaoManagerBuilder.DEFAULT_DAOSESSIONHANDLER_NAME, DaoSessionHandlerFactory.GetDaoSessionHandler("ADONET"));
-			_daoSectionHandlers.Add("ADONET", DaoSessionHandlerFactory.GetDaoSessionHandler("ADONET"));
-			_daoSectionHandlers.Add("SqlMap", DaoSessionHandlerFactory.GetDaoSessionHandler("SqlMap"));
+			_daoSectionHandlers.Add(DomDaoManagerBuilder.DEFAULT_DAOSESSIONHANDLER_NAME, typeof(SimpleDaoSessionHandler));
+			_daoSectionHandlers.Add("ADONET", typeof(SimpleDaoSessionHandler));
+			_daoSectionHandlers.Add("SqlMap", typeof(SqlMapDaoSessionHandler));
 
 		}
 		#endregion