[ 
http://issues.apache.org/jira/browse/IBATISNET-35?page=comments#action_12314645 
] 

Ron Grabowski commented on IBATISNET-35:
----------------------------------------

Here's a thread in which I posted some additional questions about creating a 
proxified IDbCommand and IDataReader to automatically log statements returned 
from database:

 http://forum.castleproject.org/posts/list/81.page

I'm able to log things in this manner now (yes, I'm aware that the ordering of 
the column names are switched):

 Dao Proxy call to GetMany
 Dao Proxy, Open a connection 
 Open Connection "826" to "OleDb1.1".
 PreparedStatement : [SELECT RegionId, Name FROM Region]
 Headers: [RegionId, Name]
 Results: [Manhattan, 1]
 Results: [Brooklyn, 2]
 Results: [New Jersey, 3]
 Results: [Long Island, 4]
 Results: [Connecticut/Westchester, 5]
 Results: [Quenns/Staten Island/Bronx, 6]
 Results: [Other, 7]
 Close Connection "826" to "OleDb1.1".
 End of proxyfied call to GetMany

Making IBatisNet.DataMapper.SqlMapSession.CreateCommand return a proxified 
IDbCommand right before the IDbCommand object is returned gets around this 
issue:

 http://forum.castleproject.org/posts/list/39.page

because the Connection and Transaction properties are assigned to the normal 
IDbCommand object.:

 if (_logger.IsDebugEnabled)
 {
  command = IDbCommandProxy.NewInstance(command);
 }
 return command;

Calls to the Execute* methods (ExecuteReader, ExecuteNonQuery, etc.) can still 
be intercepted. When the call to ExecuteReader is executed inside of the 
proxifed IDbCommand, the returned IDataReader is wrapped inside a concrete 
DataReaderWrapper class which does the actual logging:

 public object Intercept(IInvocation invocation, params object[] arguments)
 {
  object returnValue = invocation.Method.Invoke(_command, arguments);
  if (invocation.Method.Name == "ExecuteReader")
  {
   returnValue = new DataReaderWrapper((IDataReader)returnValue);
  }
  return returnValue;
 }

See the post at the top of the comment for an peak inside the DataReaderWrapper 
class:

 http://forum.castleproject.org/posts/list/81.page

Items are stored to a temp object only when they are accessed and a single log 
message is written when Read() is called to advance to the next IDataRecord.

I'm waiting for Hammett  to share his wisdom before I go any further.

> Improve logging of text sent to database and recieved from database to match 
> Java version of IBatis
> ---------------------------------------------------------------------------------------------------
>
>          Key: IBATISNET-35
>          URL: http://issues.apache.org/jira/browse/IBATISNET-35
>      Project: iBatis for .NET
>         Type: Improvement
>     Versions: DataAccess 1.5, DataMapper 1.1
>  Environment: Data Mapper - [assembly: AssemblyVersion("1.1.458")]
> Data Access - [assembly: AssemblyVersion("1.5.458")]
>     Reporter: Ron Grabowski
>     Assignee: Gilles Bayon
>  Attachments: SystemDataProxy.zip, TypeHandlerFactory.cs, 
> TypeHandlerLogWrapper.cs
>
> Here are some example logs from the Java version of IBatis. The examples show 
> INSERT, SELECT, UPDATE, and DELETE statements:
> DEBUG - Checked out connection 30332961 from pool.
> DEBUG - {conn-100003} Connection
> DEBUG - {pstm-100004} PreparedStatement: INSERT INFO UserAudit (UserId, 
> AuditEvent, DateOccurred) values (?,?,?)          
> DEBUG - {pstm-100004} Parameters: [4, audit.login.success, 2004-08-25 
> 09:15:22.809]
> DEBUG - {pstm-100004} Types: [java.lang.Integer, java.lang.String, 
> java.sql.Timestamp]
> DEBUG - {pstm-100005} PreparedStatement: SELECT LAST_INSERT_ID() AS id  
> DEBUG - {pstm-100005} Parameters: []
> DEBUG - {pstm-100005} Types: []
> DEBUG - {rset-100006} ResultSet
> DEBUG - {rset-100006} Header: [id]
> DEBUG - {rset-100006} Result: [422]
> DEBUG - Returned connection 30332961 to pool.
> DEBUG - Checked out connection 30332961 from pool.
> DEBUG - {conn-100007} Connection
> DEBUG - {pstm-100008} PreparedStatement: SELECT UserId, Login, Password FROM 
> User WHERE Login = ? and Password = ?
> DEBUG - {pstm-100008} Parameters: [abc123, def456]
> DEBUG - {pstm-100008} Types: [java.lang.String, java.lang.String]
> DEBUG - {rset-100009} ResultSet
> DEBUG - {rset-100009} Header: [UserId, Login, Password]
> DEBUG - {rset-100009} Result: [4, abc1234, def456]
> DEBUG - Returned connection 30332961 to pool.
> DEBUG - Checked out connection 4548856 from pool.
> DEBUG - {conn-100045} Connection
> DEBUG - {pstm-100046} PreparedStatement: SELECT UserId, Login FROM User
> DEBUG - {pstm-100046} Parameters: []
> DEBUG - {pstm-100046} Types: []
> DEBUG - {rset-100047} ResultSet
> DEBUG - {rset-100047} Header: [UserId, Login]
> DEBUG - {rset-100047} Result: [1, abc123]
> DEBUG - {rset-100047} Result: [4, def456]
> DEBUG - {rset-100047} Result: [6, aaaaa]
> DEBUG - Returned connection 4548856 to pool.
> DEBUG - Checked out connection 7125805 from pool.
> DEBUG - {conn-100043} Connection
> DEBUG - {pstm-100044} PreparedStatement: UPDATE User SET Login = ? WHERE 
> UserId = ?
> DEBUG - {pstm-100044} Parameters: [aaaaa, 4]
> DEBUG - {pstm-100044} Types: [java.lang.String, java.lang.Integer]
> DEBUG - Returned connection 7125805 to pool.
> DEBUG - Checked out connection 27062282 from pool.
> DEBUG - {conn-100043} Connection
> DEBUG - {pstm-100044} PreparedStatement: DELETE FROM User WHERE UserId = ?
> DEBUG - {pstm-100044} Parameters: [4]
> DEBUG - {pstm-100044} Types: [java.lang.Integer]
> DEBUG - Returned connection 27062282 to pool.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to