Permalink
Browse files

Support for rolling back a transaction. (untested)

  • Loading branch information...
1 parent 3e2caab commit 5443e9efd9f3b08c9ce9e528ba70d57cb2f69b92 @pekim pekim committed Jul 8, 2012
Showing with 13 additions and 1 deletion.
  1. +9 −0 src/connection.coffee
  2. +4 −1 src/transaction.coffee
View
@@ -400,6 +400,15 @@ class Connection extends EventEmitter
@makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.commitPayload(@currentTransactionDescriptor()))
+ rollbackTransaction: (callback) ->
+ if @transactions.length == 0
+ throw new Error('No transaction in progress')
+ transaction = @transactions.pop()
+
+ request = new Request(undefined, callback)
+
+ @makeRequest(request, TYPE.TRANSACTION_MANAGER, transaction.rollbackPayload(@currentTransactionDescriptor()))
+
makeRequest: (request, packetType, payload) ->
if @state != @STATE.LOGGED_IN
message = "Invalid state; requests can only be made in the #{@STATE.LOGGED_IN.name} state, not the #{@state.name} state"
View
@@ -64,7 +64,10 @@ class Transaction
buffer.writeString(@name, 'ucs2')
buffer.writeUInt8(0) # No fBeginXact flag, so no new transaction is started.
- buffer.data
+ payload =
+ data: buffer.data
+ toString: =>
+ "Rollback Transaction: name=#{@name}"
exports.Transaction = Transaction
exports.ISOLATION_LEVEL = ISOLATION_LEVEL

0 comments on commit 5443e9e

Please sign in to comment.