hdb
Version:
SAP HANA Database Client for Node
64 lines (57 loc) • 1.85 kB
JavaScript
// Copyright 2013 SAP AG.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with 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 util = require('../util');
var EventEmitter = require('events').EventEmitter;
var ErrorLevel = require('./common/ErrorLevel');
var debug = util.debuglog('hdbtx');
module.exports = Transaction;
util.inherits(Transaction, EventEmitter);
function Transaction() {
EventEmitter.call(this);
this.autoCommit = true;
this.kind = 'none';
this.error = undefined;
}
Transaction.prototype.setAutoCommit = function setAutoCommit(autoCommit) {
this.autoCommit = autoCommit;
};
Transaction.prototype.setFlags = function setFlags(flags) {
debug(flags);
if (flags.committed) {
this.emit('end', true, this.kind);
this.kind = 'none';
}
if (flags.rolledBack) {
this.emit('end', false, this.kind);
this.kind = 'none';
}
if (flags.writeTransactionStarted) {
this.kind = 'write';
this.emit('new', this.kind);
}
if (flags.noWriteTransactionStarted) {
this.kind = 'read';
this.emit('new', this.kind);
}
if (flags.sessionClosingTransactionErrror) {
this.error = new Error(
'A transaction error occured that implies the session must be terminated.'
);
this.error.code = 'EHDBTX';
this.error.level = ErrorLevel.FATAL;
this.error.fatal = true;
this.emit('error', this.error);
}
};