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

com.jpattern.core.command.ConditionalCommandChainStrategy Maven / Gradle / Ivy

package com.jpattern.core.command;

import com.jpattern.shared.result.IResult;

/**
 * This strategy is used by default.
 * With this strategy the command in the position i is executed only if all the (i-1) precedent commands
 * execute without errors.
 * If a command generates errors the a rollback is called on all the executed elements of the chain in reverse order of their execution.
 * 
 * @author Francesco Cina'
 *
 * 11/set/2011
 */
public class ConditionalCommandChainStrategy implements ICommandChainStrategy {

	private static final long serialVersionUID = 1L;

	@Override
	public boolean executeNext(IResult result) {
		return result.getErrorMessages().isEmpty();
	}

	@Override
	public boolean executeRollback() {
		return true;
	}

	@Override
	public void doExec(ICommand command, ACommandResult commandResult, boolean catchRuntimeException, ICommandExecutor commandExecutor) {
		command.doExec(catchRuntimeException, commandResult);		
	}

	@Override
	public void doRollback(ICommand command, ACommandResult commandResult, boolean catchRuntimeException, ICommandExecutor commandExecutor) {
		command.doRollback(catchRuntimeException, commandResult);	
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy