Made public methods overwritable in new JavaScript layer

This commit is contained in:
Christopher Jones 2016-03-01 08:38:52 +11:00
parent 95740936e8
commit 02f74fabf0
11 changed files with 276 additions and 16 deletions

View File

@ -1,5 +1,9 @@
# Change Log
## node-oracledb v1.7.1 (1 Mar 2016)
- Made public methods overwritable in new JavaScript layer
## node-oracledb v1.7.0 (29 Feb 2016)
- Added a JavaScript wrapper around the C++ API to allow for easier

View File

@ -1,4 +1,4 @@
# node-oracledb version 1.7
# node-oracledb version 1.7.1
## <a name="about"></a> About node-oracledb

View File

@ -1,4 +1,4 @@
# node-oracledb 1.7: Documentation for the Oracle Database Node.js Add-on
# node-oracledb 1.8: Documentation for the Oracle Database Node.js Add-on
*Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*

View File

@ -124,35 +124,40 @@ function extend(conn, pool) {
},
execute: {
value: execute,
enumerable: true
enumerable: true,
writable: true
},
_commit: {
value: conn.commit
},
commit: {
value: commit,
enumerable: true
enumerable: true,
writable: true
},
_rollback: {
value: conn.rollback
},
rollback: {
value: rollback,
enumerable: true
enumerable: true,
writable: true
},
_release: {
value: conn.release
},
release: {
value: release,
enumerable: true
enumerable: true,
writable: true
},
_break: {
value: conn.break
},
break: {
value: module.break,
enumerable: true
enumerable: true,
writable: true
}
}
);

View File

@ -170,14 +170,16 @@ function extend(oracledb) {
},
createPool: {
value: createPool,
enumerable: true
enumerable: true,
writable: true
},
_getConnection: {
value: oracledb.getConnection
},
getConnection: {
value: getConnection,
enumerable: true
enumerable: true,
writable: true
}
}
);

View File

@ -367,14 +367,16 @@ function extend(pool, poolAttrs, oracledb) {
},
getConnection: {
value: getConnection,
enumerable: true
enumerable: true,
writable: true
},
_terminate: {
value: pool.terminate
},
terminate: {
value: terminate,
enumerable: true
enumerable: true,
writable: true
}
}
);

View File

@ -52,21 +52,24 @@ function extend(resultSet) {
},
close: {
value: close,
enumerable: true
enumerable: true,
writable: true
},
_getRow: {
value: resultSet.getRow
},
getRow: {
value: getRow,
enumerable: true
enumerable: true,
writable: true
},
_getRows: {
value: resultSet.getRows
},
getRows: {
value: getRows,
enumerable: true
enumerable: true,
writable: true
}
}
);

View File

