Ejemplo n.º 1
0
        public static DatabaseConnectionWrapper GetConnection(Database db)
        {
            Transaction currentTransaction = Transaction.Current;

            if (currentTransaction == null)
            {
                return(null);
            }

            Dictionary <string, DatabaseConnectionWrapper> connectionList;
            DatabaseConnectionWrapper connection;

            lock (transactionConnections)
            {
                if (!transactionConnections.TryGetValue(currentTransaction, out connectionList))
                {
                    connectionList = new Dictionary <string, DatabaseConnectionWrapper>();
                    transactionConnections.Add(currentTransaction, connectionList);
                    currentTransaction.TransactionCompleted += OnTransactionCompleted;
                }
            }

            lock (connectionList)
            {
                if (!connectionList.TryGetValue(db.ConnectionString, out connection))
                {
                    var dbConnection = db.GetNewConnection();
                    connection = new DatabaseConnectionWrapper(dbConnection);
                    connectionList.Add(db.ConnectionString, connection);
                }
                connection.AddRef();
            }
            return(connection);
        }
        public static DatabaseConnectionWrapper GetConnection(Database db)
        {
            Transaction currentTransaction = Transaction.Current;
            if (currentTransaction == null)
                return null;

            Dictionary<string, DatabaseConnectionWrapper> connectionList;
            DatabaseConnectionWrapper connection;
            lock (transactionConnections)
            {
                if (!transactionConnections.TryGetValue(currentTransaction, out connectionList))
                {
                    connectionList = new Dictionary<string, DatabaseConnectionWrapper>();
                    transactionConnections.Add(currentTransaction, connectionList);
                    currentTransaction.TransactionCompleted += OnTransactionCompleted;
                }
            }

            lock (connectionList)
            {
                if (!connectionList.TryGetValue(db.ConnectionString, out connection))
                {
                    var dbConnection = db.GetNewConnection();
                    connection = new DatabaseConnectionWrapper(dbConnection);
                    connectionList.Add(db.ConnectionString, connection);
                }
                connection.AddRef();
            }
            return connection;
        }
Ejemplo n.º 3
0
 public virtual IDataReader ExecuteReader(DbCommand command)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     using (DatabaseConnectionWrapper wrapper = GetOpenConnection())
     {
         PrepareCommand(command, wrapper.DbConnection);
         IDataReader reader = DoExecuteReader(command, CommandBehavior.Default);
         return(CreateWrapperReader(wrapper, reader));
     }
 }
Ejemplo n.º 4
0
 public RefCountingDataReader(DatabaseConnectionWrapper connection, IDataReader innerReader)
     : base(innerReader)
 {
     connectionWrapper = connection;
     connectionWrapper.AddRef();
 }
Ejemplo n.º 5
0
 public RefCountingDataReader(DatabaseConnectionWrapper connection, IDataReader innerReader)
     : base(innerReader)
 {
     connectionWrapper = connection;
     connectionWrapper.AddRef();
 }
Ejemplo n.º 6
0
 protected virtual IDataReader CreateWrapperReader(DatabaseConnectionWrapper wrapper, IDataReader innerReader)
 {
     return new RefCountingDataReader(wrapper, innerReader);
 }
Ejemplo n.º 7
0
        protected DatabaseConnectionWrapper GetOpenConnection()
        {
            DatabaseConnectionWrapper con = TransactionScopeConnections.GetConnection(this);

            return(con ?? GetWrappedConnection());
        }
Ejemplo n.º 8
0
 protected virtual IDataReader CreateWrapperReader(DatabaseConnectionWrapper wrapper, IDataReader innerReader)
 {
     return(new RefCountingDataReader(wrapper, innerReader));
 }