#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 NextResult call.
///
public class DataReaderDecorator : IDataReader
{
private IDataReader _innerDataReader = null;
private RequestScope _request = null;
///
/// Initializes a new instance of the class.
///
/// The data reader.
/// The request scope
public DataReaderDecorator(IDataReader dataReader, RequestScope request)
{
_innerDataReader = dataReader;
_request = request;
}
#region IDataReader Members
///
/// Closes the 0bject.
///
void IDataReader.Close()
{
_innerDataReader.Close();
}
///
/// Gets a value indicating the depth of nesting for the current row.
///
///
/// The level of nesting.
int IDataReader.Depth
{
get { return _innerDataReader.Depth; }
}
///
/// Returns a that describes the column metadata of the .
///
///
/// A that describes the column metadata.
///
/// The is closed.
DataTable IDataReader.GetSchemaTable()
{
return _innerDataReader.GetSchemaTable();
}
///
/// Gets a value indicating whether the data reader is closed.
///
///
/// true if the data reader is closed; otherwise, false.
bool IDataReader.IsClosed
{
get { return _innerDataReader.IsClosed; }
}
///
/// Advances the data reader to the next result, when reading the results of batch SQL statements.
///
///
/// true if there are more rows; otherwise, false.
///
bool IDataReader.NextResult()
{
_request.MoveNextResultMap();
return _innerDataReader.NextResult();
}
///
/// Advances the to the next record.
///
///
/// true if there are more rows; otherwise, false.
///
bool IDataReader.Read()
{
return _innerDataReader.Read();
}
int IDataReader.RecordsAffected
{
get { return _innerDataReader.RecordsAffected; }
}
#endregion
#region IDisposable Members
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
void IDisposable.Dispose()
{
_innerDataReader.Dispose();
}
#endregion
#region IDataRecord Members
///
/// Gets the number of columns in the current row.
///
///
/// When not positioned in a valid recordset, 0; otherwise the number of columns in the current record. The default is -1.
int IDataRecord.FieldCount
{
get { return _innerDataReader.FieldCount; }
}
///
/// Gets the value of the specified column as a Boolean.
///
/// The zero-based column ordinal.
/// The value of the column.
/// The index passed was outside the range of 0 through .
bool IDataRecord.GetBoolean(int i)
{
return _innerDataReader.GetBoolean(i);
}
///
/// Gets the 8-bit unsigned integer value of the specified column.
///
/// The zero-based column ordinal.
///
/// The 8-bit unsigned integer value of the specified column.
///
/// The index passed was outside the range of 0 through .
byte IDataRecord.GetByte(int i)
{
return _innerDataReader.GetByte(i);
}
///
/// Reads a stream of bytes from the specified column offset into the buffer as an array, starting at the given buffer offset.
///
/// The zero-based column ordinal.
/// The index within the field from which to start the read operation.
/// The buffer into which to read the stream of bytes.
/// The index for buffer to start the read operation.
/// The number of bytes to read.
/// The actual number of bytes read.
/// The index passed was outside the range of 0 through .
long IDataRecord.GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
{
return _innerDataReader.GetBytes(i, fieldOffset, buffer, bufferoffset, length);
}
///
/// Gets the character value of the specified column.
///
/// The zero-based column ordinal.
///
/// The character value of the specified column.
///
/// The index passed was outside the range of 0 through .
char IDataRecord.GetChar(int i)
{
return _innerDataReader.GetChar(i);
}
///
/// Reads a stream of characters from the specified column offset into the buffer as an array, starting at the given buffer offset.
///
/// The zero-based column ordinal.
/// The index within the row from which to start the read operation.
/// The buffer into which to read the stream of bytes.
/// The index for buffer to start the read operation.
/// The number of bytes to read.
/// The actual number of characters read.
/// The index passed was outside the range of 0 through .
long IDataRecord.GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
{
return _innerDataReader.GetChars(i, fieldoffset, buffer, bufferoffset, length);
}
///
/// Gets an to be used when the field points to more remote structured data.
///
/// The index of the field to find.
///
/// An to be used when the field points to more remote structured data.
///
/// The index passed was outside the range of 0 through .
IDataReader IDataRecord.GetData(int i)
{
return _innerDataReader.GetData(i);
}
///
/// Gets the data type information for the specified field.
///
/// The index of the field to find.
///
/// The data type information for the specified field.
///
/// The index passed was outside the range of 0 through .
string IDataRecord.GetDataTypeName(int i)
{
return _innerDataReader.GetDataTypeName(i);
}
///
/// Gets the date and time data value of the specified field.
///
/// The index of the field to find.
///
/// The date and time data value of the spcified field.
///
/// The index passed was outside the range of 0 through .
DateTime IDataRecord.GetDateTime(int i)
{
return _innerDataReader.GetDateTime(i);
}
///
/// Gets the fixed-position numeric value of the specified field.
///
/// The index of the field to find.
///
/// The fixed-position numeric value of the specified field.
///
/// The index passed was outside the range of 0 through .
decimal IDataRecord.GetDecimal(int i)
{
return _innerDataReader.GetDecimal(i);
}
///
/// Gets the double-precision floating point number of the specified field.
///
/// The index of the field to find.
///
/// The double-precision floating point number of the specified field.
///
/// The index passed was outside the range of 0 through .
double IDataRecord.GetDouble(int i)
{
return _innerDataReader.GetDouble(i);
}
///
/// Gets the information corresponding to the type of that would be returned from .
///
/// The index of the field to find.
///
/// The information corresponding to the type of that would be returned from .
///
/// The index passed was outside the range of 0 through .
Type IDataRecord.GetFieldType(int i)
{
return _innerDataReader.GetFieldType(i);
}
///
/// Gets the single-precision floating point number of the specified field.
///
/// The index of the field to find.
///
/// The single-precision floating point number of the specified field.
///
/// The index passed was outside the range of 0 through .
float IDataRecord.GetFloat(int i)
{
return _innerDataReader.GetFloat(i);
}
///
/// Returns the GUID value of the specified field.
///
/// The index of the field to find.
/// The GUID value of the specified field.
/// The index passed was outside the range of 0 through .
Guid IDataRecord.GetGuid(int i)
{
return _innerDataReader.GetGuid(i);
}
///
/// Gets the 16-bit signed integer value of the specified field.
///
/// The index of the field to find.
///
/// The 16-bit signed integer value of the specified field.
///
/// The index passed was outside the range of 0 through .
short IDataRecord.GetInt16(int i)
{
return _innerDataReader.GetInt16(i);
}
///
/// Gets the 32-bit signed integer value of the specified field.
///
/// The index of the field to find.
///
/// The 32-bit signed integer value of the specified field.
///
/// The index passed was outside the range of 0 through .
int IDataRecord.GetInt32(int i)
{
return _innerDataReader.GetInt32(i);
}
///
/// Gets the 64-bit signed integer value of the specified field.
///
/// The index of the field to find.
///
/// The 64-bit signed integer value of the specified field.
///
/// The index passed was outside the range of 0 through .
long IDataRecord.GetInt64(int i)
{
return _innerDataReader.GetInt64(i);
}
///
/// Gets the name for the field to find.
///
/// The index of the field to find.
///
/// The name of the field or the empty string (""), if there is no value to return.
///
/// The index passed was outside the range of 0 through .
string IDataRecord.GetName(int i)
{
return _innerDataReader.GetName(i);
}
///
/// Return the index of the named field.
///
/// The name of the field to find.
/// The index of the named field.
int IDataRecord.GetOrdinal(string name)
{
return _innerDataReader.GetOrdinal(name);
}
///
/// Gets the string value of the specified field.
///
/// The index of the field to find.
/// The string value of the specified field.
/// The index passed was outside the range of 0 through .
string IDataRecord.GetString(int i)
{
return _innerDataReader.GetString(i);
}
///
/// Return the value of the specified field.
///
/// The index of the field to find.
///
/// The which will contain the field value upon return.
///
/// The index passed was outside the range of 0 through .
object IDataRecord.GetValue(int i)
{
return _innerDataReader.GetValue(i);
}
int IDataRecord.GetValues(object[] values)
{
return _innerDataReader.GetValues(values);
}
///
/// Return whether the specified field is set to null.
///
/// The index of the field to find.
///
/// true if the specified field is set to null. Otherwise, false.
///
/// The index passed was outside the range of 0 through .
bool IDataRecord.IsDBNull(int i)
{
return _innerDataReader.IsDBNull(i);
}
///
/// Gets the with the specified name.
///
///
object IDataRecord.this[string name]
{
get { return _innerDataReader[name]; }
}
///
/// Gets the with the specified i.
///
///
object IDataRecord.this[int i]
{
get { return _innerDataReader[i]; }
}
#endregion
}
}