1821349743@qq.com
2023-02-20 93dd9bc3f16b0f626761ec624f2dc78037568897
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
174
175
176
177
178
179
180
181
182
183
184
package com.product.data.entity;
 
import com.product.common.lang.StringUtils;
import com.product.core.entity.FieldSetEntity;
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) {
        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;
    }
}