if (data.commit) {
var match = data.commit.match(/^(.+?\/transaction\/(\d+))\/commit$/);
this.id = Number(match[2]);
this.uri = match[1];
}
}
}
Transaction.prototype.untransmittedStatements = function() {
var statements = [];
this.statements.forEach(function(statement){
if ((statement)&&(!statement.status))
statements.push(statement);
});
return statements;
}
Transaction.prototype.commit = function(cypher, parameters, cb) {
if (typeof cypher === 'function') {
cb = cypher;
} else {
var args = Transaction._sortTransactionArguments(cypher, parameters, cb);
this.addStatementsToQueue(args.statements);
cb = args.cb;
}
if (typeof cb !== 'function') {
throw Error('You need to attach a callback an a commit/close operation');
}
this.onResponse = cb;
this.status = 'committing';
return this.exec(cb);
}
Transaction.prototype.close = Transaction.prototype.commit;
Transaction.create = function(cypher, parameters, cb) {
return new Transaction(cypher, parameters, cb);
}
Transaction.new = function(cypher, parameters) {
return new Transaction(cypher, parameters);
}
Transaction.prototype.onResponse = null;
Transaction._sortTransactionArguments = function(cypher, parameters, cb) {
var statements = null;
if (typeof cypher === 'string') {
if (typeof parameters === 'function') {
cb = parameters;
parameters = {};
}
statements = [ { statement: cypher, parameters: parameters || {} } ];
} else if ((cypher) && (cypher.constructor === Array)) {
cb = parameters;
statements = cypher;
} else if ((cypher) && (cypher.statement)) {
statements = [ cypher ];
}
return {
statements: statements,
cb: cb || null
}
}
Transaction.prototype.rollback = function(cb) {
var self = this;
if ((this.id)&&(this.status!=='finalized')) {
this.neo4jrestful.delete('/transaction/'+this.id, function(err, res, debug) {