不要怂,就是干,撸起袖子干!

Commit a9b6d98c by Sascha Depold

the connector manager is now a part of the transaction manager

1 parent bccd3a0e
Showing with 60 additions and 8 deletions
...@@ -6,6 +6,7 @@ var url = require("url") ...@@ -6,6 +6,7 @@ var url = require("url")
, DAOFactoryManager = require("./dao-factory-manager") , DAOFactoryManager = require("./dao-factory-manager")
, QueryInterface = require("./query-interface") , QueryInterface = require("./query-interface")
, Transaction = require("./transaction") , Transaction = require("./transaction")
, TransactionManager = require('./transaction-manager')
module.exports = (function() { module.exports = (function() {
/** /**
...@@ -73,6 +74,7 @@ module.exports = (function() { ...@@ -73,6 +74,7 @@ module.exports = (function() {
dialect: 'mysql', dialect: 'mysql',
dialectModulePath: null, dialectModulePath: null,
host: 'localhost', host: 'localhost',
port: 3306,
protocol: 'tcp', protocol: 'tcp',
define: {}, define: {},
query: {}, query: {},
...@@ -110,14 +112,8 @@ module.exports = (function() { ...@@ -110,14 +112,8 @@ module.exports = (function() {
dialectOptions: this.options.dialectOptions, dialectOptions: this.options.dialectOptions,
} }
try {
var ConnectorManager = require("./dialects/" + this.options.dialect + "/connector-manager")
} catch(err) {
throw new Error("The dialect " + this.options.dialect + " is not supported.")
}
this.daoFactoryManager = new DAOFactoryManager(this) this.daoFactoryManager = new DAOFactoryManager(this)
this.connectorManager = new ConnectorManager(this, this.config) this.transactionManager = new TransactionManager(this)
this.importCache = {} this.importCache = {}
} }
...@@ -132,6 +128,24 @@ module.exports = (function() { ...@@ -132,6 +128,24 @@ module.exports = (function() {
} }
/** /**
* Polyfill for the default connector manager.
*/
Object.defineProperty(Sequelize.prototype, 'connectorManager', {
get: function() {
return this.transactionManager.getConnectorManager()
}
})
/**
* Returns the specified dialect.
*
* @return {String} The specified dialect.
*/
Sequelize.prototype.getDialect = function() {
return this.options.dialect
}
/**
Returns an instance of QueryInterface. Returns an instance of QueryInterface.
@method getQueryInterface @method getQueryInterface
...@@ -288,7 +302,7 @@ module.exports = (function() { ...@@ -288,7 +302,7 @@ module.exports = (function() {
type: (sql.toLowerCase().indexOf('select') === 0) ? 'SELECT' : false type: (sql.toLowerCase().indexOf('select') === 0) ? 'SELECT' : false
}) })
return this.connectorManager.query(sql, callee, options) return this.transactionManager.query(sql, callee, options)
} }
Sequelize.prototype.createSchema = function(schema) { Sequelize.prototype.createSchema = function(schema) {
......
Utils = require('./utils')
var TransactionManager = module.exports = function(sequelize) {
this.sequelize = sequelize
this.connectorManagers = {}
try {
this.ConnectorManager = require("./dialects/" + sequelize.getDialect() + "/connector-manager")
} catch(err) {
throw new Error("The dialect " + sequelize.getDialect() + " is not supported.")
}
}
TransactionManager.prototype.getConnectorManager = function(uuid) {
uuid = uuid || 'default'
if (!this.connectorManagers.hasOwnProperty(uuid)) {
var config = Utils._.clone(this.sequelize.config)
if (uuid !== 'default') {
config.pool = { maxConnections: 1, useReplicaton: false }
}
this.connectorManagers[uuid] = new this.ConnectorManager(this.sequelize, config)
}
return this.connectorManagers[uuid]
}
TransactionManager.prototype.query = function(sql, callee, options) {
var uuid = 'default'
if (options && options.transaction) {
uuid = options.transaction.id
}
return this.getConnectorManager(uuid).query(sql, callee, options)
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!