ExternalDataSource.java 5.3 KB
Newer Older
R
test  
roo00 已提交
1 2 3 4 5 6
package com.x.base.core.project.config;

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

import org.apache.commons.lang3.BooleanUtils;
R
fix  
roo00 已提交
7
import org.apache.commons.lang3.StringUtils;
R
test  
roo00 已提交
8

R
fix  
roo00 已提交
9
import com.x.base.core.container.factory.SlicePropertiesBuilder;
R
test  
roo00 已提交
10
import com.x.base.core.project.annotation.FieldDescribe;
Z
zhourui 已提交
11
import com.x.base.core.project.tools.Crypto;
R
test  
roo00 已提交
12 13 14

public class ExternalDataSource extends ConfigObject {

Z
zhourui 已提交
15 16 17
	// 无需保存
	private transient String _password;

R
test  
roo00 已提交
18 19 20 21 22 23 24
	public ExternalDataSource() {
		this.enable = false;
		this.url = "";
		this.username = "";
		this.password = "";
		this.includes = new ArrayList<>();
		this.excludes = new ArrayList<>();
R
roo00 已提交
25 26 27
		this.driverClassName = "";
		this.dictionary = "";
		this.maxTotal = DEFAULT_MAXTOTAL;
R
update  
roo00 已提交
28
		this.maxIdle = DEFAULT_MAXIDLE;
29
		this.logLevel = DEFAULT_LOGLEVEL;
R
update  
roo00 已提交
30 31 32
		this.statEnable = DEFAULT_STATENABLE;
		this.statFilter = DEFAULT_STATFILTER;
		this.slowSqlMillis = DEFAULT_SLOWSQLMILLIS;
R
test  
roo00 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46
	}

	public static ExternalDataSource defaultInstance() {
		return new ExternalDataSource();
	}

	@FieldDescribe("是否启用,可以使用切片方式启用多个数据以提高性能,如果启用多个数据库,那么必须是相同类型的,不能混用,且用户名密码必须一致.")
	private Boolean enable;
	@FieldDescribe("jdbc连接地址")
	private String url;
	@FieldDescribe("数据库jdbc连接用户名")
	private String username;
	@FieldDescribe("数据库jdbc连接密码")
	private String password;
R
fix  
roo00 已提交
47 48 49 50
	@FieldDescribe("数据库驱动类名")
	private String driverClassName;
	@FieldDescribe("方言")
	private String dictionary;
R
update  
roo00 已提交
51
	@FieldDescribe("最大使用连接数")
R
fix  
roo00 已提交
52
	private Integer maxTotal;
R
update  
roo00 已提交
53 54 55 56 57 58 59 60
	@FieldDescribe("最大空闲连接数")
	private Integer maxIdle;
	@FieldDescribe("启用统计,默认启用")
	private Boolean statEnable;
	@FieldDescribe("统计方式配置,默认mergeStat")
	private String statFilter;
	@FieldDescribe("执行缓慢sql毫秒数,默认2000毫秒,执行缓慢的sql将被单独记录.")
	private Integer slowSqlMillis;
R
fix  
roo00 已提交
61

R
test  
roo00 已提交
62 63 64 65
	@FieldDescribe("设置此数据库存储的类,默认情况下存储所有类型,如果需要对每个类进行单独的控制以达到高性能,可以将不同的类存储到不同的节点上提高性能.可以使用通配符*")
	private List<String> includes;
	@FieldDescribe("在此节点上不存储的类,和includes一起设置实际存储的类,可以使用通配符*")
	private List<String> excludes;
66 67
	@FieldDescribe("默认日志级别,FATAL, ERROR, WARN, INFO, TRACE. 完成的配置为DefaultLevel=WARN, Tool=TRACE, Enhance=TRACE, METADATA=TRACE, Runtime=TRACE, Query=TRACE, DataCache=TRACE, JDBC=TRACE, SQL=TRACE")
	private String logLevel = DEFAULT_LOGLEVEL;
R
fix  
roo00 已提交
68 69 70

	public static final Integer DEFAULT_MAXTOTAL = 50;

R
update  
roo00 已提交
71 72 73 74 75 76 77 78
	public static final Integer DEFAULT_MAXIDLE = 0;

	public static final Boolean DEFAULT_STATENABLE = true;

	public static final String DEFAULT_STATFILTER = "mergeStat";

	public static final Integer DEFAULT_SLOWSQLMILLIS = 2000;

79 80 81 82
	public static final String DEFAULT_LOGLEVEL = "WARN";

	public String getLogLevel() {
		return StringUtils.isEmpty(this.logLevel) ? DEFAULT_LOGLEVEL : this.logLevel;
R
fix  
roo00 已提交
83 84 85 86 87 88 89 90 91 92 93 94
	}

	public String getDriverClassName() throws Exception {
		return StringUtils.isEmpty(this.driverClassName) ? SlicePropertiesBuilder.driverClassNameOfUrl(this.url)
				: this.driverClassName;
	}

	public String getDictionary() throws Exception {
		return StringUtils.isEmpty(this.dictionary) ? SlicePropertiesBuilder.dictionaryOfUrl(this.url)
				: this.dictionary;
	}

R
update  
roo00 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	public Integer getSlowSqlMillis() {
		return (null == this.slowSqlMillis || this.slowSqlMillis < 1) ? DEFAULT_SLOWSQLMILLIS : this.slowSqlMillis;
	}

	public String getStatFilter() {
		return StringUtils.isEmpty(this.statFilter) ? DEFAULT_STATFILTER : this.statFilter;
	}

	public Boolean getStatEnable() {
		return BooleanUtils.isNotFalse(this.statEnable);
	}

	public Integer getMaxIdle() {
		if ((this.maxIdle == null) || (this.maxIdle < 1)) {
			return DEFAULT_MAXIDLE;
		} else {
			return this.maxTotal;
		}
	}

R
fix  
roo00 已提交
115
	public Integer getMaxTotal() {
R
update  
roo00 已提交
116
		if ((this.maxTotal == null) || (this.maxTotal < 0)) {
R
fix  
roo00 已提交
117 118 119 120 121
			return DEFAULT_MAXTOTAL;
		} else {
			return this.maxTotal;
		}
	}
R
test  
roo00 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

	public Boolean getEnable() {
		return BooleanUtils.isTrue(this.enable);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
Z
zhourui 已提交
144 145 146 147
		if (StringUtils.isEmpty(this._password)) {
			this._password = Crypto.plainText(this.password);
		}
		return this._password;
R
test  
roo00 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<String> getIncludes() {
		return includes;
	}

	public void setIncludes(List<String> includes) {
		this.includes = includes;
	}

	public List<String> getExcludes() {
		return excludes;
	}

	public void setExcludes(List<String> excludes) {
		this.excludes = excludes;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

R
fix  
roo00 已提交
174 175
	public void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
R
test  
roo00 已提交
176 177
	}

R
fix  
roo00 已提交
178 179
	public void setDictionary(String dictionary) {
		this.dictionary = dictionary;
R
test  
roo00 已提交
180 181
	}

R
fix  
roo00 已提交
182 183
	public void setMaxTotal(Integer maxTotal) {
		this.maxTotal = maxTotal;
R
test  
roo00 已提交
184 185
	}

186
	public void setLogLevel(String logLevel) {
R
fix  
roo00 已提交
187
		this.logLevel = logLevel;
R
test  
roo00 已提交
188 189 190
	}

}