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

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

package me.icymint.libra.jdbc.model;

import java.util.concurrent.atomic.AtomicInteger;

import javax.sql.DataSource;

import me.icymint.libra.jdbc.LibraTemplate;
import me.icymint.libra.jdbc.mask.Mask;

/**
 * 数据库索引。
 * 
 * @author Daniel Yu
 * @since 2013-3-12
 * 
 */
public class SqlInfo extends SqlObject {

	private final Mask mask;
	private final String prefix;
	private final LibraTemplate lt;
	private static AtomicInteger ai = new AtomicInteger();

	/**
	 * 
	 * @param mask
	 *            屏蔽码。
	 * @param prefix
	 *            数据库前缀。
	 * @param database
	 *            该数据库索引字段,并不是数据库名。
	 * @param ds
	 *            数据源,其指定数据库名称。
	 */
	public SqlInfo(Mask mask, String prefix, String database, DataSource ds) {
		if (mask == null)
			mask = Mask.DEFAULT;
		this.mask = mask;
		if (prefix != null && prefix.equals(""))
			prefix = null;
		this.prefix = prefix;
		this.setId(String.valueOf(ai.getAndIncrement()));
		this.setName(database);
		this.lt = new LibraTemplate(ds);
	}

	@Override
	public SqlInfo getInfo() {
		return this;
	}

	@Override
	public String getPrefix() {
		return prefix;
	}

	@Override
	public LibraTemplate getTemplate() {
		return lt;
	}

	public String mask(String str) {
		return mask.mask(str);
	}

	@Override
	public String toString() {
		return this.getName();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy