-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcassandra-dml-handler.js
More file actions
146 lines (120 loc) · 4.52 KB
/
Copy pathcassandra-dml-handler.js
File metadata and controls
146 lines (120 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* New node file
*/
var cassandra = require('cassandra-driver');
var async = require('async');
var sqlStrUtility = require('./sql-str-utility');
var cassandraDDLHandler= require('./cassandra-ddl-handler');
var cassandraBase = require('./cassandra-base');
var logger = require("./logger");
function CassandraDMLHandler(){
this.deleteTransactional=function(cql,txObject){
var deleteStatement = sqlStrUtility.SqlStrUtility().getDeleteStatement(cql);
deleteStatement.txObject=txObject;
this.deleteTxRecord(deleteStatement,txObject);
}
this.updateTransactional=function(cql,txObject){
var updateStatement = sqlStrUtility.SqlStrUtility().getUpdateStatement(cql);
updateStatement.txObject=txObject;
this.updateTxRecord(updateStatement,txObject);
}
this.deleteTxRecord=function(statement,txObject){
logger.debug(txObject,'inserting tx record on table ' + statement.table);
var columnClause = '';
var valueClause = '';
for (var i=0; i<statement.columns.length;i++){
var c = statement.columns[i];
if (columnClause != '')
columnClause += ',';
columnClause += c.column;
if (valueClause != '')
valueClause += ',';
valueClause += c.value;
}
this.execute('insert into tx_' + statement.table + '(' + columnClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.getColumnString() +
') values(' + valueClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.deleteValues + ",''," + statement.txObject.getTransactionId() +')',
[],
statement,
this.dummyCallback,
this,
txObject);
logger.debug(txObject,'inserted tx record on table ' + statement.table);
}
this.updateTxRecord=function(statement,txObject){
logger.debug(txObject,'inserting tx record on table ' + statement.table);
var columnClause = '';
var valueClause = '';
for (var i=0; i<statement.columns.length;i++){
var c = statement.columns[i];
if (columnClause != '')
columnClause += ',';
columnClause += c.column;
if (valueClause != '')
valueClause += ',';
valueClause += c.value;
}
var changesClause = '';
for (var i=0; i<statement.changes.length;i++){
var c = statement.changes[i];
if (changesClause != '')
changesClause += ',';
changesClause += c.column;
}
this.execute('insert into tx_' + statement.table + '(' + columnClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.getColumnString() +
') values(' + valueClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.updateValues + ",'" + changesClause + "'," + statement.txObject.getTransactionId() +')',
[],
statement,
this.dummyCallback,
this,
txObject);
logger.debug(txObject,'inserted tx record on table ' + statement.table);
}
this.insertTransactional=function(cql,txObject){
var insertStatement = sqlStrUtility.SqlStrUtility().getInsertStatement(cql);
insertStatement.txObject=txObject;
this.insertTxRecord(insertStatement,txObject);
}
this.insertTxRecord=function(statement,txObject){
logger.debug(txObject,'inserting tx record on table ' + statement.table);
var columnClause = '';
var valueClause = '';
for (var i=0; i<statement.columns.length;i++){
var c = statement.columns[i];
if (columnClause != '')
columnClause += ',';
columnClause += c.column;
if (valueClause != '')
valueClause += ',';
valueClause += c.value;
}
this.execute('insert into tx_' + statement.table + '(' + columnClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.getColumnString() +
') values(' + valueClause + ',' + cassandraDDLHandler.getInstance().transactionColumns.insertValues + ',' + statement.txObject.getTransactionId() +')',
[],
statement,
this.dummyCallback,
this,
txObject);
logger.debug(txObject,'inserted tx record on table ' + statement.table);
}
this.dummyCallback=function(rows,statement,thus,txObject){
logger.debug(txObject,"Dummy return from Cassandra DML");
txObject.txCallback(rows, statement);
};
}
module.exports = {
getInstance : function(){
CassandraDMLHandler.prototype = cassandraBase.getInstance();
var handler = new CassandraDMLHandler();
return {
executeTransactional : function(cql,txObject){
if (sqlStrUtility.SqlStrUtility().isUpdate(cql)){
handler.updateTransactional(cql,txObject);
}else if (sqlStrUtility.SqlStrUtility().isInsert(cql)){
handler.insertTransactional(cql,txObject);
}else if (sqlStrUtility.SqlStrUtility().isDelete(cql)){
handler.deleteTransactional(cql,txObject);
}
}
}
}
}