/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved.
 * <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.constants;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 田平 create 2021年3月31日下午5:17:50
 */
@Slf4j
public class DSConstants {

	public static final String DATABASE_MYSQL = "mysql";
	public static final String DATABASE_POSTGRESQL = "postgresql";
	public static final String DATABASE_ORACLE = "oracle";
	public static final String DATABASE_INFORMIX = "informix";
	public static final String DATABASE_UNKNOWN = "unknown";
	public static final String DATABASE_DM = "dm";

	/**
	 * 不需要记录sql日志的表，比如各种日志表，防止sql日志表过大
	 */
	public static final List<String> NO_SQL_TABS = new ArrayList<>();

	static {
		NO_SQL_TABS.add("tma_sql_log");
		NO_SQL_TABS.add("tma_oper_log");
		NO_SQL_TABS.add("tma_http_log");
		NO_SQL_TABS.add("tma_call_log");
		NO_SQL_TABS.add("t_sql_log");
		NO_SQL_TABS.add("t_oper_log");
		NO_SQL_TABS.add("t_http_log");
		NO_SQL_TABS.add("t_call_log");
	}

	public static boolean containLogTable(String sql) {
		String checkSql = sql.toLowerCase();
		for (String tab : NO_SQL_TABS) {
			if (checkSql.indexOf(tab) > -1) {
				return false;
			}
		}
		return true;
	}

	public static final String POOL_NAME_SUFFIX = "-db-pool";

	public static final String AOP_POINTCUT_EXPRESSION = "execution(* com.crunii.micro..*Service.*(..))";

	//start数据源名称
	public static final String DB_MAIN = "main";

	//public static final String DB_LOG = "log";

	//end数据源名称

	/**
	 * 非jta事务配置文件前缀
	 */
	public static final String DATA_ID_DRUID_PREFIX = "db-druid-";
	/**
	 * jta事务配置前缀
	 */
	public static final String DATA_ID_JTA_PREFIX = "db-jta-";

	public static String getDruidDsDataId(String dbName, String dbType) {
		return DATA_ID_DRUID_PREFIX + dbName + "-" + dbType + ".yml";
	}

	public static String getJtaDsDataId(String dbName, String dbType) {
		return DATA_ID_JTA_PREFIX + dbName + "-" + dbType + ".yml";
	}

	public static void main(String[] args) {
		System.out.println(getDruidDsDataId("mysql", "main"));
		System.out.println(getJtaDsDataId("mysql", "main"));
		System.out.println(getDruidDsDataId("postgresql", "main"));
		System.out.println(getJtaDsDataId("postgresql", "main"));
	}

	public static final String DOMAIN_BASE_PKG = "com.crunii.micro.domain";

}
