C# 클래스 DataAccessFramework.DataTool

An abstract class providing helper functionality to connect to a database.

This class provides functions that can simplfy common database access functionality, e.g. executing a stored procedure.

The tool itself is not tied to any specific database provider. Using this tool to execute database operations separates the application from the actual database server software.

The client code should also use functions in this class to create parameters to pass to the stored procedure. That will ensure that the parameters are compatible with the database provider.

상속: IDisposable
파일 보기 프로젝트 열기: PeteProgrammer/DataAccessFramework

공개 메소드들

메소드 설명
BeginTransaction ( ) : void

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling

CommitTransaction ( ) : void

Commits the transaction. Specialized classes should override this function and implement custom transaction handling

CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter

Creates database parameter for a binary value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.

CreateBoolParameter ( string parameterName, bool value ) : IDataParameter

Creates a database parameter for a Boolean value.

CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter

Creates a database parameter for a datetime value

CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter

Creates database parameter for a decimal value.

CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter

Creates database parameter for a GUID value.

CreateIntParameter ( string parameterName, int value ) : IDataParameter

Creates database parameter for an integer value.

CreateLongParameter ( string parameterName, long value ) : IDataParameter

Creates database parameter for an 64 bit integer value.

CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter

Creates a database parameter for a decimal value used for carrying monetary amount.

CreateStampParameter ( string parameterName, object stamp ) : IDataParameter

Creates a database parameter for a stamp value.

CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter

Creates database parameter for a string value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.

Dispose ( ) : void

Disposes the current instance.

ExecuteNonQuery ( string spName ) : int

Executes a stored procedure that does not return a result.

ExecuteQuery ( Query query ) : IDataReader

Executes a query represendted by a Query instance

ExecuteReader ( string spName ) : IDataReader

Executes a stored procedure that returns a single result set.

ExecuteReaderSingleRow ( string spName ) : IDataReader

Executes a stored procedure that returns a multiple result sets.

Executes a stored procedure that returns a single row.

ExecuteScalar ( string spName ) : object

Executes a stored procedure that returns a single value.

ExecuteSqlNonQuery ( string sql ) : int

Executes an sql statement that does not return a result.

ExecuteSqlReader ( string sql ) : IDataReader

Executes an SQL statement that returns an IDataReader

ExecuteSqlReaderSingleRow ( string sql ) : IDataReader

Executes an SQL statement that returns a single row.

ExecuteSqlScalar ( string sql ) : object

Executes an SQL text statement that returns a single value.

RollbackTransaction ( ) : void

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling

보호된 메소드들

메소드 설명
AssertNotDisposed ( ) : void

Verifies that the object has not been disposed.

CreateCommand ( ) : IDbCommand

Template function for creating a command object.

The DataTool class will call this internally when executing a query

Dispose ( bool disposing ) : void

Template function for disposing resources.

GetConnection ( ) : IDbConnection

Template function for getting a connection object.

The DataTool class will call this internally when executing a query

GetTransaction ( ) : IDbTransaction

Template function for getting a transaction

The DataTool class will call this internally when executing a query

비공개 메소드들

메소드 설명
ExecuteNonQuery ( string commandText, CommandType commandType ) : int
ExecuteReader ( string sql, CommandType commandType, CommandBehavior behavior ) : IDataReader
ExecuteScalar ( string commandText, CommandType commandType ) : object

메소드 상세

AssertNotDisposed() 보호된 메소드

Verifies that the object has not been disposed.
/// The object has been disposed. ///
protected AssertNotDisposed ( ) : void
리턴 void

BeginTransaction() 공개 추상적인 메소드

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling
public abstract BeginTransaction ( ) : void
리턴 void

CommitTransaction() 공개 추상적인 메소드

Commits the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract CommitTransaction ( ) : void
리턴 void

CreateBinaryParameter() 공개 메소드

public CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
parameterName string
dataStream Stream
리턴 IDataParameter

CreateBinaryParameter() 공개 추상적인 메소드

Creates database parameter for a binary value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.
/// The size of value exceeds that specified by /// length ///
public abstract CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value byte /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
리턴 IDataParameter

CreateBoolParameter() 공개 추상적인 메소드

Creates a database parameter for a Boolean value.
public abstract CreateBoolParameter ( string parameterName, bool value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value bool /// The value of the parameter ///
리턴 IDataParameter

CreateCommand() 보호된 추상적인 메소드

Template function for creating a command object.
The DataTool class will call this internally when executing a query
protected abstract CreateCommand ( ) : IDbCommand
리턴 IDbCommand

CreateDateTimeParameter() 공개 추상적인 메소드

Creates a database parameter for a datetime value
public abstract CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.DateTime /// The value of the parameter ///
리턴 IDataParameter

CreateDecimalParameter() 공개 추상적인 메소드

Creates database parameter for a decimal value.
public abstract CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
리턴 IDataParameter

CreateGuidParameter() 공개 추상적인 메소드

Creates database parameter for a GUID value.
public abstract CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.Guid /// The value of the parameter ///
리턴 IDataParameter

CreateIntParameter() 공개 추상적인 메소드

Creates database parameter for an integer value.
public abstract CreateIntParameter ( string parameterName, int value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value int /// The value of the parameter ///
리턴 IDataParameter

CreateLongParameter() 공개 추상적인 메소드

Creates database parameter for an 64 bit integer value.
public abstract CreateLongParameter ( string parameterName, long value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value long /// The value of the parameter ///
리턴 IDataParameter

CreateMoneyParameter() 공개 추상적인 메소드

Creates a database parameter for a decimal value used for carrying monetary amount.
public abstract CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
리턴 IDataParameter

CreateStampParameter() 공개 추상적인 메소드

Creates a database parameter for a stamp value.
public abstract CreateStampParameter ( string parameterName, object stamp ) : IDataParameter
parameterName string /// The name of the parameter. ///
stamp object /// The value of the parameter ///
리턴 IDataParameter

CreateStringParameter() 공개 추상적인 메소드

Creates database parameter for a string value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.
/// The length of value exceeds that specified by /// length ///
public abstract CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value string /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
리턴 IDataParameter

Dispose() 공개 메소드

Disposes the current instance.
public Dispose ( ) : void
리턴 void

Dispose() 보호된 메소드

Template function for disposing resources.
protected Dispose ( bool disposing ) : void
disposing bool /// Boolean value indicating if we are calling from dispose or the finalizer. /// true indicates we are calling from Dispose; false indicates /// we are calling from the finalizer. ///
리턴 void

ExecuteNonQuery() 공개 메소드

Executes a stored procedure that does not return a result.
public ExecuteNonQuery ( string spName ) : int
spName string /// Name of the stored procedure to execute. ///
리턴 int

ExecuteQuery() 공개 메소드

Executes a query represendted by a Query instance
public ExecuteQuery ( Query query ) : IDataReader
query DataAccessFramework.Querying.Query
리턴 IDataReader

ExecuteReader() 공개 메소드

Executes a stored procedure that returns a single result set.
public ExecuteReader ( string spName ) : IDataReader
spName string /// Name of the stored procedure to execute. ///
리턴 IDataReader

ExecuteReaderSingleRow() 공개 메소드

Executes a stored procedure that returns a multiple result sets. Executes a stored procedure that returns a single row.
public ExecuteReaderSingleRow ( string spName ) : IDataReader
spName string ///// Name of the stored procedure to execute. /////
리턴 IDataReader

ExecuteScalar() 공개 메소드

Executes a stored procedure that returns a single value.
public ExecuteScalar ( string spName ) : object
spName string /// Name of the stored procedure to execute. ///
리턴 object

ExecuteSqlNonQuery() 공개 메소드

Executes an sql statement that does not return a result.
public ExecuteSqlNonQuery ( string sql ) : int
sql string /// The SQL statement to execute ///
리턴 int

ExecuteSqlReader() 공개 메소드

Executes an SQL statement that returns an IDataReader
public ExecuteSqlReader ( string sql ) : IDataReader
sql string
리턴 IDataReader

ExecuteSqlReaderSingleRow() 공개 메소드

Executes an SQL statement that returns a single row.
public ExecuteSqlReaderSingleRow ( string sql ) : IDataReader
sql string
리턴 IDataReader

ExecuteSqlScalar() 공개 메소드

Executes an SQL text statement that returns a single value.
public ExecuteSqlScalar ( string sql ) : object
sql string
리턴 object

GetConnection() 보호된 추상적인 메소드

Template function for getting a connection object.
The DataTool class will call this internally when executing a query
protected abstract GetConnection ( ) : IDbConnection
리턴 IDbConnection

GetTransaction() 보호된 추상적인 메소드

Template function for getting a transaction
The DataTool class will call this internally when executing a query
protected abstract GetTransaction ( ) : IDbTransaction
리턴 IDbTransaction

RollbackTransaction() 공개 추상적인 메소드

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract RollbackTransaction ( ) : void
리턴 void