package info.bukova.isspst.services;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author Pepa Rokos
 */
public class HqlDataFilter {
	private String where;
	private String orderBy;
	private Map<String, Object> params;
	private Class<?> dataClass;

	public HqlDataFilter() {
		params = new HashMap<String, Object>();
	}

	public HqlDataFilter(String where) {
		this();
		this.where = where;
	}

	public HqlDataFilter(String where, String orderBy) {
		this(where);
		this.orderBy = orderBy;
	}

	public String getWhere() {
		return where;
	}

	public void setWhere(String where) {
		this.where = where;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public void setParam(String key, Object value) {
		params.put(key, value);
	}

	public Object getParam(String key) {
		return params.get(key);
	}

	public Set<String> getParamKeys() {
		return params.keySet();
	}

	public void andFilter(String filter) {
		if (where == null || where.isEmpty()) {
			where = filter;
		} else {
			where += " and (" + filter + ")";
		}
	}

	public void orFilter(String filter) {
		if (where == null ||where.isEmpty()) {
			where = filter;
		} else {
			where += " or (" + filter + ")";
		}
	}

	public void reset() {
		where = "";
		orderBy = "";
		params.clear();
	}

	public Class<?> getDataClass() {
		return dataClass;
	}

	public void setDataClass(Class<?> dataClass) {
		this.dataClass = dataClass;
	}
}
