shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.connector;
 
import com.walker.jdbc.util.StringSqlUtils;
import com.walker.jdbc.util.StringUtils;
 
/**
 * 定义数据库地址对象,也可以用于普通HTTP地址形势。不过目前主要在数据库采集模块中使用。
 * @author 时克英
 * @date 2022-09-09
 */
public class Address {
    private String url;
    private int port = 0;
    // 服务字符串,mysql中可能带有参数,如:walkersoft?encode=utf8
    private String service = StringUtils.EMPTY_STRING;
    // 服务名字,去掉了?参数信息,mysql会出现此情况
    private String serviceName = StringUtils.EMPTY_STRING;
    private String authentication;
    private String certification;
 
    private boolean using = false; // 是否正在使用
    private boolean used = false;  // 此库是否被使用过
    private int suffixIndex = 1; // 多个资源库时,后缀编号
 
    private int type = 1;
 
    private String id;
 
    /**
     * id对应数据库表中数据源主键,后追加
     * @date 2019-05-10
     * @return
     */
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    /**
     * 该字段表示数据库类型
     * @return
     * @author 时克英
     * @date 2019-05-10
     */
    public int getType() {
        return type;
    }
    public void setType(int type) {
        this.type = type;
    }
    public boolean isUsed() {
        return used;
    }
    public void setUsed(boolean used) {
        this.used = used;
    }
 
    public boolean isUsing() {
        return using;
    }
    public void setUsing(boolean use) {
        this.using = use;
    }
    public int getSuffixIndex() {
        return suffixIndex;
    }
    public void setSuffixIndex(int suffixIndex) {
        this.suffixIndex = suffixIndex;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }
 
    /**
     * 返回服务名称,如:数据库名称,目录文件夹等
     * @return
     */
    @Deprecated
    public String getService() {
        return service;
    }
 
    /**
     * 返回服务真正名字,去掉参数。因为在mysql中可能带有参数,如:walkersoft?encode=utf8
     * @return
     */
    public String getServiceName(){
        return serviceName;
    }
    public void setService(String service) {
        this.service = service;
        this.serviceName = StringSqlUtils.getMySQLSchemaName(service);
    }
 
    /**
     * 返回认证信息,如:用户名
     * @return
     */
    public String getAuthentication() {
        return authentication;
    }
    public void setAuthentication(String authentication) {
        this.authentication = authentication;
    }
 
    /**
     * 返回认证凭证,如:密码等
     * @return
     */
    public String getCertification() {
        return certification;
    }
    public void setCertification(String certification) {
        this.certification = certification;
    }
 
    @Override
    public boolean equals(Object obj){
        if(obj != null && obj instanceof Address){
            Address address = (Address)obj;
            if(address.url.equals(this.url)
                    && address.port == this.port
                    && address.serviceName.equals(this.serviceName)){
                return true;
            }
        }
        return false;
    }
 
    private int hashCode = 0;
 
    @Override
    public int hashCode(){
        if(hashCode == 0){
            hashCode = 31 + url.hashCode() + serviceName.hashCode() + port;
        }
        return hashCode;
    }
 
    @Override
    public String toString(){
        return new StringBuilder().append("address:[url=").append(url)
                .append(", port=").append(port)
                .append(", serviceName=").append(serviceName)
                .append(", suffixIndex=").append(suffixIndex)
                .append(", service=").append(service)
                .append("]").toString();
    }
 
    private int maxActive = 6;
    private int initSize = 3;
    private int maxIdle = 3;
 
    public int getMaxActive() {
        return maxActive;
    }
    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }
    public int getInitSize() {
        return initSize;
    }
    public void setInitSize(int initSize) {
        this.initSize = initSize;
    }
    public int getMaxIdle() {
        return maxIdle;
    }
    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }
 
}