예제 #1
0
        public IDbConnection Get(IRelational relational, Func <IDbConnection> newConnection)
        {
            if (relational == null)
            {
                throw new ArgumentNullException("relational");
            }
            if (newConnection == null)
            {
                throw new ArgumentNullException("newConnection");
            }
            else
            {
                this._newConnection = newConnection;
            }
            IDbConnection connection = null;

            if (!this._connections.TryGetValue(relational, out connection))
            {
                connection = newConnection();
                if (!DatabaseAccessAuxiliary.TryConnectConnection(connection))
                {
                    DatabaseAccessAuxiliary.CloseConnection(connection);
                    connection = null;
                }
                else
                {
                    relational.Disposed += this._closeRelationalEvt;
                    this._connections.Add(relational, connection);
                }
            }
            return(connection);
        }
예제 #2
0
        public virtual IDbConnection Remove(IRelational relational)
        {
            if (relational == null)
            {
                throw new ArgumentNullException("relational");
            }
            IDbConnection connection = null;

            if (this._connections.TryGetValue(relational, out connection))
            {
                relational.Disposed -= this._closeRelationalEvt;
                this._connections.Remove(relational);
            }
            DatabaseAccessAuxiliary.CloseConnection(connection);
            return(connection);
        }