private static void InnerExecuteQuery <T>(GenericRecordList <T> rl, IDbCommand command, string description, bool transformParameters) where T : ITypedRecord <T>
        {
            IDbCommand cmd = ADOAdaptersUtils.GetADOCommand(command);
            IDatabaseAccessProvider provider = DatabaseAccess.GetProviderForTransaction(cmd.Transaction);

            provider.ExecuteQuery(new ManagedCommand(provider.TransactionManager, cmd), rl, description, transformParameters, false);
        }
        public static int ExecuteNonQueryDontCleanParameters(IDbCommand command, string description, bool isApplication, bool skipLog)
        {
            IDbCommand cmd            = ADOAdaptersUtils.GetADOCommand(command);
            Command    wrapperCommand = new Command(GetExecutionForConnection(cmd.Connection), cmd);

            return(wrapperCommand.ExecuteNonQueryWithoutTransformParametersSyntax(description, isApplication, skipLog));
        }
        public static object ExecuteScalarDontCleanParameters(IDbCommand command, bool skipLog)
        {
            IDbCommand cmd            = ADOAdaptersUtils.GetADOCommand(command);
            Command    wrapperCommand = new Command(GetExecutionForConnection(cmd.Connection), cmd);

            return(wrapperCommand.ExecuteScalarWithoutTransformParametersSyntax(skipLog));
        }
        public static DataSet CreateAndFillDataSet(IDbCommand command, IDbDataAdapter adapter, string description, bool isApplication)
        {
            // Save the values before execution because sometimes the drivers clears them from the IDbCommand when an exception occurs
            IDbCommand     cmd   = ADOAdaptersUtils.GetADOCommand(command);
            IDbConnection  conn  = cmd.Connection;
            IDbTransaction trans = cmd.Transaction;

            IDatabaseAccessProvider provider = null;
            bool hasProvider = trans != null && DatabaseAccess.TryGetProviderForTransaction(trans, out provider);

            IExecutionService   executionService = hasProvider ? provider.DatabaseServices.ExecutionService : GetExecutionForConnection(conn);
            ITransactionManager manager          = provider.TransactionManager;

            try {
                DataSet dataSet;

                {
                    dataSet = new DataSet();
                    adapter.SelectCommand = cmd;
                    adapter.Fill(dataSet);
                }
                return(dataSet);
            } catch (DbException e) {
                executionService.OnExecuteException(e, cmd, null, conn, trans, manager);
                throw;
            }
        }
        public static IDataReader ExecuteReader(IDbCommand command, string description, bool isApplication, bool transformParameters, bool skipLog)
        {
            try {
                // Save the values before execution because sometimes the drivers clears them from the IDbCommand when an exception occurs
                IDbCommand     cmd   = ADOAdaptersUtils.GetADOCommand(command);
                IDbConnection  conn  = cmd.Connection;
                IDbTransaction trans = cmd.Transaction;

                IDatabaseAccessProvider provider = null;
                bool hasProvider = trans != null && DatabaseAccess.TryGetProviderForTransaction(trans, out provider);

                IExecutionService   executionService = hasProvider ? provider.DatabaseServices.ExecutionService : GetExecutionForConnection(conn);
                ITransactionManager manager          = provider.TransactionManager;

                IDataReader reader = null;
                try {
                    if (transformParameters)
                    {
                        TransformParameters(cmd);
                    }
                    reader = executionService.ExecuteReader(cmd);
                    // NOTE: This reader will be closed automatically by the transaction manager at the end of the request
                    manager.AssociateReader(trans, reader);
                } catch (DbException e) {
                    executionService.OnExecuteException(e, cmd, reader, conn, trans, manager);
                    throw;
                }
                return(reader);
            } catch (InvalidDatabaseAccessException e) {
                throw new InvalidDBTransactionManagerAccess(e.Message);
            }
        }
        public void CloseTransaction(IDbTransaction transaction)
        {
            IDbTransaction    trans            = ADOAdaptersUtils.GetADOTransaction(transaction);
            IDatabaseServices databaseServices = DBHelper.GetDatabaseServicesForConnection(trans.Connection);

            databaseServices.TransactionService.CloseTransaction(trans);
        }
        public static bool isConnectedUser(IDbTransaction transaction, string userName)
        {
            IDbTransaction    trans            = ADOAdaptersUtils.GetADOTransaction(transaction);
            IDatabaseServices databaseServices = DBHelper.GetDatabaseServicesForConnection(trans.Connection);

            return(DBCompatibilityReflectionUtils.IsConnectedUser(transaction.Connection, userName, databaseServices.ExecutionService));
        }
        public IDbTransaction CreateTransaction(string connectionName, string connectionString)
        {
            try {
                if (!String.IsNullOrEmpty(connectionName))
                {
                    IDatabaseServices databaseServices = AdaptersUtils.GetDatabaseServices(GetDatabaseKind(connectionName),
                                                                                           new ConnectionString(connectionString));

                    ITransactionManager baseTransactionManager = GetProviderFromConnectionNameOrMain(connectionName).TransactionManager;
                    ITransactionService transactionService     = databaseServices.TransactionService;

                    IDbConnection connection = transactionService.CreateConnection();

                    return(ADOAdaptersUtils.AdapterTransaction(transactionService.CreateTransaction(connection)));
                }
                else
                {
                    return(CreateTransaction(connectionString));
                }
            } catch (ConnectionNotFoundException e) {
                throw new DBConnectionNotFoundException(e.Message);
            } catch (InvalidDatabaseAccessException e) {
                throw new InvalidDBTransactionManagerAccess(e.Message);
            } catch (InvalidTransactionReleaseException e) {
                throw new InvalidReleaseException(e.Message);
            }
        }
