ConnectionPool object used internall by the patio.Database class;

Constructor

Defined ConnectionPool.js Source
  1. function (options){
  2. options = options || {};
  3. if (!options.createConnection || !isFunction(options.createConnection)) {
  4. throw new Error("patio.adapters.clients.ConnectionPool : create connection CB required.");
  5. }
  6. if (!options.closeConnection || !isFunction(options.closeConnection)) {
  7. throw new Error("patio.adapters.clients.ConnectionPool : close connection CB required.");
  8. }
  9. options.minObjects = parseInt(options.minConnections || 0, 10);
  10. options.maxObjects = parseInt(options.maxConnections || 10, 10);
  11. this.__deferredQueue = new Queue();
  12. this._options = options;
  13. this.__createConnectionCB = options.createConnection;
  14. this.__closeConnectionCB = options.closeConnection;
  15. this.__validateConnectionCB = options.validateConnection;
  16. this._super(arguments);
  17. }

__checkQueries Function Private


Defined ConnectionPool.js

Checks all deferred connection requests.

Source
  1. function (){
  2. var fc = this.freeCount, def, defQueue = this.__deferredQueue;
  3. while (fc-- >= 0 && defQueue.count) {
  4. def = defQueue.dequeue();
  5. var conn = this.getObject();
  6. if (conn) {
  7. def.callback(conn);
  8. } else {
  9. throw new Error("UNEXPECTED ERROR");
  10. }
  11. fc--;
  12. }
  13. }

closeConnection Function Public


Defined ConnectionPool.js

Override to implement close connection functionality;

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

createConnection Function Public


Defined ConnectionPool.js

Override to create connections to insert into this ConnectionPool.

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

endAll Function Public


Defined ConnectionPool.js

Override to implement the closing of all connections.

Returns Source
  1. function (){
  2. this.__ending = true;
  3. var conn, fQueue = this.__freeObjects, count = this.count, ps = [];
  4. while ((conn = this.__freeObjects.dequeue()) !== undefined) {
  5. ps.push(this.closeConnection(conn));
  6. }
  7. var inUse = this.__inUseObjects;
  8. for (var i = inUse.length - 1; i >= 0; i--) {
  9. ps.push(this.closeConnection(inUse[i]));
  10. }
  11. this.__inUseObjects.length = 0;
  12. return new PromiseList(ps).promise();
  13. }

getConnection Function Public


Defined ConnectionPool.js

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

Returns Source
  1. function (){
  2. var ret = new Promise(), conn;
  3. if (this.count > this.__maxObjects) {
  4. this.__deferredQueue.enqueue(ret);
  5. } else {
  6. //todo override getObject to make async so creating a connetion can execute setup sql
  7. conn = this.getObject();
  8. if (!conn) {
  9. //we need to deffer it
  10. this.__deferredQueue.enqueue(ret);
  11. } else {
  12. ret.callback(conn);
  13. }
  14. }
  15. if (this.count > this.__maxObjects && !conn) {
  16. ret.errback(new Error("Unexpected ConnectionPool error"));
  17. }
  18. return ret.promise();
  19. }

removeConnection Function Public


Defined ConnectionPool.js

Removes a connection from the pool.

Arguments Source
  1. function (conn){
  2. this.closeConnection(conn);
  3. return this.removeObject(conn);
  4. }

returnConnection Function Public


Defined ConnectionPool.js

Return a connection to the pool.

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

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
  1. function (obj){
  2. var self = this;
  3. this.validate(obj).chain(function (valid) {
  4. var index;
  5. if (self.count <= self.__maxObjects && valid && (index = self.__inUseObjects.indexOf(obj)) > -1) {
  6. self.__inUseObjects.splice(index, 1);
  7. self.__freeObjects.enqueue(obj);
  8. self.__checkQueries();
  9. } else {
  10. self.removeObject(obj);
  11. }
  12. });
  13. }

validate Function Public


Defined ConnectionPool.js

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

Arguments Returns Source
  1. function (conn){
  2. if (!this.__validateConnectionCB) {
  3. var ret = new Promise();
  4. ret.callback(true);
  5. return ret;
  6. } else {
  7. return this.__validateConnectionCB(conn);
  8. }
  9. }

Documentation generated using coddoc.