All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dooapp.gaedo.blueprints.TransactionalOperation Maven / Gradle / Ivy

package com.dooapp.gaedo.blueprints;

import com.dooapp.gaedo.finders.Informer;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;

/**
 * Transaction supporting "closure" base : it decorates given operation with transaction support.
 * @author ndx
 *
 * @param 
 */
public abstract class TransactionalOperation> {
	/**
	 * 
	 */
	private final AbstractBluePrintsBackedFinderService service;

	/**
	 * @param bluePrintsBackedFinderService
	 */
	public TransactionalOperation(AbstractBluePrintsBackedFinderService bluePrintsBackedFinderService) {
		service = bluePrintsBackedFinderService;
	}

	/**
	 * This is now a no-op code, as gaedo should not handle transactions itself.
	 * @return
	 */
	public ResultType perform() {
		if(false && service.transactionSupport!=null) {
			try {
//				service.transactionSupport.startTransaction();
				try {
					ResultType returned = doPerform();
					service.transactionSupport.stopTransaction(Conclusion.SUCCESS);
					return returned;
				} catch(RuntimeException e) {
					service.transactionSupport.stopTransaction(Conclusion.FAILURE);
					throw e;
				}
			} catch(RuntimeException e) {
				/*
				 * People of tinkerpop : I hate you for that code block !
				 * Why on earth didn't you send a specific exception conveying that very purpose ? I could have handled it clearly.
				 * Instead, I have to rely on messy and slow string comparison. OMG
				 */
				if("Stop current transaction before starting another".equals(e.getMessage())) {
					// Anyway, perform operation in transaction
					return doPerform();
					// And obviously, I won't close a transaction I didn't opened
				} else {
					throw e;
				}
			}
		} else {
			return doPerform();
		}
	}

	/**
	 * Operation that will be performed (in transactional context or not)
	 * @return effective result
	 */
	protected abstract ResultType doPerform();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy