Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
athiththan11 committed Aug 6, 2019
1 parent 0e8b461 commit 5eefb0f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/commands/alter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AlterCommand extends Command {

this.log(`starting to alter ${product}-${version} with ${datasource} configurations`);

cli.action.start('\taltering master-datasources.xml');
if (datasource === 'postgres')
await Postgres.configure(this.log, cli);
else if (datasource === 'mysql')
Expand Down
47 changes: 29 additions & 18 deletions src/services/datasources/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,47 @@ let pMasterDatasource =
let pIdentity = process.cwd() + '/repository/conf/identity/identity.xml';

let _ = 'Generic';
let _t = '\t\t';
let _n = '\n\n';
let _comment = 'HYDROGENERATED:';
let _description = _.toLowerCase() + ' datasource added';
let _carbon = 'jdbc/WSO2' + _ + 'CarbonDB';
let _comment = 'HYDROGENERATED:';
let _connectionUrl = '{specify connection url}';
let _username = _.toLowerCase();
let _defaultAutoCommit = 'false';
let _description = _.toLowerCase() + ' datasource added';
let _driver = '{specify jdbc driver}';
let _maxActive = '80';
let _maxWait = '60000';
let _minIdle = '5';
let _n = '\n\n';
let _t = '\t\t';
let _testOnBorrow = 'true';
let _username = _.toLowerCase();
let _validationInterval = '30000';
let _validationQuery = 'SELECT 1';
let _defaultAutoCommit = 'false';

exports.configureDatasource = async function (log, cli, args) {
// variable set
_ = args._ ? args._ : _;

_description = _.toLowerCase() + ' datasource added';
_carbon = 'jdbc/WSO2' + _ + 'CarbonDB';
_description = _.toLowerCase() + ' datasource added';
_username = _.toLowerCase();

_t = args._t ? args._t : _t;
_n = args._n ? args._n : _n;
_comment = args._comment ? args._comment : _comment;
_description = args._description ? args._description : _description;
_carbon = args._carbon ? args._carbon : _carbon;
_comment = args._comment ? args._comment : _comment;
_connectionUrl = args._connectionUrl ? args._connectionUrl : _connectionUrl;
_username = args._username ? args._username : _username;
_defaultAutoCommit = args._defaultAutoCommit ? args._defaultAutoCommit : _defaultAutoCommit;
_description = args._description ? args._description : _description;
_driver = args._driver ? args._driver : _driver;
_maxActive = args._maxActive ? args._maxActive : _maxActive;
_maxWait = args._maxWait ? args._maxWait : _maxWait;
_minIdle = args._minIdle ? args._minIdle : _minIdle;
_n = args._n ? args._n : _n;
_t = args._t ? args._t : _t;
_testOnBorrow = args._testOnBorrow ? args._testOnBorrow : _testOnBorrow;
_username = args._username ? args._username : _username;
_validationInterval = args._validationInterval ? args._validationInterval : _validationInterval;
_validationQuery = args._validationQuery ? args._validationQuery : _validationQuery;
_defaultAutoCommit = args._defaultAutoCommit ? args._defaultAutoCommit : _defaultAutoCommit;

cli.action.start('\taltering master-datasources.xml');
await parseXML(log, pMasterDatasource).then(master => {
alterMasterDatasource(log, master, pMasterDatasource).then(() => {
cli.action.stop();
Expand Down Expand Up @@ -114,17 +125,17 @@ function buildOracleDatasource(doc) {
.parent()
.node('driverClassName', _driver)
.parent()
.node('maxActive', '80')
.node('maxActive', _maxActive)
.parent()
.node('maxWait', '60000')
.node('maxWait', _maxWait)
.parent()
.node('minIdle', '5')
.node('minIdle', _minIdle)
.parent()
.node('testOnBorrow', 'true')
.node('testOnBorrow', _testOnBorrow)
.parent()
.node('validationQuery', _validationQuery)
.parent()
.node('validationInterval', '30000')
.node('validationInterval', _validationInterval)
.parent()
.node('defaultAutoCommit', _defaultAutoCommit);

Expand Down
2 changes: 1 addition & 1 deletion src/services/datasources/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const { configureDatasource } = require('./generic');
let args = {};
args._ = 'MySQL';
args._connectionUrl = 'jdbc:mysql://localhost:3306/wso2mysql';
args._defaultAutoCommit = 'false';
args._driver = 'com.mysql.jdbc.Driver';
args._validationQuery = 'SELECT 1';
args._defaultAutoCommit = 'false';

exports.configure = async function (log, cli) {
configureDatasource(log, cli, args);
Expand Down
2 changes: 1 addition & 1 deletion src/services/datasources/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const { configureDatasource } = require('./generic');
let args = {};
args._ = 'Postgres';
args._connectionUrl = 'jdbc:postgresql://localhost:5432/wso2postgres';
args._defaultAutoCommit = 'true';
args._driver = 'org.postgresql.Driver';
args._validationQuery = 'SELECT 1; COMMIT';
args._defaultAutoCommit = 'true';

exports.configure = async function (log, cli) {
configureDatasource(log, cli, args);
Expand Down

0 comments on commit 5eefb0f

Please sign in to comment.