/* ************************************************************************
#
#  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.CompositeStruct;

/**
 * Assemble a generic Query request for the database.  A query request should not
 * call a stored procedure with parameters that will cause it to update/alter data
 * with in the database (other than temp tables and caches).  Other than that restriction
 * this class can call nearly any stored procedure if the parameters are assembled 
 * correctly.
 * 
 * @author Andy
 *
 */
public class QueryRequest implements IDatabaseRequest {
	protected CompositeStruct parameters = null;	
	protected String proc = null;
	
	/**
	 * Build an unguided query request.
	 * 
	 * @param proc procedure name to call
	 */
	public QueryRequest(String proc) {
		this.proc = proc;
	}
	
	/**
	 * Build an unguided query request.
	 * 
	 * @param proc procedure name to call
	 * @param params parameters to send to the procedure
	 */
	public QueryRequest(String proc, CompositeStruct params) {
		this.proc = proc;
		this.parameters = params;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#getDatabaseParams()
	 */
	@Override
	public CompositeStruct getDatabaseParams(IDatabaseManager dbm) {
		return this.parameters;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#isDatabaseUpdate()
	 */
	@Override
	public boolean isDatabaseUpdate() {
		return false;
	}

	/* (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
	}

	@Override
	public void process(DatabaseResult result) {
	}
}
