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:47 UTC

svn commit: r164615 [1/3] - in /incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper: ./ Commands/ MappedStatements/ Scope/ Test/bin/Debug/

Author: gbayon
Date: Mon Apr 25 11:21:46 2005
New Revision: 164615

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

Added:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommandProxy.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.xml
Modified:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandFactory.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/LazyLoadList.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config?rev=164615&r1=164614&r2=164615&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config Mon Apr 25 11:21:46 2005
@@ -19,7 +19,7 @@
 		<!-- To test MySql via ByteFx value="ByteFx"  -->
 		<!-- To test via OleDb provider (any database) value="OleDb"  -->
 		<!-- To test via Odbc provider (any database) value="Odbc"  -->
-		<add key="providerType" value="OleDb"/>
+		<add key="providerType" value="SqlClient"/>
 	</appSettings>
 	
 	<!-- This section contains the log4net configuration settings -->
@@ -43,7 +43,7 @@
 				<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
 			</layout>
 		</appender>
-		
+		<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
 		<!-- Set root logger level to ERROR and its appenders -->
 		<root>
 			<level value="DEBUG" />
@@ -56,9 +56,9 @@
 			<level value="DEBUG" />
 		</logger>
 		<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
-			<level value="DEBUG" />
+			<level value="OFF" />
 		</logger>
-		<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
+		<logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
 			<level value="DEBUG" />
 		</logger>		
 		<logger name="IBatisNet.DataMapper.LazyLoadList">
@@ -74,6 +74,9 @@
 			<level value="DEBUG" />
 		</logger>
 		<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
+			<level value="DEBUG" />
+		</logger>
+		<logger name="System.Data.IDbConnection">
 			<level value="DEBUG" />
 		</logger>
 	</log4net>

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs?rev=164615&r1=164614&r2=164615&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/DefaultPreparedCommand.cs Mon Apr 25 11:21:46 2005
@@ -70,12 +70,12 @@
 			// the IDbConnection & the IDbTransaction are assign in the CreateCommand 
 			IDbCommand command = session.CreateCommand(statement.CommandType);
 			
+			command.CommandText = request.PreparedStatement.PreparedSql;
+
 			if (_logger.IsDebugEnabled)
 			{
-				_logger.Debug("PreparedStatement : [" + request.PreparedStatement.PreparedSql + "]");
+				_logger.Debug("PreparedStatement : [" + command.CommandText + "]");
 			}
-
-			command.CommandText = request.PreparedStatement.PreparedSql;
 
 			ApplyParameterMap( session, command, request, statement, parameterObject  );
 

Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommandProxy.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommandProxy.cs?rev=164615&view=auto
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommandProxy.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/IPreparedCommandProxy.cs Mon Apr 25 11:21:46 2005
@@ -0,0 +1,152 @@
+
+#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 System.Text;
+
+using Castle.DynamicProxy;
+
+using IBatisNet.Common;
+using IBatisNet.Common.Utilities.Objects;
+
+using IBatisNet.Common.Exceptions;
+
+using log4net;
+#endregion
+
+namespace IBatisNet.DataMapper.Commands
+{
+	/// <summary>
+	/// Summary description for IPreparedCommandProxy.
+	/// </summary>
+	public class IPreparedCommandProxy : IInterceptor
+	{
+
+		#region Fields
+		private IPreparedCommand _preparedCommand = null;
+		private static ArrayList _passthroughMethods = new ArrayList();
+		private static readonly ILog _logger = LogManager.GetLogger( "IBatisNet.DataMapper.Commands.IPreparedCommand" );
+
+		#endregion 
+
+		#region Constructors
+
+		static IPreparedCommandProxy()
+		{
+			_passthroughMethods.Add("GetType");
+			_passthroughMethods.Add("ToString");
+		}
+
+		/// <summary>
+		/// Constructor for a connection proxy
+		/// </summary>
+		/// <param name="preparedCommand">The connection which been proxified.</param>
+		internal IPreparedCommandProxy(IPreparedCommand preparedCommand)
+		{
+			_preparedCommand = preparedCommand;
+		}
+		#endregion 
+
+		#region Methods
+
+		/// <summary>
+		/// Static constructor
+		/// </summary>
+		/// <param name="preparedCommand">The connection which been proxified.</param>
+		/// <returns>A proxy</returns>
+		internal static IPreparedCommand NewInstance(IPreparedCommand preparedCommand)
+		{
+			object proxyIPreparedCommand = null;
+			IInterceptor handler = new IPreparedCommandProxy(preparedCommand);
+
+			ProxyGenerator proxyGenerator = new ProxyGenerator();
+
+			proxyIPreparedCommand = proxyGenerator.CreateProxy(typeof(IPreparedCommand), handler, preparedCommand);
+
+			return (IPreparedCommand) proxyIPreparedCommand;
+		}
+		#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;
+
+			returnValue = invocation.Method.Invoke( _preparedCommand, arguments);
+
+			if (invocation.Method.Name=="Create")
+			{
+				if (_logger.IsDebugEnabled)
+				{
+					IDbCommand command = (IDbCommand)returnValue;
+
+					_logger.Debug("PreparedStatement : [" + command.CommandText + "]");
+					if (command.Parameters.Count>0)
+					{
+						StringBuilder valueList = new StringBuilder(); // Log info
+						StringBuilder typeList = new StringBuilder(); // Log info 
+
+						for ( int i = 0; i < command.Parameters.Count; ++i )
+						{
+							IDataParameter sqlParameter = (IDataParameter)command.Parameters[i];
+							if (sqlParameter.Value == System.DBNull.Value) 
+							{
+								valueList.Append("null,");
+								typeList.Append("null,");
+							} 
+							else 
+							{
+								valueList.Append( sqlParameter.Value.ToString() );
+								valueList.Append( "," );
+								typeList.Append( sqlParameter.Value.GetType().ToString() );
+								typeList.Append( "," );
+							}
+						}
+
+						_logger.Debug("Parameters: [" + valueList.ToString().Remove(valueList.ToString().Length-1,1) + "]");
+						_logger.Debug("Types: [" + typeList.ToString().Remove(typeList.ToString().Length-1,1) + "]");
+					}
+				}
+			}
+
+			return returnValue;
+		}
+
+		#endregion
+	}
+}

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandFactory.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandFactory.cs?rev=164615&r1=164614&r2=164615&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandFactory.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Commands/PreparedCommandFactory.cs Mon Apr 25 11:21:46 2005
@@ -23,8 +23,9 @@
  ********************************************************************************/
 #endregion
 
-#region Imports
+#region Using
 
+using log4net;
 #endregion
 
 namespace IBatisNet.DataMapper.Commands
@@ -40,14 +41,20 @@
 		/// <returns></returns>
 		static public IPreparedCommand GetPreparedCommand(bool isEmbedStatementParams)
 		{
+			IPreparedCommand preparedCommand = null;
+
 			if (isEmbedStatementParams)
 			{
-				return new EmbedParamsPreparedCommand();
+				preparedCommand = new EmbedParamsPreparedCommand();
 			}
 			else
 			{
-				return new DefaultPreparedCommand();				
+				preparedCommand = new DefaultPreparedCommand();
 			}
+
+			//return (IPreparedCommand)IPreparedCommandProxy.NewInstance(preparedCommand);
+
+			return preparedCommand;
 		}
 
 	}

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj?rev=164615&r1=164614&r2=164615&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Mon Apr 25 11:21:46 2005
@@ -191,6 +191,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "Commands\IPreparedCommandProxy.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Commands\PreparedCommandFactory.cs"
                     SubType = "Code"
                     BuildAction = "Compile"