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

net.turnbig.qb.segment.SqlSegment Maven / Gradle / Ivy

The newest version!
package net.turnbig.qb.segment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author Woo Cupid
 * @date 2014年11月14日
 * @version $Revision$
 */
public abstract class SqlSegment {

	/**
	 * generate sql for the edu.woo.qb.segment
	 * 
	 * @return
	 */
	public abstract String asSql();

	/**
	 * whether required named query parameter for this edu.woo.qb.segment
	 * 
	 * @return
	 */
	public abstract boolean isParamRequired();

	/**
	 * named query parameter map
	 */
	protected Map params = new LinkedHashMap();
	protected Settings settings = Settings.namedQuery();

	public Map getParams() {
		return params;
	}

	public Map getKeyedParams() {
		Map map = new HashMap();
		map.putAll(params);
		return map;
	}

	public List getListParams() {
		List dest = new ArrayList();
		dest.addAll(params.values());
		return dest;
	}


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

	/**
	 * @return the settings
	 */
	public Settings getSettings() {
		return settings;
	}

	/**
	 * @param settings
	 *            the settings to set
	 */
	public void setSettings(Settings settings) {
		this.settings = settings;
	}

	@Override
	public String toString() {
		return "SqlSegment [Sql = " + asSql() + ", params = " + params + "]";
	}

}