1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.dbcp2;
18
19 import java.sql.SQLException;
20
21 /**
22 * Defines the methods that will be made available via
23 * <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html">JMX</a>.
24 *
25 * @since 2.9.0
26 */
27 public interface DataSourceMXBean {
28
29 /**
30 * See {@link BasicDataSource#getAbandonedUsageTracking()}.
31 *
32 * @return {@link BasicDataSource#getAbandonedUsageTracking()}
33 */
34 boolean getAbandonedUsageTracking();
35
36 /**
37 * See {@link BasicDataSource#getCacheState()}.
38 *
39 * @return {@link BasicDataSource#getCacheState()}.
40 */
41 boolean getCacheState();
42
43 /**
44 * See {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
45 *
46 * @return {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
47 */
48 String[] getConnectionInitSqlsAsArray();
49
50 /**
51 * See {@link BasicDataSource#getDefaultAutoCommit()}.
52 *
53 * @return {@link BasicDataSource#getDefaultAutoCommit()}.
54 */
55 Boolean getDefaultAutoCommit();
56
57 /**
58 * See {@link BasicDataSource#getDefaultCatalog()}.
59 *
60 * @return {@link BasicDataSource#getDefaultCatalog()}.
61 */
62 String getDefaultCatalog();
63
64 /**
65 * See {@link BasicDataSource#getDefaultReadOnly()}.
66 *
67 * @return {@link BasicDataSource#getDefaultReadOnly()}.
68 */
69 Boolean getDefaultReadOnly();
70
71 /**
72 * See {@link BasicDataSource#getDefaultSchema()}.
73 *
74 * @return {@link BasicDataSource#getDefaultSchema()}.
75 * @since 2.5.0
76 */
77 default String getDefaultSchema() {
78 return null;
79 }
80
81 /**
82 * See {@link BasicDataSource#getDefaultTransactionIsolation()}.
83 *
84 * @return {@link BasicDataSource#getDefaultTransactionIsolation()}.
85 */
86 int getDefaultTransactionIsolation();
87
88 /**
89 * See {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
90 *
91 * @return {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
92 * @since 2.13.0
93 */
94 default String[] getDisconnectionIgnoreSqlCodesAsArray() {
95 return Utils.EMPTY_STRING_ARRAY;
96 }
97
98 /**
99 * See {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}.
100 *
101 * @return {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}.
102 * @since 2.1
103 */
104 String[] getDisconnectionSqlCodesAsArray();
105
106 /**
107 * See {@link BasicDataSource#getDriverClassName()}.
108 *
109 * @return {@link BasicDataSource#getDriverClassName()}.
110 */
111 String getDriverClassName();
112
113 /**
114 * See {@link BasicDataSource#getFastFailValidation()}.
115 *
116 * @return {@link BasicDataSource#getFastFailValidation()}.
117 * @since 2.1
118 */
119 boolean getFastFailValidation();
120
121 /**
122 * See {@link BasicDataSource#getInitialSize()}.
123 *
124 * @return {@link BasicDataSource#getInitialSize()}.
125 */
126 int getInitialSize();
127
128 /**
129 * See {@link BasicDataSource#getLifo()}.
130 *
131 * @return {@link BasicDataSource#getLifo()}.
132 */
133 boolean getLifo();
134
135 /**
136 * See {@link BasicDataSource#getLogAbandoned()}.
137 *
138 * @return {@link BasicDataSource#getLogAbandoned()}.
139 */
140 boolean getLogAbandoned();
141
142 /**
143 * See {@link BasicDataSource#getLogExpiredConnections()}.
144 *
145 * @return {@link BasicDataSource#getLogExpiredConnections()}.
146 * @since 2.1
147 */
148 boolean getLogExpiredConnections();
149
150 /**
151 * See {@link BasicDataSource#getMaxConnLifetimeMillis()}.
152 *
153 * @return {@link BasicDataSource#getMaxConnLifetimeMillis()}.
154 */
155 long getMaxConnLifetimeMillis();
156
157 /**
158 * See {@link BasicDataSource#getMaxIdle()}.
159 *
160 * @return {@link BasicDataSource#getMaxIdle()}.
161 */
162 int getMaxIdle();
163
164 /**
165 * See {@link BasicDataSource#getMaxOpenPreparedStatements()}.
166 *
167 * @return {@link BasicDataSource#getMaxOpenPreparedStatements()}.
168 */
169 int getMaxOpenPreparedStatements();
170
171 /**
172 * See {@link BasicDataSource#getMaxTotal()}.
173 *
174 * @return {@link BasicDataSource#getMaxTotal()}.
175 */
176 int getMaxTotal();
177
178 /**
179 * See {@link BasicDataSource#getMaxWaitMillis()}.
180 *
181 * @return {@link BasicDataSource#getMaxWaitMillis()}.
182 */
183 long getMaxWaitMillis();
184
185 /**
186 * See {@link BasicDataSource#getMinEvictableIdleTimeMillis()}.
187 *
188 * @return {@link BasicDataSource#getMinEvictableIdleTimeMillis()}.
189 */
190 long getMinEvictableIdleTimeMillis();
191
192 /**
193 * See {@link BasicDataSource#getMinIdle()}.
194 *
195 * @return {@link BasicDataSource#getMinIdle()}.
196 */
197 int getMinIdle();
198
199 /**
200 * See {@link BasicDataSource#getNumActive()}.
201 *
202 * @return {@link BasicDataSource#getNumActive()}.
203 */
204 int getNumActive();
205
206 /**
207 * See {@link BasicDataSource#getNumIdle()}.
208 *
209 * @return {@link BasicDataSource#getNumIdle()}.
210 */
211 int getNumIdle();
212
213 /**
214 * See {@link BasicDataSource#getNumTestsPerEvictionRun()}.
215 *
216 * @return {@link BasicDataSource#getNumTestsPerEvictionRun()}.
217 */
218 int getNumTestsPerEvictionRun();
219
220 /**
221 * See {@link BasicDataSource#getRemoveAbandonedOnBorrow()}.
222 *
223 * @return {@link BasicDataSource#getRemoveAbandonedOnBorrow()}.
224 */
225 boolean getRemoveAbandonedOnBorrow();
226
227 /**
228 * See {@link BasicDataSource#getRemoveAbandonedOnMaintenance()}.
229 *
230 * @return {@link BasicDataSource#getRemoveAbandonedOnMaintenance()}.
231 */
232 boolean getRemoveAbandonedOnMaintenance();
233
234 /**
235 * See {@link BasicDataSource#getRemoveAbandonedTimeout()}.
236 *
237 * @return {@link BasicDataSource#getRemoveAbandonedTimeout()}.
238 */
239 int getRemoveAbandonedTimeout();
240
241 /**
242 * See {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()}.
243 *
244 * @return {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()}.
245 */
246 long getSoftMinEvictableIdleTimeMillis();
247
248 /**
249 * See {@link BasicDataSource#getTestOnBorrow()}.
250 *
251 * @return {@link BasicDataSource#getTestOnBorrow()}.
252 */
253 boolean getTestOnBorrow();
254
255 /**
256 * See {@link BasicDataSource#getTestOnCreate()}.
257 *
258 * @return {@link BasicDataSource#getTestOnCreate()}.
259 */
260 boolean getTestOnCreate();
261
262 /**
263 * See {@link BasicDataSource#getTestWhileIdle()}.
264 *
265 * @return {@link BasicDataSource#getTestWhileIdle()}.
266 */
267 boolean getTestWhileIdle();
268
269 /**
270 * See {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()}.
271 *
272 * @return {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()}.
273 */
274 long getTimeBetweenEvictionRunsMillis();
275
276 /**
277 * See {@link BasicDataSource#getUrl()}.
278 *
279 * @return {@link BasicDataSource#getUrl()}.
280 */
281 String getUrl();
282
283 /**
284 * See {@link BasicDataSource#getUsername()}.
285 *
286 * @return {@link BasicDataSource#getUsername()}.
287 * @deprecated Use {@link #getUserName()}.
288 */
289 @Deprecated
290 String getUsername();
291
292 /**
293 * See {@link BasicDataSource#getUsername()}.
294 *
295 * @return {@link BasicDataSource#getUsername()}.
296 * @since 2.11.0
297 */
298 default String getUserName() {
299 return getUsername();
300 }
301
302 /**
303 * See {@link BasicDataSource#getValidationQuery()}.
304 *
305 * @return {@link BasicDataSource#getValidationQuery()}.
306 */
307 String getValidationQuery();
308
309 /**
310 * See {@link BasicDataSource#getValidationQueryTimeout()}.
311 *
312 * @return {@link BasicDataSource#getValidationQueryTimeout()}.
313 */
314 int getValidationQueryTimeout();
315
316 /**
317 * See {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()}.
318 *
319 * @return {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()}.
320 */
321 boolean isAccessToUnderlyingConnectionAllowed();
322
323 /**
324 * See {@link BasicDataSource#isClearStatementPoolOnReturn()}.
325 *
326 * @return {@link BasicDataSource#isClearStatementPoolOnReturn()}.
327 * @since 2.8.0
328 */
329 default boolean isClearStatementPoolOnReturn() {
330 return false;
331 }
332
333 /**
334 * See {@link BasicDataSource#isClosed()}.
335 *
336 * @return {@link BasicDataSource#isClosed()}.
337 */
338 boolean isClosed();
339
340 /**
341 * See {@link BasicDataSource#isPoolPreparedStatements()}.
342 *
343 * @return {@link BasicDataSource#isPoolPreparedStatements()}.
344 */
345 boolean isPoolPreparedStatements();
346
347 /**
348 * See {@link BasicDataSource#restart()}
349 *
350 * @throws SQLException if an error occurs initializing the data source.
351 *
352 * @since 2.8.0
353 */
354 default void restart() throws SQLException {
355 // do nothing by default?
356 }
357
358 /**
359 * See {@link BasicDataSource#start()}
360 *
361 * @throws SQLException if an error occurs initializing the data source.
362 *
363 * @since 2.8.0
364 */
365 default void start() throws SQLException {
366 // do nothing
367 }
368 }