<commit_before>package org.neo4j.api.core;

import org.neo4j.impl.transaction.TransactionUtil;

/**
 * A utility class to manage transactions in Neo. All operations that work with
 * the node space (even read operations) must be wrapped in a transaction.
 * Fortunately, the Transaction class makes this very easy. Here's the idiomatic
 * use of transactions in Neo:<pre><code> Transaction tx = Transaction.begin();
 * try
 * {
 * 	... // any operation that works with the node space
 *	tx.success();
 * }
 * finally
 * {
 * 	tx.finish();
 * } </code></pre>
 * <p>
 * Let's walk through this example line by line. First we retrieve a Transaction
 * object by invoking the static {@link #begin()} factory method. This creates
 * a new Transaction instance which has internal state to keep track of whether
 * the current transaction is successful. Then we wrap all operations that work
 * with the node space in a try-finally block. At the end of the block, we
 * invoke the {@link #finish() tx.success()} method to indicate that the
 * transaction is successful. As we exit the block, the finally clause will
 * kick in and {@link #finish() tx.finish} will commit the transaction if the
 * internal state indicates success or else mark it for rollback.
 * <p>
 * If an exception is raised in the try-block, <code>tx.success()</code> will
 * never be invoked and the internal state of the transaction object will cause
 * <code>tx.finish()</code> to roll back the transaction. This is very
 * important: unless {@link #success()} is invoked, the transaction will fail
 * upon {@link #finish()}. A transaction can be explicitly marked for rollback
 * by invoking the {@link #failure() tx.failure()} method.
 */
public class Transaction
{
	private static final Transaction PLACEBO_TRANSACTION = new Transaction()
	{
		@Override
		public void failure()
		{
			// If a "nested" transaction fails, invoke parent's failure()
			// method, which causes the current transaction to be marked for
			// rollback
			super.failure();
		}

		@Override
		public void finish()
		{
			// Do nothing
		}

		@Override
		public void success()
		{
			// Do nothing
		}
	};
	
	private boolean success = false;
	
	/**
	 * Private constructor.
	 */
	private Transaction()
	{
	}
	
	/**
	 * Starts a new transaction.
	 * @return a transaction object representing the current transaction
	 */
	public static Transaction begin()
	{
		if ( TransactionUtil.beginTx() )
		{
			return new Transaction();			
		}
		else
		{
			return PLACEBO_TRANSACTION;
		}		
	}
	
	/**
	 * Marks this transaction as failed, which means that it will inexplicably be
	 * rolled back upon invocation of {@link #finish()}. Once this method has
	 * been invoked, it doesn't matter how many times {@link #success()} is
	 * invoked -- the transaction will still be rolled back.
	 */
	public void failure()
	{
		this.success = false;
		TransactionUtil.markAsRollbackOnly();
	}
	
	/**
	 * Marks this transaction as successful, which means that it will be
	 * commited upon invocation of {@link #finish()} unless {@link #failure()}
	 * has or will be invoked before then.
	 */
	public void success()
	{
		success = true;
	}
	
	/**
	 * Commits or marks this transaction for rollback, depending on whether
	 * {@link #success()} or {@link #failure()} has been previously invoked.
	 */
	public void finish()
	{
		TransactionUtil.finishTx( success, true );
	}
}
<commit_msg>Placebo transaction failure() now just marks the transaction  rollback only instead of calling super.failure(). See #15<commit_after>package org.neo4j.api.core;

import org.neo4j.impl.transaction.TransactionUtil;

/**
 * A utility class to manage transactions in Neo. All operations that work with
 * the node space (even read operations) must be wrapped in a transaction.
 * Fortunately, the Transaction class makes this very easy. Here's the idiomatic
 * use of transactions in Neo:<pre><code> Transaction tx = Transaction.begin();
 * try
 * {
 * 	... // any operation that works with the node space
 *	tx.success();
 * }
 * finally
 * {
 * 	tx.finish();
 * } </code></pre>
 * <p>
 * Let's walk through this example line by line. First we retrieve a Transaction
 * object by invoking the static {@link #begin()} factory method. This creates
 * a new Transaction instance which has internal state to keep track of whether
 * the current transaction is successful. Then we wrap all operations that work
 * with the node space in a try-finally block. At the end of the block, we
 * invoke the {@link #finish() tx.success()} method to indicate that the
 * transaction is successful. As we exit the block, the finally clause will
 * kick in and {@link #finish() tx.finish} will commit the transaction if the
 * internal state indicates success or else mark it for rollback.
 * <p>
 * If an exception is raised in the try-block, <code>tx.success()</code> will
 * never be invoked and the internal state of the transaction object will cause
 * <code>tx.finish()</code> to roll back the transaction. This is very
 * important: unless {@link #success()} is invoked, the transaction will fail
 * upon {@link #finish()}. A transaction can be explicitly marked for rollback
 * by invoking the {@link #failure() tx.failure()} method.
 */
public class Transaction
{
	private static final Transaction PLACEBO_TRANSACTION = new Transaction()
	{
		@Override
		public void failure()
		{
			TransactionUtil.markAsRollbackOnly();
		}

		@Override
		public void finish()
		{
			// Do nothing
		}

		@Override
		public void success()
		{
			// Do nothing
		}
	};
	
	private boolean success = false;
	
	/**
	 * Private constructor.
	 */
	private Transaction()
	{
	}
	
	/**
	 * Starts a new transaction.
	 * @return a transaction object representing the current transaction
	 */
	public static Transaction begin()
	{
		if ( TransactionUtil.beginTx() )
		{
			return new Transaction();			
		}
		else
		{
			return PLACEBO_TRANSACTION;
		}		
	}
	
	/**
	 * Marks this transaction as failed, which means that it will inexplicably be
	 * rolled back upon invocation of {@link #finish()}. Once this method has
	 * been invoked, it doesn't matter how many times {@link #success()} is
	 * invoked -- the transaction will still be rolled back.
	 */
	public void failure()
	{
		this.success = false;
		TransactionUtil.markAsRollbackOnly();
	}
	
	/**
	 * Marks this transaction as successful, which means that it will be
	 * commited upon invocation of {@link #finish()} unless {@link #failure()}
	 * has or will be invoked before then.
	 */
	public void success()
	{
		success = true;
	}
	
	/**
	 * Commits or marks this transaction for rollback, depending on whether
	 * {@link #success()} or {@link #failure()} has been previously invoked.
	 */
	public void finish()
	{
		TransactionUtil.finishTx( success, true );
	}
}

{'fraction_non_alphanumeric': 0.10116159388325247, 'fraction_numerical': 0.000882223202470225, 'mean_word_length': 3.498677248677249, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6884160', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1819, 'n_words': 824}