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/04/25 20:21:20 UTC

svn commit: r164614 - in /incubator/ibatis/trunk/cs/mapper/IBatisNet.Common: DataSource.cs IBatisNet.Common.csproj Logging/ Logging/IDbConnectionProxy.cs Provider.cs Utilities/DynamicProxy/ Utilities/ScriptRunner.cs

Author: gbayon
Date: Mon Apr 25 11:21:19 2005
New Revision: 164614

URL: http://svn.apache.org/viewcvs?rev=164614&view=rev
Log:
Test proxy for logging but it's not performant, we will not use them.

Added:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/IDbConnectionProxy.cs
Removed:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/DynamicProxy/
Modified:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/DataSource.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Provider.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ScriptRunner.cs

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/DataSource.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/DataSource.cs?rev=164614&r1=164613&r2=164614&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/DataSource.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/DataSource.cs Mon Apr 25 11:21:19 2005
@@ -24,12 +24,11 @@
  ********************************************************************************/
 #endregion
 
-#region Imports
+#region Using
 using System;
 using System.Runtime.Serialization;
 using System.Xml.Serialization;
 #endregion
-
 
 namespace IBatisNet.Common
 {

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj?rev=164614&r1=164613&r2=164614&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj Mon Apr 25 11:21:19 2005
@@ -94,6 +94,11 @@
                     AssemblyName = "log4net"
                     HintPath = "..\External-Bin\Net\1.1\log4net.dll"
                 />
+                <Reference
+                    Name = "Castle.DynamicProxy"
+                    AssemblyName = "Castle.DynamicProxy"
+                    HintPath = "..\External-Bin\Net\1.1\Castle.DynamicProxy.dll"
+                />
             </References>
         </Build>
         <Files>
@@ -159,6 +164,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "Logging\IDbConnectionProxy.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Pagination\IPaginatedList.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
@@ -215,21 +225,6 @@
                 />
                 <File
                     RelPath = "Utilities\StringTokenizer.cs"
-                    SubType = "Code"
-                    BuildAction = "Compile"
-                />
-                <File
-                    RelPath = "Utilities\DynamicProxy\IInvocationHandler.cs"
-                    SubType = "Code"
-                    BuildAction = "Compile"
-                />
-                <File
-                    RelPath = "Utilities\DynamicProxy\ProxyGenerator.cs"
-                    SubType = "Code"
-                    BuildAction = "Compile"
-                />
-                <File
-                    RelPath = "Utilities\DynamicProxy\StandardInvocationHandler.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
                 />

Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/IDbConnectionProxy.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/IDbConnectionProxy.cs?rev=164614&view=auto
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/IDbConnectionProxy.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/IDbConnectionProxy.cs Mon Apr 25 11:21:19 2005
@@ -0,0 +1,141 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ * 
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *  
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ ********************************************************************************/
+#endregion
+
+#region Using
+using System;
+using System.Data;
+using System.Collections;
+using System.Reflection;
+using System.Xml.Serialization;
+
+using Castle.DynamicProxy;
+
+using IBatisNet.Common;
+using IBatisNet.Common.Utilities.Objects;
+
+using IBatisNet.Common.Exceptions;
+
+using log4net;
+#endregion
+
+namespace IBatisNet.Common.Logging
+{
+	/// <summary>
+	/// Summary description for IDbConnectionProxy.
+	/// </summary>
+	/// <remarks>Not used.</remarks>
+	public class IDbConnectionProxy : IInterceptor
+	{
+
+		#region Fields
+		private string _connectionString = string.Empty;
+		private IDbConnection _connection = null;
+		private Provider _provider = null;
+		private static ArrayList _passthroughMethods = new ArrayList();
+		private static readonly ILog _logger = LogManager.GetLogger( "System.Data.IDbConnection" );
+
+		#endregion 
+
+		#region Constructors
+
+		static IDbConnectionProxy()
+		{
+			_passthroughMethods.Add("GetType");
+			_passthroughMethods.Add("ToString");
+		}
+
+		/// <summary>
+		/// Constructor for a connection proxy
+		/// </summary>
+		/// <param name="connection">The connection which been proxified.</param>
+		/// <param name="provider">The provider used</param>
+		internal IDbConnectionProxy(IDbConnection connection, Provider provider)
+		{
+			_connection = connection;
+			_provider = provider;
+		}
+		#endregion 
+
+		#region Methods
+
+		/// <summary>
+		/// Static constructor
+		/// </summary>
+		/// <param name="connection">The connection which been proxified.</param>
+		/// <param name="provider">The provider used</param>
+		/// <returns>A proxy</returns>
+		internal static IDbConnection NewInstance(IDbConnection connection, Provider provider)
+		{
+			object proxyConnection = null;
+			IInterceptor handler = new IDbConnectionProxy(connection, provider);
+
+			ProxyGenerator proxyGenerator = new ProxyGenerator();
+
+			proxyConnection = proxyGenerator.CreateProxy(typeof(IDbConnection), handler, connection);
+
+			return (IDbConnection) proxyConnection;
+		}
+		#endregion 
+
+		#region IInterceptor Members
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="invocation"></param>
+		/// <param name="arguments"></param>
+		/// <returns></returns>
+		public object Intercept(IInvocation invocation, params object[] arguments)
+		{
+			object returnValue = null;
+
+			if (invocation.Method.Name=="Open")
+			{
+				_connection.Open();
+				if (_logger.IsDebugEnabled)
+				{
+					_logger.Debug( string.Format("Open Connection \"{0}\" to \"{1}\".", _connection.GetHashCode().ToString(), _provider.Description) );
+				}				 
+			}
+			else if (invocation.Method.Name=="Close")
+			{
+				_connection.Close();
+				if (_logger.IsDebugEnabled)
+				{
+					_logger.Debug( string.Format("Close Connection \"{0}\" to \"{1}\".", _connection.GetHashCode().ToString(), _provider.Description) );
+				}				 
+			}
+			else //if ( !_passthroughMethods.Contains(invocation.Method.Name) )
+			{
+				returnValue = invocation.Method.Invoke( _connection, arguments);
+			}
+
+			return returnValue;
+		}
+
+		#endregion
+	}
+}

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Provider.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Provider.cs?rev=164614&r1=164613&r2=164614&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Provider.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Provider.cs Mon Apr 25 11:21:19 2005
@@ -24,7 +24,7 @@
  ********************************************************************************/
 #endregion
 
-#region Imports
+#region Using
 using System;
 using System.Data;
 
@@ -33,7 +33,10 @@
 using System.Xml.Serialization;
 using System.Reflection;
 
-using IBatisNet.Common.Exceptions; 
+using IBatisNet.Common.Exceptions;
+using IBatisNet.Common.Logging; 
+
+using log4net;
 #endregion
 
 namespace IBatisNet.Common
@@ -94,6 +97,8 @@
 		[NonSerialized]
 		private bool _usePositionalParameters = false;
 		
+		private static readonly ILog _connectionLogger = LogManager.GetLogger("System.Data.IDbConnection");
+
 		#endregion
 		
 		#region Properties
@@ -434,6 +439,15 @@
 		/// <returns>An 'IDbConnection' object.</returns>
 		public IDbConnection GetConnection()
 		{
+			// Cannot do that because on 
+			// IDbCommand.Connection = cmdConnection
+			// .NET cast the cmdConnection to the real type (as SqlConnection)
+			// and we pass a proxy --> exception invalid cast !
+//			if (_connectionLogger.IsDebugEnabled)
+//			{
+//				connection = (IDbConnection)IDbConnectionProxy.NewInstance(connection, this);
+//			}
+
 			return (IDbConnection) ((ICloneable)_templateConnection).Clone();
 		}
 

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ScriptRunner.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ScriptRunner.cs?rev=164614&r1=164613&r2=164614&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ScriptRunner.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/ScriptRunner.cs Mon Apr 25 11:21:19 2005
@@ -141,6 +141,7 @@
 			IDbTransaction transaction = connection.BeginTransaction();
 			
 			IDbCommand command = dataSource.Provider.GetCommand();
+
 			command.Connection = connection;
 			command.Transaction = transaction;