#region Apache Notice
/*****************************************************************************
* $Header: $
* $Revision: 383115 $
* $Date$
*
* iBATIS.NET Data Mapper
* Copyright (C) 2005 - 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
using System;
using System.Data;
using IBatisNet.DataMapper.Scope;
namespace IBatisNet.DataMapper.Commands
{
///
/// Decorate an
/// to auto move to next ResultMap on ExecuteReader call.
///
public class DbCommandDecorator : IDbCommand
{
private IDbCommand _innerDbCommand = null;
private RequestScope _request = null;
///
/// Initializes a new instance of the class.
///
/// The db command.
/// The request scope
public DbCommandDecorator(IDbCommand dbCommand, RequestScope request)
{
_request = request;
_innerDbCommand = dbCommand;
}
#region IDbCommand Members
///
/// Attempts to cancels the execution of an .
///
void IDbCommand.Cancel()
{
_innerDbCommand.Cancel();
}
///
/// Gets or sets the text command to run against the data source.
///
///
/// The text command to execute. The default value is an empty string ("").
string IDbCommand.CommandText
{
get { return _innerDbCommand.CommandText; }
set { _innerDbCommand.CommandText = value; }
}
///
/// Gets or sets the wait time before terminating the attempt to execute a command and generating an error.
///
///
/// The time (in seconds) to wait for the command to execute. The default value is 30 seconds.
/// The property value assigned is less than 0.
int IDbCommand.CommandTimeout
{
get { return _innerDbCommand.CommandTimeout; }
set { _innerDbCommand.CommandTimeout = value; }
}
///
/// Indicates or specifies how the property is interpreted.
///
///
/// One of the values. The default is Text.
CommandType IDbCommand.CommandType
{
get { return _innerDbCommand.CommandType; }
set { _innerDbCommand.CommandType = value; }
}
///
/// Gets or sets the used by this instance of the .
///
///
/// The connection to the data source.
IDbConnection IDbCommand.Connection
{
get { return _innerDbCommand.Connection; }
set { _innerDbCommand.Connection = value; }
}
///
/// Creates a new instance of an object.
///
/// An IDbDataParameter object.
IDbDataParameter IDbCommand.CreateParameter()
{
return _innerDbCommand.CreateParameter();
}
///
/// Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.
///
/// The number of rows affected.
/// The connection does not exist.-or- The connection is not open.
int IDbCommand.ExecuteNonQuery()
{
_request.Session.OpenConnection();
return _innerDbCommand.ExecuteNonQuery();
}
///
/// Executes the against the , and builds an using one of the values.
///
/// One of the values.
///
/// An object.
///
IDataReader IDbCommand.ExecuteReader(CommandBehavior behavior)
{
_request.Session.OpenConnection();
return _innerDbCommand.ExecuteReader(behavior);
}
///
/// Executes the against the and builds an .
///
///
/// An object.
///
IDataReader IDbCommand.ExecuteReader()
{
_request.Session.OpenConnection();
_request.MoveNextResultMap();
return new DataReaderDecorator(_innerDbCommand.ExecuteReader(), _request);
}
///
/// Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The first column of the first row in the resultset.
///
object IDbCommand.ExecuteScalar()
{
_request.Session.OpenConnection();
return _innerDbCommand.ExecuteScalar();
}
///
/// Gets the .
///
///
/// The parameters of the SQL statement or stored procedure.
IDataParameterCollection IDbCommand.Parameters
{
get { return _innerDbCommand.Parameters; }
}
///
/// Creates a prepared (or compiled) version of the command on the data source.
///
/// The is not set.-or- The is not .
void IDbCommand.Prepare()
{
_innerDbCommand.Prepare();
}
///
/// Gets or sets the transaction within which the Command object of a .NET Framework data provider executes.
///
///
/// the Command object of a .NET Framework data provider executes. The default value is null.
IDbTransaction IDbCommand.Transaction
{
get { return _innerDbCommand.Transaction; }
set { _innerDbCommand.Transaction = value; }
}
///
/// Gets or sets how command results are applied to the when used by the method of a .
///
///
/// One of the values. The default is Both unless the command is automatically generated. Then the default is None.
/// The value entered was not one of the values.
UpdateRowSource IDbCommand.UpdatedRowSource
{
get { return _innerDbCommand.UpdatedRowSource; }
set { _innerDbCommand.UpdatedRowSource = value; }
}
#endregion
#region IDisposable Members
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
void IDisposable.Dispose()
{
_innerDbCommand.Dispose();
}
#endregion
}
}