Beispiel #9
0
 public IDbTransaction GetReadOnlyTransaction()
 {
     try {
         return(ADOAdaptersUtils.AdapterTransaction(TransactionManager.GetReadOnlyTransaction()));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public virtual IDbTransaction GetPrivateTransaction()
 {
     try {
         return(ADOAdaptersUtils.AdapterTransaction(DBAccess.MainProvider.GetCommitableTransaction().DriverTransaction));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public void CleanParameterSyntax(IDbCommand command)
 {
     try {
         IDbCommand cmd = ADOAdaptersUtils.GetADOCommand(command);
         DBHelper.TransformParameters(cmd);
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public static IDbCommand CreateCommand(IDbTransaction transaction)
 {
     try {
         IDbTransaction trans = ADOAdaptersUtils.GetADOTransaction(transaction);
         return(ADOAdaptersUtils.AdapterCommand(GetExecutionForConnection(trans.Connection).CreateCommand(trans, "")));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public virtual void RollbackTransaction(IDbTransaction transaction)
 {
     try {
         IDbTransaction trans = ADOAdaptersUtils.GetADOTransaction(transaction);
         GetProviderFromConnectionNameOrMain(null).TransactionManager.RollbackTransaction(trans);
     } catch (InvalidCommitOrRollbackTransactionException e) {
         throw new InvalidCommitOrRollbackException(e.Message);
     }
 }
Beispiel #14
0
 public IDbTransaction CreateTransaction(ConnectionString connectionString)
 {
     try {
         IDatabaseServices databaseServices = AdaptersUtils.GetDatabaseServices(DatabaseKind, connectionString);
         return(ADOAdaptersUtils.AdapterTransaction(databaseServices.TransactionService.CreateTransaction(GetConnection(connectionString))));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public static IDbCommand CreateCommand(IDbConnection connection, string sql)
 {
     try {
         DatabaseConnection conn = new DatabaseConnection(GetExecutionForConnection(connection).DatabaseServices, connection);
         return(ADOAdaptersUtils.AdapterCommand(conn.CreateCommand(sql).DriverCommand));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public static int ExecuteNonQuery(IDbCommand command, bool skipLog)
 {
     try {
         IDbCommand cmd            = ADOAdaptersUtils.GetADOCommand(command);
         Command    wrappedCommand = new Command(GetExecutionForConnection(cmd.Connection), cmd);
         return(wrappedCommand.ExecuteNonQuery(skipLog));
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
        public static IDbDataParameter AddParameter(IDbCommand cmd, string name, DbType dbType, object paramValue, DBKind dbKind, bool magicReplace)
        {
            IExecutionService executionService = GetExecutionForKind(dbKind);

            if (magicReplace)
            {
                paramValue = executionService.TransformRuntimeToDatabaseValue(dbType, paramValue);
            }
            return(ADOAdaptersUtils.AdapterParameter(executionService.CreateParameter(ADOAdaptersUtils.GetADOCommand(cmd), name, dbType, paramValue)));
        }
 public static object ExecuteScalar(IDbCommand command)
 {
     try {
         IDbCommand cmd            = ADOAdaptersUtils.GetADOCommand(command);
         Command    wrapperCommand = new Command(GetExecutionForConnection(cmd.Connection), cmd);
         return(wrapperCommand.ExecuteScalar());
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public IDbTransaction GetPrivateTransaction(string connectionName)
 {
     try {
         return(ADOAdaptersUtils.AdapterTransaction(GetProviderFromConnectionNameOrMain(connectionName).TransactionManager.GetCommitableTransaction()));
     } catch (ConnectionNotFoundException e) {
         throw new DBConnectionNotFoundException(e.Message);
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     } catch (InvalidTransactionReleaseException e) {
         throw new InvalidReleaseException(e.Message);
     }
 }
 public static IDataReader ExecuteStoredProcedure(IDbCommand command, DBKind dbKind, string readerVarName, bool skipLog)
 {
     try {
         IDbCommand cmd = ADOAdaptersUtils.GetADOCommand(command);
         TransformParameters(cmd);
         IDataReader reader = GetExecutionForKind(dbKind).ExecuteStoredProcedureWithResultSet(cmd, readerVarName);
         DatabaseAccess.GetProviderForTransaction(cmd.Transaction).TransactionManager.AssociateReader(cmd.Transaction, reader);
         return(reader);
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     }
 }
 public void ReleaseTransaction(string connectionName, IDbTransaction transaction)
 {
     try {
         IDbTransaction trans = ADOAdaptersUtils.GetADOTransaction(transaction);
         GetProviderFromConnectionNameOrMain(connectionName).TransactionManager.ReleaseTransaction(trans);
     } catch (ConnectionNotFoundException e) {
         throw new DBConnectionNotFoundException(e.Message);
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     } catch (InvalidTransactionReleaseException e) {
         throw new InvalidReleaseException(e.Message);
     }
 }
        public static IDbDataParameter AddParameterWithDirection(IDbCommand command, string name, DbType dbType, ParameterDirection direction)
        {
            try {
                Command cmd = new Command(DatabaseAccess.ForSystemDatabase.DatabaseServices.ExecutionService, ADOAdaptersUtils.GetADOCommand(command));

                return(ADOAdaptersUtils.AdapterParameter(cmd.CreateParameterWithDirection(name, dbType, direction).DriverParameter));
            } catch (ConnectionNotFoundException e) {
                throw new DBConnectionNotFoundException(e.Message);
            } catch (InvalidDatabaseAccessException e) {
                throw new InvalidDBTransactionManagerAccess(e.Message);
            } catch (InvalidTransactionReleaseException e) {
                throw new InvalidReleaseException(e.Message);
            }
        }
        public bool isConnectedUser(string userName)
        {
            try {
                using (Transaction requestTransaction = DBAccess.MainProvider.GetRequestTransaction()) {
                    // ReSharper disable once JoinDeclarationAndInitializer

                    IDbTransaction trans;
                    trans = ADOAdaptersUtils.AdapterTransaction(requestTransaction.DriverTransaction);
                    return(isConnectedUser(trans, userName));
                }
            } catch (InvalidDatabaseAccessException e) {
                throw new InvalidDBTransactionManagerAccess(e.Message);
            }
        }
 public IDbDataParameter AddParameter(string connectionName, IDbCommand command, string name, DbType dbType, object paramValue)
 {
     try {
         IDbCommand        cmd = ADOAdaptersUtils.GetADOCommand(command);
         IDatabaseServices databaseServices = GetProviderFromConnectionNameOrMain(connectionName).DatabaseServices;
         Command           wrappedCommand   = new Command(databaseServices.ExecutionService, cmd);
         return(ADOAdaptersUtils.AdapterParameter(wrappedCommand.CreateParameter(name, dbType, paramValue).DriverParameter));
     } catch (ConnectionNotFoundException e) {
         throw new DBConnectionNotFoundException(e.Message);
     } catch (InvalidDatabaseAccessException e) {
         throw new InvalidDBTransactionManagerAccess(e.Message);
     } catch (InvalidTransactionReleaseException e) {
         throw new InvalidReleaseException(e.Message);
     }
 }
        public static void SetParamDirection(IDbDataParameter parameter, ParameterDirection direction)
        {
            IDbDataParameter  param          = ADOAdaptersUtils.GetADOParameter(parameter);
            IExecutionService executionToUse = GetExecutionForKind(DBKind.Oracle);

            {
                Assembly oracleClient        = Assembly.Load("Oracle.ManagedDataAccess.Client");
                Type     oracleParameterType = oracleClient.GetType("Oracle.ManagedDataAccess.Client.OracleParameter");

                if (!oracleParameterType.IsInstanceOfType(param))
                {
                    executionToUse = GetExecutionForKind(DBKind.SqlServer);
                }
            }

            executionToUse.SetParameterDirection(param, direction);
        }
Beispiel #26
0
        public virtual IDbDataParameter AddParameter(IDbCommand cmd, string name, DbType dbType, object paramValue)
        {
            Command command = new Command(TransactionManager.TransactionService.DatabaseServices.ExecutionService, cmd);

            return(ADOAdaptersUtils.AdapterParameter(command.CreateParameter(name, dbType, paramValue).DriverParameter));
        }
        public static IDbDataParameter AddParameter(IDbCommand cmd, string name, DbType dbType, ObjectKey key, DBKind dbKind)
        {
            Command command = new Command(GetExecutionForKind(dbKind).DatabaseServices.ExecutionService, ADOAdaptersUtils.GetADOCommand(cmd));

            return(ADOAdaptersUtils.AdapterParameter(command.CreateParameter(name, dbType, key).DriverParameter));
        }
 public void AssociateReader(IDbTransaction trans, IDataReader reader, string schema)
 {
     DBAccess.InnerGetProviderForTransaction(ADOAdaptersUtils.GetADOTransaction(trans), schema).TransactionManager.AssociateReader(ADOAdaptersUtils.GetADOTransaction(trans), reader);
 }