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

me.icymint.libra.jdbc.model.SqlObject Maven / Gradle / Ivy

package me.icymint.libra.jdbc.model;

import me.icymint.libra.jdbc.LibraTemplate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 抽象SQL对象。
 * 
 * @author Daniel Yu
 * @since 2013-3-6
 * 
 */
public abstract class SqlObject {
	protected static String id(SqlInfo info, Object... values) {
		StringBuilder sb = new StringBuilder(info.getId());
		for (Object v : values) {
			sb.append("|");
			if (v != null)
				sb.append(v);
		}
		return info.mask(sb.toString());
	}

	protected Logger logger = LoggerFactory.getLogger(getClass());

	private String id;
	private String name;

	private SqlInfo si;

	protected SqlObject() {
	}

	/**
	 * Sql对象的Id号,其对所有Sql对象都必须唯一。
	 */
	public String getId() {
		return id;
	}

	public SqlInfo getInfo() {
		return si;
	}

	/**
	 * Sql对象的名称。其对同类Sql对象唯一。
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sql对象的前缀。
	 */
	public String getPrefix() {
		return this.getInfo().getPrefix();
	}

	protected LibraTemplate getTemplate() {
		return this.getInfo().getTemplate();
	}

	/**
	 * Sql对象是否被屏蔽。
	 */
	public boolean isMask() {
		return true;
	}

	protected void setId(String id) {
		this.id = id;
	}

	protected void setInfo(SqlInfo si) {
		this.si = si;
	}

	protected void setName(String name) {
		this.name = name;
	}

	/**
	 * Sql对象的实际名称。
	 */
	@Override
	public String toString() {
		if (this.isMask()) {
			String str = "";
			if (this.getPrefix() != null) {
				str = getPrefix() + "_";
			}
			return str + this.getInfo().mask(getName());
		} else {
			return getName();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy