Skip to content

Commit 24e2eba

Browse files
authored
Tidy up style (#81)
1 parent 2399d5b commit 24e2eba

39 files changed

+853
-842
lines changed

lib/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function normalizeArguments(args, defaults) {
255255
var command = args[0];
256256
var options = args[1];
257257
var cb = args[2];
258-
defaults = defaults;
258+
defaults = defaults || {};
259259
if (util.isFunction(options)) {
260260
cb = options;
261261
if (util.isObject(command)) {

lib/protocol/ClientInfo.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ function ClientInfo() {
2626
ClientInfo.prototype.setProperty = function setProperty(key, value) {
2727
this._updatedProperties[key] = true;
2828
this._properties[key] = value;
29-
}
29+
};
3030

3131
ClientInfo.prototype.getProperty = function getProperty(key) {
3232
return this._properties[key];
33-
}
33+
};
3434

3535
ClientInfo.prototype.shouldSend = function shouldSend(messageType) {
3636
switch (messageType) {
@@ -44,7 +44,7 @@ ClientInfo.prototype.shouldSend = function shouldSend(messageType) {
4444
default:
4545
return false;
4646
}
47-
}
47+
};
4848

4949
ClientInfo.prototype.getUpdatedProperties = function getUpdatedProperties() {
5050
var self = this;
@@ -54,5 +54,5 @@ ClientInfo.prototype.getUpdatedProperties = function getUpdatedProperties() {
5454
}, []);
5555
this._updatedProperties = {};
5656
return res;
57-
}
57+
};
5858

lib/protocol/Connection.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ Object.defineProperties(Connection.prototype, {
125125
return 'opening';
126126
}
127127
switch (this._state.messageType) {
128-
case MessageType.AUTHENTICATE:
129-
case MessageType.CONNECT:
130-
return 'connecting';
131-
case MessageType.DISCONNECT:
132-
return 'disconnecting';
128+
case MessageType.AUTHENTICATE:
129+
case MessageType.CONNECT:
130+
return 'connecting';
131+
case MessageType.DISCONNECT:
132+
return 'disconnecting';
133+
default:
134+
// do nothing
133135
}
134136
if (this._state.sessionId === -1) {
135137
return 'disconnected';
@@ -301,7 +303,7 @@ Connection.prototype.send = function send(message, receive) {
301303

302304
Connection.prototype.getClientInfo = function getClientInfo() {
303305
return this._clientInfo;
304-
}
306+
};
305307

306308
Connection.prototype.setStatementContext = function setStatementContext(options) {
307309
if (options && options.length) {
@@ -367,7 +369,7 @@ Connection.prototype.enqueue = function enqueue(task, cb) {
367369
if (!this._socket) {
368370
var err = new Error('Connection closed');
369371
err.code = 'EHDBCLOSE';
370-
return cb(err)
372+
return cb(err);
371373
}
372374
if (util.isFunction(task)) {
373375
queueable = this._queue.createTask(task, cb);

lib/protocol/ConnectionManager.js

+126-126
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
1-
// Copyright 2013 SAP AG.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http: //www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing,
10-
// software distributed under the License is distributed on an
11-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12-
// either express or implied. See the License for the specific
13-
// language governing permissions and limitations under the License.
14-
'use strict';
15-
16-
var State = require('./ConnectionManagerState');
17-
var util = require('../util');
18-
var debug = util.debuglog('hdb_conn');
19-
20-
module.exports = ConnectionManager;
21-
22-
function ConnectionManager(settings) {
23-
this.state = new State(settings);
24-
}
25-
26-
ConnectionManager.prototype.updateState = function updateState(newOptions) {
27-
this.state.update(newOptions);
28-
};
29-
30-
ConnectionManager.prototype.getConnectOptions = function getConnectOptions() {
31-
return this.state.options.connect;
32-
};
33-
34-
ConnectionManager.prototype.openConnection = function openConnection(conn, cb) {
35-
var dbHosts = this.state.dbHosts;
36-
debug('Opening connection. Hosts:', dbHosts);
37-
38-
this._openConnectionToHost(conn, dbHosts, 0, [], cb);
39-
};
40-
41-
ConnectionManager.prototype._openConnectionToHost = function _openConnectionToHost(conn, dbHosts, whichHost, errorStats, cb) {
42-
if (whichHost === dbHosts.length) {
43-
return cb(couldNotOpenConnectionError(errorStats));
44-
}
45-
46-
var self = this;
47-
var currentHostOptions = dbHosts[whichHost];
48-
var openOptions = util.extend({}, currentHostOptions, this.state.options.encryption);
49-
this._openConnection(conn, openOptions, function (err) {
50-
if (!err) {
51-
debug('Successful connection to %s:%d', openOptions.host, openOptions.port);
52-
return cb(null);
53-
}
54-
debug('Connection to %s:%d failed with:', openOptions.host, openOptions.port, err.message);
55-
errorStats.push({ host: openOptions.host, port: openOptions.port, err: err });
56-
self._openConnectionToHost(conn, dbHosts, (whichHost + 1), errorStats, cb);
57-
});
58-
};
59-
60-
ConnectionManager.prototype._openConnection = function _openConnection(conn, openOptions, cb) {
61-
var dbName = this.state.options.multiDb.databaseName;
62-
if (util.isString(dbName) && dbName.length) {
63-
this._openConnectionMultiDbCase(conn, openOptions, cb);
64-
} else {
65-
conn.open(openOptions, cb);
66-
}
67-
};
68-
69-
ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectionMultiDbCase(conn, openOptions, cb) {
70-
var multiDbOptions = this.state.options.multiDb;
71-
72-
if (!openOptions.port) {
73-
var instanceNum = extractInstanceNumber(multiDbOptions.instanceNumber);
74-
if (isNaN(instanceNum)) {
75-
return cb(new Error('Instance Number is not valid'));
76-
} else {
77-
openOptions.port = 30013 + (instanceNum * 100);
78-
}
79-
}
80-
81-
function handleError(err) {
82-
conn.close();
83-
cb(err);
84-
}
85-
86-
conn.open(openOptions, function (err) {
87-
if (err) {
88-
return handleError(err);
89-
}
90-
91-
conn.fetchDbConnectInfo(multiDbOptions, function (err, info) {
92-
if (err) {
93-
return handleError(err);
94-
}
95-
96-
if (info.isConnected) {
97-
cb(null);
98-
} else {
99-
conn._closeSilently();
100-
openOptions.host = info.host;
101-
openOptions.port = info.port;
102-
debug('Connecting to tenant-db %s on %s:%d', multiDbOptions.databaseName, openOptions.host, openOptions.port);
103-
conn.open(openOptions, cb);
104-
}
105-
});
106-
});
107-
};
108-
109-
function extractInstanceNumber(instanceNumber) {
110-
if (util.isNumber(instanceNumber)) {
111-
return instanceNumber;
112-
}
113-
if (util.isString(instanceNumber) && instanceNumber.length) {
114-
return parseInt(instanceNumber, 10);
115-
}
116-
return NaN;
117-
}
118-
119-
function couldNotOpenConnectionError(errorStats) {
120-
var message = 'Could not connect to any host:';
121-
errorStats.forEach(function (stats) {
122-
message += util.format(' [ %s:%d - %s ]', stats.host, stats.port, stats.err.message);
123-
});
124-
var err = new Error(message);
125-
err.code = 'EHDBOPENCONN';
126-
return err;
1+
// Copyright 2013 SAP AG.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http: //www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied. See the License for the specific
13+
// language governing permissions and limitations under the License.
14+
'use strict';
15+
16+
var State = require('./ConnectionManagerState');
17+
var util = require('../util');
18+
var debug = util.debuglog('hdb_conn');
19+
20+
module.exports = ConnectionManager;
21+
22+
function ConnectionManager(settings) {
23+
this.state = new State(settings);
24+
}
25+
26+
ConnectionManager.prototype.updateState = function updateState(newOptions) {
27+
this.state.update(newOptions);
28+
};
29+
30+
ConnectionManager.prototype.getConnectOptions = function getConnectOptions() {
31+
return this.state.options.connect;
32+
};
33+
34+
ConnectionManager.prototype.openConnection = function openConnection(conn, cb) {
35+
var dbHosts = this.state.dbHosts;
36+
debug('Opening connection. Hosts:', dbHosts);
37+
38+
this._openConnectionToHost(conn, dbHosts, 0, [], cb);
39+
};
40+
41+
ConnectionManager.prototype._openConnectionToHost = function _openConnectionToHost(conn, dbHosts, whichHost, errorStats, cb) {
42+
if (whichHost === dbHosts.length) {
43+
return cb(couldNotOpenConnectionError(errorStats));
44+
}
45+
46+
var self = this;
47+
var currentHostOptions = dbHosts[whichHost];
48+
var openOptions = util.extend({}, currentHostOptions, this.state.options.encryption);
49+
this._openConnection(conn, openOptions, function (err) {
50+
if (!err) {
51+
debug('Successful connection to %s:%d', openOptions.host, openOptions.port);
52+
return cb(null);
53+
}
54+
debug('Connection to %s:%d failed with:', openOptions.host, openOptions.port, err.message);
55+
errorStats.push({ host: openOptions.host, port: openOptions.port, err: err });
56+
self._openConnectionToHost(conn, dbHosts, (whichHost + 1), errorStats, cb);
57+
});
58+
};
59+
60+
ConnectionManager.prototype._openConnection = function _openConnection(conn, openOptions, cb) {
61+
var dbName = this.state.options.multiDb.databaseName;
62+
if (util.isString(dbName) && dbName.length) {
63+
this._openConnectionMultiDbCase(conn, openOptions, cb);
64+
} else {
65+
conn.open(openOptions, cb);
66+
}
67+
};
68+
69+
ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectionMultiDbCase(conn, openOptions, cb) {
70+
var multiDbOptions = this.state.options.multiDb;
71+
72+
if (!openOptions.port) {
73+
var instanceNum = extractInstanceNumber(multiDbOptions.instanceNumber);
74+
if (isNaN(instanceNum)) {
75+
return cb(new Error('Instance Number is not valid'));
76+
} else {
77+
openOptions.port = 30013 + (instanceNum * 100);
78+
}
79+
}
80+
81+
function handleError(err) {
82+
conn.close();
83+
cb(err);
84+
}
85+
86+
conn.open(openOptions, function (err) {
87+
if (err) {
88+
return handleError(err);
89+
}
90+
91+
conn.fetchDbConnectInfo(multiDbOptions, function (err, info) {
92+
if (err) {
93+
return handleError(err);
94+
}
95+
96+
if (info.isConnected) {
97+
cb(null);
98+
} else {
99+
conn._closeSilently();
100+
openOptions.host = info.host;
101+
openOptions.port = info.port;
102+
debug('Connecting to tenant-db %s on %s:%d', multiDbOptions.databaseName, openOptions.host, openOptions.port);
103+
conn.open(openOptions, cb);
104+
}
105+
});
106+
});
107+
};
108+
109+
function extractInstanceNumber(instanceNumber) {
110+
if (util.isNumber(instanceNumber)) {
111+
return instanceNumber;
112+
}
113+
if (util.isString(instanceNumber) && instanceNumber.length) {
114+
return parseInt(instanceNumber, 10);
115+
}
116+
return NaN;
117+
}
118+
119+
function couldNotOpenConnectionError(errorStats) {
120+
var message = 'Could not connect to any host:';
121+
errorStats.forEach(function (stats) {
122+
message += util.format(' [ %s:%d - %s ]', stats.host, stats.port, stats.err.message);
123+
});
124+
var err = new Error(message);
125+
err.code = 'EHDBOPENCONN';
126+
return err;
127127
}

0 commit comments

Comments
 (0)