@sap/xsodata
Version:
Expose data from a HANA database as OData V2 service with help of .xsodata files.
85 lines (70 loc) • 2.88 kB
JavaScript
;
//Include
var dataCollector2 = require('./dataCollector2');
var statementProcessor = require('./statementProcessor');
exports.createTmpTables = function (context, asyncDone) {
context.logger.silly('dataCollectorDelete', 'createTmpTables');
var dbSeg = context.oData.dbSegmentLast;
var stm = dbSeg.sql.stmContainer.createTmpDel;
return statementProcessor.execStmsDirectlyNoResult(context,stm, asyncDone);
};
exports.insertDataToDelTable = function (context, asyncDone) {
context.logger.silly('dataCollectorDelete', 'insertDataToDelTable');
var dbSeg = context.oData.dbSegmentLast;
statementProcessor.execStmsAsPrepared(context,[dbSeg.sql.stmContainer.insertTmpDel], (err, context, resultset) => {
if (err) {
return asyncDone(err, context);
}
return dataCollector2.resultSetCheckRowCountForUpdate(context, resultset, 0, 1, asyncDone);
});
};
exports.deleteTable = function (context, asyncDone) {
context.logger.silly('dataCollectorDelete', 'deleteTable');
var dbSeg = context.oData.dbSegmentLast;
statementProcessor.execStmsAsPreparedNoResult(context,dbSeg.sql.stmContainer.delete, asyncDone);
};
exports.commit = function (context, asyncDone) {
context.logger.silly('dataCollectorDelete', 'commit');
var client = context.db.client;
client.commit(function (err) {
if (err) {
context.logger.info('SQL Exec', 'Commit Error: \n' + JSON.stringify(err));
return asyncDone(err, context);
}
return asyncDone(null, context);
});
};
/**
* Executes truncation of temporary created tables
*
* @param {Object} context The xsodata context
* @param {Function} asyncDone async waterfall callback
*/
exports.truncateTempTables = function (context, asyncDone) {
var statements;
context.logger.silly('dataCollectorDelete', 'truncateTempTables');
statements = [context.sql.container.createTmpDelTruncate];
return statementProcessor.execTempTableStatements(context,statements, (err, context) => {
if (err) {
context.logger.silly('dataCollectorDelete', 'truncateTempTables rc !=0 but OK');
}
return asyncDone(null, context);
});
};
/**
* Executes deletion of temporary created tables
*
* @param {Object} context The xsodata context
* @param {Function} asyncDone async waterfall callback
*/
exports.dropTempTables = function (context, asyncDone) {
var statements;
context.logger.silly('dataCollectorDelete', 'dropTempTables');
statements = [context.sql.container.createTmpDelDrop];
return statementProcessor.execTempTableStatements(context,statements, (err, context) => {
if (err) {
context.logger.silly('dataCollectorDelete', 'dropTempTables rc !=0 but OK');
}
return asyncDone(null, context);
});
};