@ -1,6 +1,6 @@
{
"name": "oracledb",
"version": "1.7.0",
"version": "1.7.1",
"description": "Oracle Database driver by Oracle Corp.",
"license": "Apache-2.0",
"homepage": "http://www.oracle.com/technetwork/database/database-technologies/scripting-languages/node_js/",

View File

@ -70,7 +70,7 @@ using namespace v8;
/* Keep the version in sync with package.json */
#define NJS_NODE_ORACLEDB_MAJOR 1
#define NJS_NODE_ORACLEDB_MINOR 7
#define NJS_NODE_ORACLEDB_PATCH 0
#define NJS_NODE_ORACLEDB_PATCH 1
/* Used for Oracledb.version */
#define NJS_NODE_ORACLEDB_VERSION ( (NJS_NODE_ORACLEDB_MAJOR * 10000) + \

View File

@ -596,3 +596,10 @@
65. uninitializedLob.js
65.1 an uninitialized Lob is returned from a PL/SQL block
66. writableProperties.js
66.1 allows overwriting of public methods on the oracledb instance
66.2 allows overwriting of public methods on pool instances
66.3 allows overwriting of public methods on connection instances
66.4 allows overwriting of public methods on resultset instances
66.5 allows overwriting of public methods on lob instances

237
test/writableProperties.js Normal file
View File

@ -0,0 +1,237 @@
/* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with the Apache
* License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*****************************************************************************/
'use strict';
var oracledbCLib;
var oracledb = require('oracledb');
var should = require('should');
var dbConfig = require('./dbconfig.js');
var credential;
try {
oracledbCLib = require('../build/Release/oracledb');
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
oracledbCLib = require('../build/Debug/oracledb');
} else {
throw err;
}
}
if (dbConfig.externalAuth) {
credential = { externalAuth: true, connectString: dbConfig.connectString };
} else {
credential = dbConfig;
}
describe('66. writeableProperties.js', function() {
it('66.1 allows overwriting of public methods on the oracledb instance', function(done) {
var keys = Object.keys(oracledb);
var keysIdx;
var originalFunction;
function isConstructorFunction(name) {
// The following has an exception for ILob, which was documented and
// exposed on oracledb as Lob
return typeof oracledbCLib[name] === 'function' || name === 'Lob';
}
for (keysIdx = 0; keysIdx < keys.length; keysIdx += 1) {
if (typeof oracledb[keys[keysIdx]] === 'function' &&
!isConstructorFunction(keys[keysIdx]) // skip constructor functions from the C layer
) {
try {
originalFunction = oracledb[keys[keysIdx]];
oracledb[keys[keysIdx]] = function() {};
oracledb[keys[keysIdx]] = originalFunction;
} catch (err) {
should.not.exist(err);
}
}
}
done();
});
it('66.2 allows overwriting of public methods on pool instances', function(done) {
oracledb.createPool(
{
externalAuth : credential.externalAuth,
user : credential.user,
password : credential.password,
connectString : credential.connectString,
poolMin : 0,
poolMax : 1,
poolIncrement : 1
},
function(err, pool){
var keys;
var keysIdx;
var originalFunction;
should.not.exist(err);
keys = Object.keys(pool);
for (keysIdx = 0; keysIdx < keys.length; keysIdx += 1) {
if (typeof pool[keys[keysIdx]] === 'function') {
try {
originalFunction = pool[keys[keysIdx]];
pool[keys[keysIdx]] = function() {};
pool[keys[keysIdx]] = originalFunction;
} catch (err) {
should.not.exist(err);
}
}
}
pool.terminate(function(err) {
should.not.exist(err);
done();
});
}
);
});
it('66.3 allows overwriting of public methods on connection instances', function(done) {
oracledb.getConnection(credential, function(err, conn) {
var keys;
var keysIdx;
var originalFunction;
should.not.exist(err);
keys = Object.keys(conn);
for (keysIdx = 0; keysIdx < keys.length; keysIdx += 1) {
if (typeof conn[keys[keysIdx]] === 'function') {
try {
originalFunction = conn[keys[keysIdx]];
conn[keys[keysIdx]] = function() {};
conn[keys[keysIdx]] = originalFunction;
} catch (err) {
should.not.exist(err);
}
}
}
conn.release(function(err) {
should.not.exist(err);
done();
});
});
});
it('66.4 allows overwriting of public methods on resultset instances', function(done) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
conn.execute(
'select 1 from dual union select 2 from dual',
[], // no binds
{
resultSet: true
},
function(err, result) {
var keys;
var keysIdx;
var originalFunction;
should.not.exist(err);
keys = Object.keys(result.resultSet);
for (keysIdx = 0; keysIdx < keys.length; keysIdx += 1) {
if (typeof result.resultSet[keys[keysIdx]] === 'function') {
try {
originalFunction = result.resultSet[keys[keysIdx]];
result.resultSet[keys[keysIdx]] = function() {};
result.resultSet[keys[keysIdx]] = originalFunction;
} catch (err) {
should.not.exist(err);
}
}
}
result.resultSet.close(function(err) {
should.not.exist(err);
conn.release(function(err) {
should.not.exist(err);
done();
});
});
}
);
});
});
it('66.5 allows overwriting of public methods on lob instances', function(done) {
oracledb.getConnection(credential, function(err, conn) {
should.not.exist(err);
conn.execute(
'select to_clob(dummy) from dual',
function(err, result) {
var keys;
var keysIdx;
var originalFunction;
var lob;
should.not.exist(err);
lob = result.rows[0][0];
keys = Object.keys(lob);
for (keysIdx = 0; keysIdx < keys.length; keysIdx += 1) {
if (typeof lob[keys[keysIdx]] === 'function') {
try {
originalFunction = lob[keys[keysIdx]];
lob[keys[keysIdx]] = function() {};
lob[keys[keysIdx]] = originalFunction;
} catch (err) {
should.not.exist(err);
}
}
}
conn.release(function(err) {
should.not.exist(err);
done();
});
}
);
});
});
});