ConnectionPool object used internall by the patio.Database class;

Constructor

Defined ConnectionPool.js Source
function (options){
   options = options || {};
   if (!options.createConnection || !isFunction(options.createConnection)) {
       throw new Error("patio.adapters.clients.ConnectionPool : create connection CB required.");
   }
   if (!options.closeConnection || !isFunction(options.closeConnection)) {
       throw new Error("patio.adapters.clients.ConnectionPool : close connection CB required.");
   }
   options.minObjects = parseInt(options.minConnections || 0, 10);
   options.maxObjects = parseInt(options.maxConnections || 10, 10);
   this.__deferredQueue = new Queue();
   this._options = options;
   this.__createConnectionCB = options.createConnection;
   this.__closeConnectionCB = options.closeConnection;
   this.__validateConnectionCB = options.validateConnection;
   this._super(arguments);
           
}
            

__checkQueries Function Private


Defined ConnectionPool.js

Checks all deferred connection requests.

Source
function (){
   var fc = this.freeCount, def, defQueue = this.__deferredQueue;
   while (fc-- >= 0 && defQueue.count) {
       def = defQueue.dequeue();
       var conn = this.getObject();
       if (conn) {
           def.callback(conn);
       } else {
           throw new Error("UNEXPECTED ERROR");
       }
       fc--;
   }
           
}
    

closeConnection Function Public


Defined ConnectionPool.js

Override to implement close connection functionality;

Arguments Returns Source
function (conn){
   return this.__closeConnectionCB(conn);
           
}
    

createConnection Function Public


Defined ConnectionPool.js

Override to create connections to insert into this ConnectionPool.

Source
function (){
   return this.__createConnectionCB(this._options);
           
}
    

endAll Function Public


Defined ConnectionPool.js

Override to implement the closing of all connections.

Returns Source
function (){
   this.__ending = true;
   var conn, fQueue = this.__freeObjects, count = this.count, ps = [];
   while ((conn = this.__freeObjects.dequeue()) !== undefined) {
       ps.push(this.closeConnection(conn));
   }
   var inUse = this.__inUseObjects;
   for (var i = inUse.length - 1; i >= 0; i--) {
       ps.push(this.closeConnection(inUse[i]));
   }
   this.__inUseObjects.length = 0;
   return new PromiseList(ps).promise();
           
}
    

getConnection Function Public


Defined ConnectionPool.js

Performs a query on one of the connection in this Pool.

Returns Source
function (){
   var ret = new Promise(), conn;
   if (this.count > this.__maxObjects) {
       this.__deferredQueue.enqueue(ret);
   } else {
       //todo override getObject to make async so creating a connetion can execute setup sql
       conn = this.getObject();
       if (!conn) {
           //we need to deffer it
           this.__deferredQueue.enqueue(ret);
       } else {
           ret.callback(conn);
       }
   }
   if (this.count > this.__maxObjects && !conn) {
       ret.errback(new Error("Unexpected ConnectionPool error"));
   }
   return ret.promise();
           
}
    

removeConnection Function Public


Defined ConnectionPool.js

Removes a connection from the pool.

Arguments Source
function (conn){
   this.closeConnection(conn);
   return this.removeObject(conn);
           
}
    

returnConnection Function Public


Defined ConnectionPool.js

Return a connection to the pool.

Arguments Returns Source
function (connection){
   this.returnObject(connection);
           
}
    

returnObject Function Public


Defined ConnectionPool.js

Override comb.collections.Pool to allow async validation to allow pools to do any calls to reset a connection if it needs to be done.

Arguments Source
function (obj){
   var self = this;
   this.validate(obj).chain(function (valid) {
       var index;
       if (self.count <= self.__maxObjects && valid && (index = self.__inUseObjects.indexOf(obj)) > -1) {
           self.__inUseObjects.splice(index, 1);
           self.__freeObjects.enqueue(obj);
           self.__checkQueries();
       } else {
           self.removeObject(obj);
       }
   });
           
}
    

validate Function Public


Defined ConnectionPool.js

Override to provide any additional validation. By default the promise is called back with true.

Arguments Returns Source
function (conn){
   if (!this.__validateConnectionCB) {
       var ret = new Promise();
       ret.callback(true);
       return ret;
   } else {
       return this.__validateConnectionCB(conn);
   }
           
}
    

Documentation generated using coddoc.