    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.dbcp2;
    018
    019import java.sql.SQLException;
    020
    021/**
    022 * Defines the methods that will be made available via
    023 * <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html">JMX</a>.
    024 *
    025 * @since 2.9.0
    026 */
    027public interface DataSourceMXBean {
    028
    029    /**
    030     * See {@link BasicDataSource#getAbandonedUsageTracking()}.
    031     *
    032     * @return {@link BasicDataSource#getAbandonedUsageTracking()}
    033     */
    034    boolean getAbandonedUsageTracking();
    035
    036    /**
    037     * See {@link BasicDataSource#getCacheState()}.
    038     *
    039     * @return {@link BasicDataSource#getCacheState()}.
    040     */
    041    boolean getCacheState();
    042
    043    /**
    044     * See {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
    045     *
    046     * @return {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
    047     */
    048    String[] getConnectionInitSqlsAsArray();
    049
    050    /**
    051     * See {@link BasicDataSource#getDefaultAutoCommit()}.
    052     *
    053     * @return {@link BasicDataSource#getDefaultAutoCommit()}.
    054     */
    055    Boolean getDefaultAutoCommit();
    056
    057    /**
    058     * See {@link BasicDataSource#getDefaultCatalog()}.
    059     *
    060     * @return {@link BasicDataSource#getDefaultCatalog()}.
    061     */
    062    String getDefaultCatalog();
    063
    064    /**
    065     * See {@link BasicDataSource#getDefaultReadOnly()}.
    066     *
    067     * @return {@link BasicDataSource#getDefaultReadOnly()}.
    068     */
    069    Boolean getDefaultReadOnly();
    070
    071    /**
    072     * See {@link BasicDataSource#getDefaultSchema()}.
    073     *
    074     * @return {@link BasicDataSource#getDefaultSchema()}.
    075     * @since 2.5.0
    076     */
    077    default String getDefaultSchema() {
    078        return null;
    079    }
    080
    081    /**
    082     * See {@link BasicDataSource#getDefaultTransactionIsolation()}.
    083     *
    084     * @return {@link BasicDataSource#getDefaultTransactionIsolation()}.
    085     */
    086    int getDefaultTransactionIsolation();
    087
    088    /**
    089     * See {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
    090     *
    091     * @return {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
    092     * @since 2.13.0
    093     */
    094    default String[] getDisconnectionIgnoreSqlCodesAsArray() {
    095        return Utils.EMPTY_STRING_ARRAY;
    096    }
    097
    098    /**
    099     * 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}