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

nyla.solutions.dao.patterns.command.ExecuteUpdateArrayableCommand Maven / Gradle / Ivy

package nyla.solutions.dao.patterns.command;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import nyla.solutions.global.data.Arrayable;
import nyla.solutions.global.exception.SystemException;

/**
 * Example
 * 	
		true
		
		select 'Y' from ASAP_STRUCTURES where cdregno = ? 
		
			
				1
				
			
	
 * @author Gregory Green
 *
 */
public class ExecuteUpdateArrayableCommand extends AbstractDAOCommand> 
{
	/**
	 * 
	 * @see solutions.global.patterns.command.Command#execute(java.lang.Object)
	 */
	public Integer execute(Arrayable  eval)
	{
		PreparedStatement stmt = null;
		
		try
		{
			if(!this.isConnected())
				this.connect();
			
			stmt = prepareStatement(this.sql);
			
			int size = inputsPositions.length;
			

			Object[] dataRow = eval.toArray();
			
			for(int i= 0; i < size;i++)
			{
				stmt.setObject(i+1, dataRow[inputsPositions[i]]);
			}
			
			return new Integer(stmt.executeUpdate());
			
		}
		catch(SQLException e)
		{
			throw new SystemException(this.sql,e);
		}
		finally
		{
			
			if(stmt != null)
				try{ stmt.close();} catch(Exception e){}
		}
	}// --------------------------------------------------------

	
	/**
	 * @return the inputsPositions
	 */
	public int[] getInputsPositions()
	{
		return inputsPositions;
	}


	/**
	 * @param inputsPositions the inputsPositions to set
	 */
	public void setInputsPositions(int[] inputsPositions)
	{
		this.inputsPositions = inputsPositions;
	}

	
	/**
	 * @return the sql
	 */
	public String getSql()
	{
		return sql;
	}
	/**
	 * @param sql the sql to set
	 */
	public void setSql(String sql)
	{
		this.sql = sql;
	}


	private int[] inputsPositions;
	private String sql;
}