using System;
using System.Data;
using System.Data.Common;
using System.Globalization;
//using GZTW.Common;
namespace GZTW.Data
{
public enum DataBaseType
{
FireBird,
MSSQL,
Oracle
}
///
/// Summary description for GZTWDatabase.
///
public abstract class GZTWDatabase
{
private string connectionString;
private static ParameterCache parameterCache = new ParameterCache();
protected GZTWDatabase()
{
}
///
/// Use to clear the connection pool
/// Required when doing schema updates in firebird
/// as some ddl can't be executed from more than one connection
///
public abstract void ClearPool();
///
/// Get the DataBaseType enum for the active db type
/// Used by higher layers when some DB specific code needs to be
/// executed
///
///
/// DataBaseType enumeration value
///
public abstract DataBaseType DBType { get; }
///
/// A schema fingerprint to detect corruption
/// or unauthorized 3rd party changes to database
///
public abstract string SchemaFingerPrint { get; }
///
/// Gets the string used to open a database.
///
///
///
/// The string used to open a database.
///
public string ConnectionString
{
get
{
return connectionString;
// string s = ConnectionStringBuilder.Build(DatabaseProviderData.ConnectionStringData);
// ConnectionString connectionString = new ConnectionString(s, VALID_USER_ID_TOKENS, VALID_PASSWORD_TOKENS);
// return connectionString.ToString();
}
set
{
connectionString=value;
}
}
///
/// When implemented by a class, gets the parameter token used to delimit parameters for the database.
///
///
/// the parameter token used to delimit parameters for the database.
///
protected abstract char ParameterToken { get; }
// ///
// /// Provides methods to record each event that occurs. Allows for performance counters
// /// to monitor the Data block.
// ///
// internal DataInstrumentationFacade Instrumentation
// {
// get { return//this.instrumentation; }
// }
// ///
// /// Gets the connection string with out the username and password.
// ///
// ///
// ///
// /// The connection string with out the username and password.
// ///
// protected string ConnectionStringNoCredentials
// {
// get
// {
// string s = ConnectionStringBuilder.Build(DatabaseProviderData.ConnectionStringData);
// ConnectionString connectionString = new ConnectionString(s, VALID_USER_ID_TOKENS, VALID_PASSWORD_TOKENS);
// return connectionString.ToStringNoCredentials();
// }
// }
// ///
// /// Method used for testing ONLY!!!
// ///
// internal string GetConnectionStringWithoutCredentials()
// {
// return ConnectionStringNoCredentials;
// }
//
// ///
// /// Gets the service key used to create the database instance.
// ///
// ///
// /// The service key used to create the database instance.
// ///
// protected string ServiceKey
// {
// get { return DatabaseProviderData.Name; }
// }
// ///
// /// Gets the from which
// /// this object was initialized.
// ///
// /// A .
// protected DatabaseProviderData DatabaseProviderData
// {
// get { return databaseConfigurationView.GetDatabaseProviderData(ConfigurationName); }
// }
///
/// When overridden in a derived class, gets the connection for this database.
///
///
///
/// The for this database.
///
public abstract IDbConnection GetConnection();
///
/// When overridden in a derived class, creates a for a stored procedure.
///
/// The name of the stored procedure.
/// The for the stored procedure.
//public abstract DBCommandWrapper GetStoredProcCommandWrapper(string storedProcedureName);
///
/// When overridden in a derived class, creates an for a stored procedure.
///
/// The name of the stored procedure.
/// The list of parameters for the procedure.
/// The for the stored procedure.
///
/// The parameters for the stored procedure will be discovered and the values are assigned in positional order.
///
//public abstract DBCommandWrapper GetStoredProcCommandWrapper(string storedProcedureName, params object[] parameterValues);
///
/// When overridden in a derived class, creates an for a SQL query.
///
/// The text of the query.
/// The for the SQL query.
public abstract DBCommandWrapper GetSqlStringCommandWrapper(string query);
///
/// When overridden in a derived class, creates a with the given update behavior and connection.
///
///
/// One of the values.
///
///
/// The open connection to the database.
///
/// An .
///
protected abstract DbDataAdapter GetDataAdapter(UpdateBehavior behavior, IDbConnection connection);
///
/// Execute the and add a new to the existing
///
///
/// The to execute.
///
///
/// The to load.
///
///
/// The name for the new to add to the .
///
///
/// Any input parameter was null
/// tableName was an empty string
public virtual void LoadDataSet(DBCommandWrapper command, DataSet dataSet, string tableName)
{
LoadDataSet(command, dataSet, new string[] {tableName});
}
///
/// Execute the within the given and add a new to the existing
///
///
/// The to execute.
///
///
/// The to load.
///
///
/// The name for the new to add to the .
///
///
/// The to execute the command within.
///
///
/// Any input parameter was null
/// tableName was an empty string
public virtual void LoadDataSet(DBCommandWrapper command, DataSet dataSet, string tableName, IDbTransaction transaction)
{
LoadDataSet(command, dataSet, new string[] {tableName}, transaction);
}
///
/// Load a from a .
///
///
/// The command to execute to fill the .
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
public virtual void LoadDataSet(DBCommandWrapper command, DataSet dataSet, string[] tableNames)
{
using (IDbConnection connection = GetConnection())
{
PrepareCommand(command, connection);
DoLoadDataSet(command, dataSet, tableNames);
}
}
///
/// Load a from a in a transaction.
///
///
/// The command to execute to fill the .
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
///
/// The to execute the command in.
///
public virtual void LoadDataSet(DBCommandWrapper command, DataSet dataSet, string[] tableNames, IDbTransaction transaction)
{
PrepareCommand(command, transaction);
DoLoadDataSet(command, dataSet, tableNames);
}
///
/// Load a from a
///
///
/// The stored procedure name to execute.
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
// public virtual void LoadDataSet(string storedProcedureName, DataSet dataSet, string[] tableNames, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// LoadDataSet(wrapper, dataSet, tableNames);
// }
// }
///
/// Load a from a stored procedure in a transaction.
///
///
/// The to execute the stored procedure in.
///
///
/// The stored procedure name to execute.
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
// public virtual void LoadDataSet(IDbTransaction transaction, string storedProcedureName, DataSet dataSet, string[] tableNames, object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// LoadDataSet(wrapper, dataSet, tableNames, transaction);
// }
// }
///
/// Load a from command text.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
public virtual void LoadDataSet(CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
LoadDataSet(wrapper, dataSet, tableNames);
}
}
///
/// Load a from command text in a transaction.
///
///
/// The to execute the command in.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The to fill.
///
///
/// An array of table name mappings for the .
///
public virtual void LoadDataSet(IDbTransaction transaction, CommandType commandType, string commandText, DataSet dataSet, string[] tableNames)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
LoadDataSet(wrapper, dataSet, tableNames, transaction);
}
}
///
/// Execute the and return the results in a new .
///
/// The to execute.
/// A with the results of the .
///
public virtual DataSet ExecuteDataSet(DBCommandWrapper command)
{
DataSet dataSet = new DataSet();
dataSet.Locale = CultureInfo.InvariantCulture;
LoadDataSet(command, dataSet, "Table");
return dataSet;
}
///
/// Execute the as part of the and return the results in a new .
///
/// The to execute.
///
/// The to execute the command within.
///
/// A with the results of the .
///
public virtual DataSet ExecuteDataSet(DBCommandWrapper command, IDbTransaction transaction)
{
DataSet dataSet = new DataSet();
dataSet.Locale = CultureInfo.InvariantCulture;
LoadDataSet(command, dataSet, "Table", transaction);
return dataSet;
}
///
/// Execute the with and return the results in a new .
///
///
/// The stored procedure to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// A with the results of the .
///
// public virtual DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteDataSet(wrapper);
// }
// }
///
/// Execute the ith as part of the and return the results in a new within a transaction.
///
///
/// The to execute the command within.
///
///
/// The stored procedure to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// A with the results of the .
///
// public virtual DataSet ExecuteDataSet(IDbTransaction transaction, string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteDataSet(wrapper, transaction);
// }
// }
///
/// Execute the interpreted as specified by the and return the results in a new .
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// A with the results of the .
///
public virtual DataSet ExecuteDataSet(CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteDataSet(wrapper);
}
}
///
/// Execute the as part of the given and return the results in a new .
///
///
/// The to execute the command within.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// A with the results of the .
///
public virtual DataSet ExecuteDataSet(IDbTransaction transaction, CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteDataSet(wrapper, transaction);
}
}
///
/// Executes the and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The command that contains the query to execute.
///
///
/// The first column of the first row in the resultset.
///
///
public virtual object ExecuteScalar(DBCommandWrapper command)
{
using (IDbConnection connection = OpenConnection())
{
PrepareCommand(command, connection);
return DoExecuteScalar(command);
}
}
///
/// Executes the within a , and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The command that contains the query to execute.
///
///
/// The to execute the command within.
///
///
/// The first column of the first row in the resultset.
///
///
public virtual object ExecuteScalar(DBCommandWrapper command, IDbTransaction transaction)
{
PrepareCommand(command, transaction);
return DoExecuteScalar(command);
}
///
/// Executes the with the given and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The stored procedure to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// The first column of the first row in the resultset.
///
///
// public virtual object ExecuteScalar(string storedProcedureName, params Object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteScalar(wrapper);
// }
// }
///
/// Executes the with the given within a
/// and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The to execute the command within.
///
///
/// The stored procedure to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// The first column of the first row in the resultset.
///
///
// public virtual object ExecuteScalar(IDbTransaction transaction, string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteScalar(wrapper, transaction);
// }
// }
///
/// Executes the interpreted as specified by the and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The first column of the first row in the resultset.
///
///
public virtual object ExecuteScalar(CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteScalar(wrapper);
}
}
///
/// Executes the interpreted as specified by the
/// within the given and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
///
///
/// The to execute the command within.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The first column of the first row in the resultset.
///
///
public virtual object ExecuteScalar(IDbTransaction transaction, CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteScalar(wrapper, transaction);
}
}
///
/// Executes the and returns the number of rows affected.
///
///
/// The command that contains the query to execute.
///
///
public virtual void ExecuteNonQuery(DBCommandWrapper command)
{
using (IDbConnection connection = OpenConnection())
{
PrepareCommand(command, connection);
DoExecuteNonQuery(command);
}
}
///
/// Executes the within the given , and returns the number of rows affected.
///
///
/// The command that contains the query to execute.
///
///
/// The to execute the command within.
///
///
public virtual void ExecuteNonQuery(DBCommandWrapper command, IDbTransaction transaction)
{
PrepareCommand(command, transaction);
DoExecuteNonQuery(command);
}
///
/// Executes the using the given and returns the number of rows affected.
///
///
/// The command that contains the query to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// The number of rows affected
///
///
// public virtual int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// ExecuteNonQuery(wrapper);
// return wrapper.RowsAffected;
// }
// }
///
/// Executes the using the given within a transaction and returns the number of rows affected.
///
///
/// The to execute the command within.
///
///
/// The command that contains the query to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// The number of rows affected
///
///
// public virtual int ExecuteNonQuery(IDbTransaction transaction, string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// ExecuteNonQuery(wrapper, transaction);
//
// return wrapper.RowsAffected;
// }
// }
///
/// Execute the interpreted as specified by the and return the number of rows affected.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The number of rows affected
///
///
public virtual int ExecuteNonQuery(CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
ExecuteNonQuery(wrapper);
return wrapper.RowsAffected;
}
}
///
/// Execute the interpreted as specified by the as part of the given and return the number of rows affected.
///
///
/// The to execute the command within.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// The number of rows affected
///
///
public virtual int ExecuteNonQuery(IDbTransaction transaction, CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
ExecuteNonQuery(wrapper, transaction);
return wrapper.RowsAffected;
}
}
///
/// Executes the and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// The command that contains the query to execute.
///
///
/// An object.
///
///
public virtual IDataReader ExecuteReader(DBCommandWrapper command)
{
IDbConnection connection = OpenConnection();
PrepareCommand(command, connection);
try
{
return DoExecuteReader(command.Command, CommandBehavior.CloseConnection);
}
catch
{
connection.Close();
throw;
}
}
///
/// Executes the within a transaction and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// The command that contains the query to execute.
///
///
/// The to execute the command within.
///
///
/// An object.
///
///
public virtual IDataReader ExecuteReader(DBCommandWrapper command, IDbTransaction transaction)
{
PrepareCommand(command, transaction);
return DoExecuteReader(command.Command, CommandBehavior.Default);
}
///
/// Executes the with the given and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// The command that contains the query to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// An object.
///
///
// public IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteReader(wrapper);
// }
// }
///
/// Executes the with the given within the given and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// The to execute the command within.
///
///
/// The command that contains the query to execute.
///
///
/// An array of paramters to pass to the stored procedure. The parameter values must be in call order as they appear in the stored procedure.
///
///
/// An object.
///
///
// public IDataReader ExecuteReader(IDbTransaction transaction, string storedProcedureName, params object[] parameterValues)
// {
// using (DBCommandWrapper wrapper = GetStoredProcCommandWrapper(storedProcedureName, parameterValues))
// {
// return ExecuteReader(wrapper, transaction);
// }
// }
///
/// Execute the interpreted as specified by the and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// An object.
///
///
public IDataReader ExecuteReader(CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteReader(wrapper);
}
}
///
/// Execute the interpreted as specified by the within the given
/// and returns an through which the result can be read.
/// It is the responsibility of the caller to close the connection and reader when finished.
///
///
/// The to execute the command within.
///
///
/// One of the values.
///
///
/// The command text to execute.
///
///
/// An object.
///
///
public IDataReader ExecuteReader(IDbTransaction transaction, CommandType commandType, string commandText)
{
using (DBCommandWrapper wrapper = CreateCommandWrapperByCommandType(commandType, commandText))
{
return ExecuteReader(wrapper, transaction);
}
}
///
/// Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the .
///
/// The used to update the data source.
/// The name of the source table to use for table mapping.
/// The executed when is
/// The executed when is
/// The executed when is
/// One of the values.
/// number of records affected
///
public virtual int UpdateDataSet(DataSet dataSet, string tableName,
DBCommandWrapper insertCommand, DBCommandWrapper updateCommand,
DBCommandWrapper deleteCommand, UpdateBehavior updateBehavior)
{
using (IDbConnection connection = OpenConnection())
{
if (updateBehavior == UpdateBehavior.Transactional)
{
IDbTransaction trans = BeginTransaction(connection);
try
{
int rowsAffected = UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, trans);
CommitTransaction(trans);
return rowsAffected;
}
catch
{
RollbackTransaction(trans);
throw;
}
}
else
{
if (insertCommand != null)
{
PrepareCommand(insertCommand, connection);
}
if (updateCommand != null)
{
PrepareCommand(updateCommand, connection);
}
if (deleteCommand != null)
{
PrepareCommand(deleteCommand, connection);
}
return DoUpdateDataSet(updateBehavior, connection, dataSet, tableName,
insertCommand, updateCommand, deleteCommand);
}
}
}
///
/// Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the within a transaction.
///
/// The used to update the data source.
/// The name of the source table to use for table mapping.
/// The executed when is
/// The executed when is
/// The executed when is
/// The to use.
/// number of records affected
///
public virtual int UpdateDataSet(DataSet dataSet, string tableName,
DBCommandWrapper insertCommand, DBCommandWrapper updateCommand,
DBCommandWrapper deleteCommand, IDbTransaction transaction)
{
if (insertCommand != null)
{
PrepareCommand(insertCommand, transaction);
}
if (updateCommand != null)
{
PrepareCommand(updateCommand, transaction);
}
if (deleteCommand != null)
{
PrepareCommand(deleteCommand, transaction);
}
return DoUpdateDataSet(UpdateBehavior.Transactional, transaction.Connection,
dataSet, tableName, insertCommand, updateCommand, deleteCommand);
}
///
/// Clears the parameter cache. Since there is only one parameter cache that is shared by all instances
/// of this class, this clears all parameters cached for all databases.
///
public void ClearParameterCache()
{
parameterCache.Clear();
}
///
/// Assigns a to the and discovers parameters if needed.
///
/// The command that contains the query to prepare.
/// The connection to assign to the command.
protected void PrepareCommand(DBCommandWrapper command, IDbConnection connection)
{
ArgumentValidation.CheckForNullReference(command, "command");
ArgumentValidation.CheckForNullReference(connection, "connection");
command.Command.Connection = connection;
if (command.IsFurtherPreparationNeeded())
{
parameterCache.FillParameters(command, ParameterToken);
}
}
///
/// Assigns a to the and discovers parameters if needed.
///
/// The command that contains the query to prepare.
/// The transaction to assign to the command.
protected void PrepareCommand(DBCommandWrapper command, IDbTransaction transaction)
{
ArgumentValidation.CheckForNullReference(command, "command");
ArgumentValidation.CheckForNullReference(transaction, "transaction");
command.Command.Transaction = transaction;
PrepareCommand(command, transaction.Connection);
}
///
/// Open a connection.
///
/// The opened connection.
protected IDbConnection OpenConnection()
{
IDbConnection connection = GetConnection();
try
{
connection.Open();
return connection;
}
catch
{
throw;
}
}
private DBCommandWrapper CreateCommandWrapperByCommandType(CommandType commandType, string commandText)
{
DBCommandWrapper wrapper = null;
switch (commandType)
{
case CommandType.StoredProcedure:
throw new ApplicationException("GZTWDatabase:CreateCommandWrapperByCommandType() STORED PROCEDURE NOT SUPPORTED");
case CommandType.Text:
wrapper = GetSqlStringCommandWrapper(commandText);
break;
}
if (wrapper == null)
{
throw new ArgumentException(SR.ExceptionCommandTypeNotValid, "commandType");
}
return wrapper;
}
private int DoUpdateDataSet(UpdateBehavior behavior, IDbConnection connection,
DataSet dataSet, string tableName, DBCommandWrapper insertCommand,
DBCommandWrapper updateCommand, DBCommandWrapper deleteCommand)
{
ArgumentValidation.CheckForNullReference(dataSet, "dataSet");
ArgumentValidation.CheckForNullReference(tableName, "tableName");
ArgumentValidation.CheckForEmptyString(tableName, "tableName");
if (insertCommand == null && updateCommand == null && deleteCommand == null)
{
throw new ArgumentException(SR.ExceptionMessageUpdateDataSetArgumentFailure);
}
using (DbDataAdapter adapter = GetDataAdapter(behavior, connection))
{
IDbDataAdapter explicitAdapter = (IDbDataAdapter) adapter;
if (insertCommand != null)
{
explicitAdapter.InsertCommand = insertCommand.Command;
}
if (updateCommand != null)
{
explicitAdapter.UpdateCommand = updateCommand.Command;
}
if (deleteCommand != null)
{
explicitAdapter.DeleteCommand = deleteCommand.Command;
}
try
{
int rows = adapter.Update(dataSet.Tables[tableName]);
return rows;
}
catch
{
throw;
}
}
}
private void DoLoadDataSet(DBCommandWrapper command, DataSet dataSet, string[] tableNames)
{
ArgumentValidation.CheckForNullReference(tableNames, "tableNames");
if (tableNames.Length == 0)
{
throw new ArgumentException(SR.ExceptionTableNameArrayEmpty, "tableNames");
}
for (int i = 0; i < tableNames.Length; i++)
{
ArgumentValidation.CheckForNullReference(tableNames[i], string.Concat("tableNames[", i, "]"));
ArgumentValidation.CheckForEmptyString(tableNames[i], string.Concat("tableNames[", i, "]"));
}
using (DbDataAdapter adapter = GetDataAdapter(UpdateBehavior.Standard, command.Command.Connection))
{
((IDbDataAdapter) adapter).SelectCommand = command.Command;
try
{
string systemCreatedTableNameRoot = "Table";
for (int i = 0; i < tableNames.Length; i++)
{
string systemCreatedTableName = (i == 0)
? systemCreatedTableNameRoot
: systemCreatedTableNameRoot + i;
adapter.TableMappings.Add(systemCreatedTableName, tableNames[i]);
}
adapter.Fill(dataSet);
}
catch
{
throw;
}
}
}
private object DoExecuteScalar(DBCommandWrapper command)
{
try
{
object returnValue = command.Command.ExecuteScalar();
return returnValue;
}
catch
{
throw;
}
}
private void DoExecuteNonQuery(DBCommandWrapper command)
{
try
{
command.RowsAffected = command.Command.ExecuteNonQuery();
}
catch
{
throw;
}
}
private IDataReader DoExecuteReader(IDbCommand command, CommandBehavior cmdBehavior)
{
try
{
IDataReader reader = command.ExecuteReader(cmdBehavior);
return reader;
}
catch/*(Exception ex)*/
{
throw;
}
}
private IDbTransaction BeginTransaction(IDbConnection connection)
{
try
{
IDbTransaction tran = connection.BeginTransaction();
return tran;
}
catch
{
throw;
}
}
private void RollbackTransaction(IDbTransaction tran)
{
tran.Rollback();
}
private void CommitTransaction(IDbTransaction tran)
{
tran.Commit();
}
}
}