56380
|
1 |
/*
|
56475
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
56380
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.incubator.sql2;
|
|
27 |
|
|
28 |
import java.util.function.Function;
|
|
29 |
import java.time.Duration;
|
|
30 |
import java.util.concurrent.Executor;
|
|
31 |
import java.util.concurrent.ForkJoinPool;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* A set of {@link ConnectionProperty} commonly supported. Implementations are not
|
|
35 |
* required to support all of these properties.
|
56797
|
36 |
*
|
|
37 |
* ISSUE: Need others such as IDLE_TIMEOUT, TIME_TO_LIVE_TIMEOUT, etc. Can we
|
|
38 |
* get away with just ConnectionProperties or do we need DataSourceProperties
|
|
39 |
* as well, MAX_CACHED_CONNECTIONS, etc?
|
56380
|
40 |
*
|
|
41 |
*/
|
|
42 |
public enum AdbaConnectionProperty implements ConnectionProperty {
|
|
43 |
|
|
44 |
/**
|
|
45 |
*
|
|
46 |
*/
|
|
47 |
CACHING(Caching.class,
|
|
48 |
v -> v instanceof Caching,
|
56475
|
49 |
Caching.AS_NEW,
|
56380
|
50 |
false),
|
|
51 |
|
|
52 |
/**
|
|
53 |
*
|
|
54 |
*/
|
|
55 |
EXECUTOR(Executor.class,
|
|
56 |
v -> v instanceof Executor,
|
|
57 |
ForkJoinPool.commonPool(),
|
|
58 |
false),
|
|
59 |
|
|
60 |
/**
|
|
61 |
*
|
|
62 |
*/
|
|
63 |
CONNECT_TIMEOUT(Duration.class,
|
|
64 |
v -> v instanceof Duration && ! ((Duration)v).isNegative(),
|
|
65 |
Duration.ofSeconds(Long.MAX_VALUE),
|
|
66 |
false),
|
|
67 |
|
|
68 |
/**
|
|
69 |
*
|
|
70 |
*/
|
|
71 |
HOLDABILITY(Holdability.class,
|
|
72 |
v -> v instanceof Holdability,
|
|
73 |
Holdability.HOLD_OVER_COMMIT,
|
|
74 |
false),
|
|
75 |
|
|
76 |
/**
|
|
77 |
*
|
|
78 |
*/
|
56475
|
79 |
NETWORK_TIMEOUT(Duration.class,
|
|
80 |
v -> v instanceof Duration && ! ((Duration)v).isNegative(),
|
|
81 |
Duration.ofSeconds(Long.MAX_VALUE),
|
56380
|
82 |
false),
|
|
83 |
|
|
84 |
/**
|
|
85 |
*
|
|
86 |
*/
|
|
87 |
PASSWORD(String.class,
|
|
88 |
v -> v instanceof String,
|
|
89 |
null,
|
|
90 |
true),
|
|
91 |
|
|
92 |
/**
|
|
93 |
*
|
|
94 |
*/
|
|
95 |
READ_ONLY(Boolean.class,
|
|
96 |
v -> v instanceof Boolean,
|
|
97 |
false,
|
|
98 |
false),
|
|
99 |
|
|
100 |
/**
|
|
101 |
*
|
|
102 |
*/
|
|
103 |
SHARDING_KEY(ShardingKey.class,
|
|
104 |
v -> v instanceof ShardingKey,
|
|
105 |
null,
|
|
106 |
false),
|
|
107 |
|
|
108 |
/**
|
|
109 |
*
|
|
110 |
*/
|
|
111 |
SHARDING_GROUP_KEY(ShardingKey.class,
|
|
112 |
v -> v instanceof ShardingKey,
|
|
113 |
null,
|
|
114 |
false),
|
|
115 |
|
|
116 |
/**
|
|
117 |
*
|
|
118 |
*/
|
|
119 |
TRANSACTION_ISOLATION(TransactionIsolation.class,
|
|
120 |
v -> v instanceof TransactionIsolation,
|
|
121 |
TransactionIsolation.READ_COMMITTED,
|
|
122 |
false),
|
|
123 |
|
|
124 |
/**
|
|
125 |
*
|
|
126 |
*/
|
|
127 |
URL(String.class,
|
|
128 |
v -> v instanceof String,
|
|
129 |
null,
|
|
130 |
false),
|
|
131 |
|
|
132 |
/**
|
|
133 |
*
|
|
134 |
*/
|
|
135 |
USER(String.class,
|
|
136 |
v -> v instanceof String,
|
|
137 |
null,
|
|
138 |
false);
|
|
139 |
|
|
140 |
private final Class<?> range;
|
|
141 |
private final Function<Object, Boolean> validator;
|
|
142 |
private final Object defaultValue;
|
|
143 |
private final boolean isSensitive;
|
|
144 |
|
|
145 |
private AdbaConnectionProperty(Class<?> range,
|
|
146 |
Function<Object, Boolean> validator,
|
|
147 |
Object value,
|
|
148 |
boolean isSensitive) {
|
|
149 |
this.range = range;
|
|
150 |
this.validator = validator;
|
|
151 |
this.defaultValue = value;
|
|
152 |
this.isSensitive = isSensitive;
|
|
153 |
}
|
|
154 |
|
|
155 |
@Override
|
|
156 |
public Class<?> range() {
|
|
157 |
return range;
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
|
161 |
public boolean validate(Object value) {
|
|
162 |
return validator.apply(value);
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
public Object defaultValue() {
|
|
167 |
return defaultValue;
|
|
168 |
}
|
|
169 |
|
|
170 |
@Override
|
|
171 |
public boolean isSensitive() {
|
|
172 |
return isSensitive;
|
|
173 |
}
|
|
174 |
|
|
175 |
/**
|
|
176 |
*
|
|
177 |
*/
|
|
178 |
public enum Caching {
|
|
179 |
/**
|
|
180 |
* The returned {@link Connection} is required to be completely new and configured
|
|
181 |
* exactly as specified by the other properties. Use this with caution and
|
|
182 |
* only when absolutely necessary. Use {@link AS_NEW} instead if at all possible.
|
|
183 |
* This should be used only to work around some limitation of the database
|
|
184 |
* or the implementation.
|
|
185 |
*/
|
|
186 |
NEW,
|
|
187 |
/**
|
|
188 |
* The returned {@link Connection} has no state other than that of a new Connection
|
|
189 |
* modified as specified by the other properties. May not be strictly new
|
|
190 |
* but has the same behavior as a new {@link Connection}. The {@link Connection} may be {@link NEW}. The default.
|
|
191 |
*/
|
|
192 |
AS_NEW,
|
|
193 |
/**
|
|
194 |
* The returned {@link Connection} has the state specified by the other properties
|
|
195 |
* but may have additional state that differs from that of a new {@link Connection}.
|
|
196 |
* The {@link Connection} may be {@link AS_NEW}.
|
|
197 |
*/
|
|
198 |
CACHED;
|
|
199 |
}
|
|
200 |
|
|
201 |
/**
|
|
202 |
*
|
|
203 |
*/
|
|
204 |
public enum TransactionIsolation {
|
|
205 |
|
|
206 |
/**
|
|
207 |
*
|
|
208 |
*/
|
|
209 |
NONE,
|
|
210 |
|
|
211 |
/**
|
|
212 |
*
|
|
213 |
*/
|
|
214 |
READ_COMMITTED,
|
|
215 |
|
|
216 |
/**
|
|
217 |
*
|
|
218 |
*/
|
|
219 |
READ_UNCOMMITTED,
|
|
220 |
|
|
221 |
/**
|
|
222 |
*
|
|
223 |
*/
|
|
224 |
REPEATABLE_READ,
|
|
225 |
|
|
226 |
/**
|
|
227 |
*
|
|
228 |
*/
|
|
229 |
SERIALIZABLE;
|
|
230 |
}
|
|
231 |
|
|
232 |
/**
|
|
233 |
*
|
|
234 |
*/
|
|
235 |
public enum Holdability {
|
|
236 |
|
|
237 |
/**
|
|
238 |
*
|
|
239 |
*/
|
|
240 |
HOLD_OVER_COMMIT,
|
|
241 |
|
|
242 |
/**
|
|
243 |
*
|
|
244 |
*/
|
|
245 |
CLOSE_AT_COMMIT;
|
|
246 |
}
|
|
247 |
|
|
248 |
}
|