package org.jglue.totorom;

import java.io.Closeable;
import java.io.IOException;

import com.tinkerpop.blueprints.TransactionalGraph;

/**
 * Represents a transaction on the underlying graph. 
 * Note that for tinkerpop2 this is not a true transaction object and just wraps calls to commit and rollback. Therefore nested transactions won't work.
 *   
 * @author Bryn Cooke (http://jglue.org)
 *
 */
public class Transaction implements AutoCloseable {

	private TransactionalGraph graph;
	private boolean comitted;

	Transaction(TransactionalGraph graph) {
		this.graph = graph;
		
	}

	/**
	 * Commit the transaction.
	 */
	public void commit() {
		graph.commit();
		comitted = true;
	}

	/**
	 * Rollback the transaction.
	 */
	public void rollback() {
		graph.rollback();
	}

	/* (non-Javadoc)
	 * @see java.io.Closeable#close()
	 */
	@Override
	public void close() {
		if(!comitted) {
			rollback();
		}
		
	}

}

@@ -508,16 +508,45 @@
 omitted;
+%0A%09private boolean rolledBack;
 %0A%0A%09Trans
@@ -798,16 +798,37 @@
 back();%0A
+%09%09rolledBack = true;%0A
 %09%7D%0A%0A%09/* 
@@ -929,16 +929,31 @@
 comitted
+ && !rolledBack
 ) %7B%0A%09%09%09r

Fix rollback behaviour.