Skip to content

Commit

Permalink
Be consistent in calling jones.ConnectionProperties() as a constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdduncan committed May 6, 2015
1 parent 2b055d7 commit 58d7a86
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 45 deletions.
11 changes: 5 additions & 6 deletions database-jones/API-documentation/Jones
Expand Up @@ -5,14 +5,13 @@
* CONSTRUCTOR
*
* If implName_or_connectionProperties is the name of a backend adapter,
* (i.e. either "mysql" or "ndb"), this constructor returns the default
* (e.g. "mysql" or "ndb"), this constructor returns the default
* ConnectionProperties for that adapter.
*
* If implName_or_connectionProperties is a ConnectionProperties object,
* then this works as a copy constructor, copying it to and returning a new
* ConnectionProperties object.
*
* Otherwise, returns undefined.
* If implName_or_connectionProperties is an object which includes a member
* property "implementation", then the default ConnectionProperties for
* adapter <implementation> are fetched, and then overridden by any
* properties present in implName_or_connectionProperties.
*/
ConnectionProperties(implName_or_connectionProperties);

Expand Down
2 changes: 1 addition & 1 deletion database-jones/Adapter/api/Session.js
Expand Up @@ -47,7 +47,7 @@ exports.Session.prototype.getTableMetadata = function() {

exports.Session.prototype.listTables = function() {
var context = new userContext.UserContext(arguments, 2, 2, this, this.sessionFactory);
// delegate to context's getTableMetadata for execution
// delegate to context's listTables for execution
return context.listTables();
};

Expand Down
24 changes: 13 additions & 11 deletions database-jones/Adapter/api/jones.js
Expand Up @@ -22,6 +22,7 @@

var path = require("path"),
fs = require("fs"),
assert = require("assert"),

conf = require("../adapter_config"),
UserContext = null, // loaded later to prevent circular dependency
Expand Down Expand Up @@ -99,28 +100,29 @@ exports.converters = {
"JSONSparseConverter" : require(path.join(conf.converters_dir, "JSONSparseConverter"))
};

/*jslint forin: true */
exports.ConnectionProperties = function(nameOrProperties) {
var serviceProvider, newProperties, key, value;
var serviceProvider, newProperties, key;

newProperties = {};

if(typeof nameOrProperties === 'string') {
udebug.log("ConnectionProperties [default for " + nameOrProperties + "]");
serviceProvider = getDBServiceProvider(nameOrProperties);
newProperties = serviceProvider.getDefaultConnectionProperties();
assert(newProperties.implementation === nameOrProperties);
}
else if(typeof nameOrProperties === 'object' &&
typeof nameOrProperties.implementation === 'string') {
udebug.log("ConnectionProperties [copy constructor]");
newProperties = {};
for(key in nameOrProperties) {
value = nameOrProperties[key];
if(typeof value === 'string' || typeof value === 'number') {
newProperties[key] = value;
}
else {
udebug.log(" .. not copying property:", key);
}
serviceProvider = getDBServiceProvider(nameOrProperties.implementation);
newProperties = serviceProvider.getDefaultConnectionProperties();

for(key in nameOrProperties) if(nameOrProperties.hasOwnProperty(key)) {
newProperties[key] = nameOrProperties[key];
}
}

/* "Normally constructors don't return a value, but they can choose to" */
return newProperties;
};

Expand Down
2 changes: 1 addition & 1 deletion database-jones/test/api/DefaultImplementationTest.js
Expand Up @@ -18,7 +18,7 @@
02110-1301 USA
*/

var t1 = new harness.ConcurrentTest("testDefaultImplementation");
var t1 = new harness.ConcurrentTest("testImplementation");
t1.run = function() {
mynode.connect(global.adapter, null, function(err, sessionFactory) {
if (sessionFactory) {
Expand Down
2 changes: 1 addition & 1 deletion database-jones/test/multidb/ConnectTest.js
Expand Up @@ -70,7 +70,7 @@ var badtbl9 = function(i, j) {
};

// create all properties for connecting with different default databases
var properties = mynode.ConnectionProperties(global.adapter);
var properties = new mynode.ConnectionProperties(global.adapter);
// make a local copy of the properties
var propertiesList = [];
var p, x, props;
Expand Down
25 changes: 6 additions & 19 deletions database-jones/test/utilities.js
Expand Up @@ -24,6 +24,8 @@

var path = require("path"),
fs = require("fs"),
assert = require("assert"),
udebug = unified_debug.getLogger("utilities.js"),
dbServiceProvider = mynode.getDBServiceProvider(adapter),
metadataManager = dbServiceProvider.getDBMetadataManager();

Expand Down Expand Up @@ -60,26 +62,10 @@ function getTestConnectionProperties() {
return properties;
}

function getAdapterProperties(adapter) {
var impl = adapter || global.adapter;
var p = new mynode.ConnectionProperties(impl);
return p;
}

function merge(target, m) {
var p;
for(p in m) {
if(m.hasOwnProperty(p)) {
target[p] = m[p];
}
}
}

function getConnectionProperties() {
var adapterProps = getAdapterProperties();
var localConnectionProps = getTestConnectionProperties();
merge(adapterProps, localConnectionProps);
return adapterProps;
var testEnvProperties = getTestConnectionProperties();
testEnvProperties.implementation = global.adapter;
return new mynode.ConnectionProperties(testEnvProperties);
}

/** Set global test connection properties */
Expand All @@ -103,6 +89,7 @@ global.fail_openSession = function(testCase, callback) {
}
var properties = global.test_conn_properties;
var mappings = testCase.mappings;
udebug.log_detail("fail_openSession", properties.implementation);
promise = mynode.openSession(properties, mappings, function(err, session) {
if (callback && err) {
testCase.fail(err);
Expand Down
4 changes: 2 additions & 2 deletions jones-mysql/test/driver.js
Expand Up @@ -25,7 +25,7 @@ global.mynode = require("database-jones");
global.adapter = "mysql";

var jonesMysql = require("jones-mysql");
var driver = require(mynode.fs.suites_dir + "/JonesTestDriver");
var driver = require(mynode.fs.test_driver);
var storageEngine = null;

driver.addCommandLineOption("-e", "--engine", "use named mysql storage engine",
Expand All @@ -46,6 +46,6 @@ if(storageEngine && global.test_conn_properties) {

/* Find and run all tests */
driver.addSuitesFromDirectory(mynode.fs.suites_dir);
driver.addSuitesFromDirectory(jonesMysql.fs.suites_dir);
driver.addSuitesFromDirectory(jonesMysql.config.suites_dir);
driver.runAllTests();

1 change: 1 addition & 0 deletions jones-ndb/impl/ndb/NdbMetadataManager.js
Expand Up @@ -50,6 +50,7 @@ function NdbMetadataManager() {

NdbMetadataManager.prototype.runSQL = function(properties, sqlPath, callback) {
properties.implementation = "mysql";
properties.isMetadataOnlyConnection = true;
assert(sqlPath);
udebug.log("runSQL", sqlPath);
var statement = "set storage_engine=ndbcluster;\n";
Expand Down
1 change: 1 addition & 0 deletions jones-ndb/impl/ndb/NdbSession.js
Expand Up @@ -70,6 +70,7 @@ NdbSession = function(pool) {
this.seizeTxQueue = null;
this.maxTxContexts = pool.properties.ndb_session_concurrency;
this.openTxContexts = 0; // currently opened
this.isNdbSession = true;
};

/* fetch DBSessionImpl. Undocumented - private to NdbConnectionPool.
Expand Down
2 changes: 1 addition & 1 deletion jones-ndb/test/driver.js
Expand Up @@ -23,7 +23,7 @@
var jones = require("database-jones"),
jonesNdb = require("jones-ndb"),
jonesMysql = require("jones-mysql"),
driver = require(jones.fs.suites_dir + "/JonesTestDriver");
driver = require(jones.fs.test_driver);

// Setup globals:
global.mynode = jones;
Expand Down
2 changes: 1 addition & 1 deletion samples/find.js
Expand Up @@ -107,7 +107,7 @@ if (exit) {
console.log('Running find with adapter', adapter, user_args);
//create a database properties object

var dbProperties = nosql.ConnectionProperties(adapter);
var dbProperties = new nosql.ConnectionProperties(adapter);

// create a basic mapping
var annotations = new nosql.TableMapping('tweet').applyToClass(lib.Tweet);
Expand Down
2 changes: 1 addition & 1 deletion samples/insert.js
Expand Up @@ -107,7 +107,7 @@ if (exit) {
console.log('Running insert with adapter', adapter, user_args);
//create a database properties object

var dbProperties = nosql.ConnectionProperties(adapter);
var dbProperties = new nosql.ConnectionProperties(adapter);

// create a basic mapping
var annotations = new nosql.TableMapping('tweet').applyToClass(lib.Tweet);
Expand Down
2 changes: 1 addition & 1 deletion shell/jshell
Expand Up @@ -8,7 +8,7 @@
// Configure what's available in the REPL
context.util = require("util");
context.jones = require("database-jones");
global.MySQLngDefaultConnectionProperties = context.jones.ConnectionProperties('mysql');
global.MySQLngDefaultConnectionProperties = new context.jones.ConnectionProperties('mysql');

global.t_basic = function(id, name, age, magic) {
if (typeof id !== 'undefined') this.id = id;
Expand Down

0 comments on commit 58d7a86

Please sign in to comment.