/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.db;

import divconq.db.IDatabaseRequest;
import divconq.lang.OperationResult;
import divconq.struct.RecordStruct;

/**
 * Assemble a generic Update request for the database.  An update request should 
 * result in an update/alteration to data within the database (other than temp tables 
 * and caches).  There can be some auditing overhead with an update request, so use
 * QueryRequest when no data will be altered to fulfill this request.  
 * Other than that restriction this class can call nearly any stored procedure if 
 * the parameters are assembled correctly.
 * 
 * @author Andy
 *
 */
public class UpdateRequest implements IDatabaseRequest {
	protected RecordStruct parameters = null;	// TODO types
	protected String proc = null;
	
	/**
	 * Build an unguided update request.
	 * 
	 * @param proc procedure name to call
	 */
	public UpdateRequest(String proc) {
		this.proc = proc;
	}
	
	/**
	 * Build an unguided update request.
	 * 
	 * @param proc procedure name to call
	 * @param params parameters to send to the procedure
	 */
	public UpdateRequest(String proc, RecordStruct params) {
		this.proc = proc;
		this.parameters = params;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#getDatabaseParams()
	 */
	@Override
	public RecordStruct getDatabaseParams(IDatabaseManager dbm) {
		return this.parameters;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#isDatabaseUpdate()
	 */
	@Override
	public boolean isDatabaseUpdate() {
		return true;
	}

	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#isBulkyRequest()
	 */
	@Override
	public boolean isBulkyRequest() {
		return false;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#getProcedure()
	 */
	@Override
	public String getProcedure() {
		return this.proc;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#validate(divconq.lang.OperationResult)
	 */
	@Override
	public void validate(OperationResult or) {
		// NA
	}

	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#process(divconq.db.DatabaseResult)
	 */
	@Override
	public void process(DatabaseResult result) {
	}
}
