package com.product.data.entity;
|
|
import com.product.common.lang.StringUtils;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.data.config.CmnConst;
|
import com.product.data.config.DatabaseType;
|
|
/**
|
* @Author cheng
|
* @Date 2022/2/5 16:45
|
* @Desc 数据库配置
|
*/
|
public class DatabaseEntity {
|
|
private Class<?> DbTypeBase;
|
|
private int DbType;
|
|
private String userName;
|
|
private String passWord;
|
|
private String ip;
|
|
private String port;
|
|
private String DbName;
|
/**
|
* 实例名
|
* mysql oracle 无用
|
*/
|
private String DbInstance;
|
|
/**
|
* 自定义参数
|
* sqlserver oracle 无用
|
*/
|
private String customParams;
|
|
/**
|
* 仅Oracle使用
|
*/
|
private String serverName;
|
|
|
/**
|
* 仅Oracle使用
|
*/
|
private String sid;
|
|
public String getServerName() {
|
return serverName;
|
}
|
|
public void setServerName(String serverName) {
|
this.serverName = serverName;
|
}
|
|
public String getSid() {
|
return sid;
|
}
|
|
public void setSid(String sid) {
|
this.sid = sid;
|
}
|
|
public DatabaseEntity(int dbType) {
|
DbType = dbType;
|
}
|
|
@Override
|
public String toString() {
|
return "DatabaseEntity{" +
|
"DbType=" + DbType == null ? null : getDbType().getValue() +
|
", userName='" + userName + '\'' +
|
", passWord='" + passWord + '\'' +
|
", ip='" + ip + '\'' +
|
", port='" + port + '\'' +
|
", DbName='" + DbName + '\'' +
|
", DbInstance='" + DbInstance + '\'' +
|
", customParams='" + customParams + '\'' +
|
", serverName='" + serverName + '\'' +
|
", sid='" + sid + '\'' +
|
'}';
|
}
|
|
|
public DatabaseEntity(FieldSetEntity fse) {
|
this.DbTypeBase = DatabaseType.class;
|
init(fse);
|
}
|
|
protected void init(FieldSetEntity fse) {
|
if (CmnConst.TABLE_PRODUCT_SYS_DATASOURCE_CONFIG.equals(fse.getTableName())) {
|
DbType = fse.getInteger("datasource_type");
|
userName = fse.getString("username");
|
passWord = fse.getString("password");
|
ip = fse.getString("ip_address");
|
port = fse.getString("database_port");
|
customParams = fse.getString("link_params");
|
DbInstance = fse.getString("instance_name");
|
return;
|
}
|
DbType = fse.getInteger("db_type");
|
userName = fse.getString("user_name");
|
passWord = fse.getString("pass_word");
|
ip = fse.getString("ip");
|
port = fse.getString("port");
|
DbName = StringUtils.isEmpty(fse.getString("db_name")) ? fse.getString("user_name") : fse.getString("db_name");
|
serverName = fse.getString("server_name");
|
sid = fse.getString("sid");
|
customParams = fse.getString("custom_params");
|
DbInstance = fse.getString("instance");
|
}
|
|
public String getCustomParams() {
|
|
if (this.getDbType().equals(DatabaseType.MySql) && !StringUtils.isEmpty(this.customParams)) {
|
if (!"?".equals(this.customParams.substring(1))) {
|
return "?" + this.customParams;
|
}
|
}
|
return customParams == null ? "" : this.customParams;
|
}
|
|
public int getDbTypeByInt() {
|
return this.DbType;
|
}
|
|
public String getOnlyKey() {
|
String[] params = {DbType + "", ip, port, DbName, serverName, sid, DbInstance};
|
StringBuilder str = new StringBuilder();
|
for (String param : params) {
|
str.append(param == null ? "" : param).append("-");
|
}
|
return str.toString();
|
}
|
|
|
public void setCustomParams(String customParams) {
|
this.customParams = customParams;
|
}
|
|
public DatabaseType getDbType() {
|
return DatabaseType.getDataBaseType(this.DbType);
|
}
|
|
public String getUserName() {
|
return userName;
|
}
|
|
public void setUserName(String userName) {
|
this.userName = userName;
|
}
|
|
public String getPassWord() {
|
return passWord;
|
}
|
|
public void setPassWord(String passWord) {
|
this.passWord = passWord;
|
}
|
|
public String getIp() {
|
return ip;
|
}
|
|
public void setIp(String ip) {
|
this.ip = ip;
|
}
|
|
public String getDbName() {
|
return DbName;
|
}
|
|
public void setDbName(String dbName) {
|
DbName = dbName;
|
}
|
|
public String getDbInstance() {
|
return DbInstance;
|
}
|
|
public void setDbInstance(String dbInstance) {
|
DbInstance = dbInstance;
|
}
|
|
public String getPort() {
|
return port;
|
}
|
|
public void setPort(String port) {
|
this.port = port;
|
}
|
}
|