DataSourceMXBean.java

  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. import java.sql.SQLException;

  19. /**
  20.  * Defines the methods that will be made available via
  21.  * <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html">JMX</a>.
  22.  *
  23.  * @since 2.9.0
  24.  */
  25. public interface DataSourceMXBean {

  26.     /**
  27.      * See {@link BasicDataSource#getAbandonedUsageTracking()}.
  28.      *
  29.      * @return {@link BasicDataSource#getAbandonedUsageTracking()}
  30.      */
  31.     boolean getAbandonedUsageTracking();

  32.     /**
  33.      * See {@link BasicDataSource#getCacheState()}.
  34.      *
  35.      * @return {@link BasicDataSource#getCacheState()}.
  36.      */
  37.     boolean getCacheState();

  38.     /**
  39.      * See {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
  40.      *
  41.      * @return {@link BasicDataSource#getConnectionInitSqlsAsArray()}.
  42.      */
  43.     String[] getConnectionInitSqlsAsArray();

  44.     /**
  45.      * See {@link BasicDataSource#getDefaultAutoCommit()}.
  46.      *
  47.      * @return {@link BasicDataSource#getDefaultAutoCommit()}.
  48.      */
  49.     Boolean getDefaultAutoCommit();

  50.     /**
  51.      * See {@link BasicDataSource#getDefaultCatalog()}.
  52.      *
  53.      * @return {@link BasicDataSource#getDefaultCatalog()}.
  54.      */
  55.     String getDefaultCatalog();

  56.     /**
  57.      * See {@link BasicDataSource#getDefaultReadOnly()}.
  58.      *
  59.      * @return {@link BasicDataSource#getDefaultReadOnly()}.
  60.      */
  61.     Boolean getDefaultReadOnly();

  62.     /**
  63.      * See {@link BasicDataSource#getDefaultSchema()}.
  64.      *
  65.      * @return {@link BasicDataSource#getDefaultSchema()}.
  66.      * @since 2.5.0
  67.      */
  68.     default String getDefaultSchema() {
  69.         return null;
  70.     }

  71.     /**
  72.      * See {@link BasicDataSource#getDefaultTransactionIsolation()}.
  73.      *
  74.      * @return {@link BasicDataSource#getDefaultTransactionIsolation()}.
  75.      */
  76.     int getDefaultTransactionIsolation();

  77.     /**
  78.      * See {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
  79.      *
  80.      * @return {@link BasicDataSource#getDisconnectionIgnoreSqlCodesAsArray()}.
  81.      * @since 2.13.0
  82.      */
  83.     default String[] getDisconnectionIgnoreSqlCodesAsArray() {
  84.         return Utils.EMPTY_STRING_ARRAY;
  85.     }

  86.     /**
  87.      * See {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}.
  88.      *
  89.      * @return {@link BasicDataSource#getDisconnectionSqlCodesAsArray()}.
  90.      * @since 2.1
  91.      */
  92.     String[] getDisconnectionSqlCodesAsArray();

  93.     /**
  94.      * See {@link BasicDataSource#getDriverClassName()}.
  95.      *
  96.      * @return {@link BasicDataSource#getDriverClassName()}.
  97.      */
  98.     String getDriverClassName();

  99.     /**
  100.      * See {@link BasicDataSource#getFastFailValidation()}.
  101.      *
  102.      * @return {@link BasicDataSource#getFastFailValidation()}.
  103.      * @since 2.1
  104.      */
  105.     boolean getFastFailValidation();

  106.     /**
  107.      * See {@link BasicDataSource#getInitialSize()}.
  108.      *
  109.      * @return {@link BasicDataSource#getInitialSize()}.
  110.      */
  111.     int getInitialSize();

  112.     /**
  113.      * See {@link BasicDataSource#getLifo()}.
  114.      *
  115.      * @return {@link BasicDataSource#getLifo()}.
  116.      */
  117.     boolean getLifo();

  118.     /**
  119.      * See {@link BasicDataSource#getLogAbandoned()}.
  120.      *
  121.      * @return {@link BasicDataSource#getLogAbandoned()}.
  122.      */
  123.     boolean getLogAbandoned();

  124.     /**
  125.      * See {@link BasicDataSource#getLogExpiredConnections()}.
  126.      *
  127.      * @return {@link BasicDataSource#getLogExpiredConnections()}.
  128.      * @since 2.1
  129.      */
  130.     boolean getLogExpiredConnections();

  131.     /**
  132.      * See {@link BasicDataSource#getMaxConnLifetimeMillis()}.
  133.      *
  134.      * @return {@link BasicDataSource#getMaxConnLifetimeMillis()}.
  135.      */
  136.     long getMaxConnLifetimeMillis();

  137.     /**
  138.      * See {@link BasicDataSource#getMaxIdle()}.
  139.      *
  140.      * @return {@link BasicDataSource#getMaxIdle()}.
  141.      */
  142.     int getMaxIdle();

  143.     /**
  144.      * See {@link BasicDataSource#getMaxOpenPreparedStatements()}.
  145.      *
  146.      * @return {@link BasicDataSource#getMaxOpenPreparedStatements()}.
  147.      */
  148.     int getMaxOpenPreparedStatements();

  149.     /**
  150.      * See {@link BasicDataSource#getMaxTotal()}.
  151.      *
  152.      * @return {@link BasicDataSource#getMaxTotal()}.
  153.      */
  154.     int getMaxTotal();

  155.     /**
  156.      * See {@link BasicDataSource#getMaxWaitMillis()}.
  157.      *
  158.      * @return {@link BasicDataSource#getMaxWaitMillis()}.
  159.      */
  160.     long getMaxWaitMillis();

  161.     /**
  162.      * See {@link BasicDataSource#getMinEvictableIdleTimeMillis()}.
  163.      *
  164.      * @return {@link BasicDataSource#getMinEvictableIdleTimeMillis()}.
  165.      */
  166.     long getMinEvictableIdleTimeMillis();

  167.     /**
  168.      * See {@link BasicDataSource#getMinIdle()}.
  169.      *
  170.      * @return {@link BasicDataSource#getMinIdle()}.
  171.      */
  172.     int getMinIdle();

  173.     /**
  174.      * See {@link BasicDataSource#getNumActive()}.
  175.      *
  176.      * @return {@link BasicDataSource#getNumActive()}.
  177.      */
  178.     int getNumActive();

  179.     /**
  180.      * See {@link BasicDataSource#getNumIdle()}.
  181.      *
  182.      * @return {@link BasicDataSource#getNumIdle()}.
  183.      */
  184.     int getNumIdle();

  185.     /**
  186.      * See {@link BasicDataSource#getNumTestsPerEvictionRun()}.
  187.      *
  188.      * @return {@link BasicDataSource#getNumTestsPerEvictionRun()}.
  189.      */
  190.     int getNumTestsPerEvictionRun();

  191.     /**
  192.      * See {@link BasicDataSource#getRemoveAbandonedOnBorrow()}.
  193.      *
  194.      * @return {@link BasicDataSource#getRemoveAbandonedOnBorrow()}.
  195.      */
  196.     boolean getRemoveAbandonedOnBorrow();

  197.     /**
  198.      * See {@link BasicDataSource#getRemoveAbandonedOnMaintenance()}.
  199.      *
  200.      * @return {@link BasicDataSource#getRemoveAbandonedOnMaintenance()}.
  201.      */
  202.     boolean getRemoveAbandonedOnMaintenance();

  203.     /**
  204.      * See {@link BasicDataSource#getRemoveAbandonedTimeout()}.
  205.      *
  206.      * @return {@link BasicDataSource#getRemoveAbandonedTimeout()}.
  207.      */
  208.     int getRemoveAbandonedTimeout();

  209.     /**
  210.      * See {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()}.
  211.      *
  212.      * @return {@link BasicDataSource#getSoftMinEvictableIdleTimeMillis()}.
  213.      */
  214.     long getSoftMinEvictableIdleTimeMillis();

  215.     /**
  216.      * See {@link BasicDataSource#getTestOnBorrow()}.
  217.      *
  218.      * @return {@link BasicDataSource#getTestOnBorrow()}.
  219.      */
  220.     boolean getTestOnBorrow();

  221.     /**
  222.      * See {@link BasicDataSource#getTestOnCreate()}.
  223.      *
  224.      * @return {@link BasicDataSource#getTestOnCreate()}.
  225.      */
  226.     boolean getTestOnCreate();

  227.     /**
  228.      * See {@link BasicDataSource#getTestWhileIdle()}.
  229.      *
  230.      * @return {@link BasicDataSource#getTestWhileIdle()}.
  231.      */
  232.     boolean getTestWhileIdle();

  233.     /**
  234.      * See {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()}.
  235.      *
  236.      * @return {@link BasicDataSource#getTimeBetweenEvictionRunsMillis()}.
  237.      */
  238.     long getTimeBetweenEvictionRunsMillis();

  239.     /**
  240.      * See {@link BasicDataSource#getUrl()}.
  241.      *
  242.      * @return {@link BasicDataSource#getUrl()}.
  243.      */
  244.     String getUrl();

  245.     /**
  246.      * See {@link BasicDataSource#getUsername()}.
  247.      *
  248.      * @return {@link BasicDataSource#getUsername()}.
  249.      * @deprecated Use {@link #getUserName()}.
  250.      */
  251.     @Deprecated
  252.     String getUsername();

  253.     /**
  254.      * See {@link BasicDataSource#getUsername()}.
  255.      *
  256.      * @return {@link BasicDataSource#getUsername()}.
  257.      * @since 2.11.0
  258.      */
  259.     default String getUserName() {
  260.         return getUsername();
  261.     }

  262.     /**
  263.      * See {@link BasicDataSource#getValidationQuery()}.
  264.      *
  265.      * @return {@link BasicDataSource#getValidationQuery()}.
  266.      */
  267.     String getValidationQuery();

  268.     /**
  269.      * See {@link BasicDataSource#getValidationQueryTimeout()}.
  270.      *
  271.      * @return {@link BasicDataSource#getValidationQueryTimeout()}.
  272.      */
  273.     int getValidationQueryTimeout();

  274.     /**
  275.      * See {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()}.
  276.      *
  277.      * @return {@link BasicDataSource#isAccessToUnderlyingConnectionAllowed()}.
  278.      */
  279.     boolean isAccessToUnderlyingConnectionAllowed();

  280.     /**
  281.      * See {@link BasicDataSource#isClearStatementPoolOnReturn()}.
  282.      *
  283.      * @return {@link BasicDataSource#isClearStatementPoolOnReturn()}.
  284.      * @since 2.8.0
  285.      */
  286.     default boolean isClearStatementPoolOnReturn() {
  287.         return false;
  288.     }

  289.     /**
  290.      * See {@link BasicDataSource#isClosed()}.
  291.      *
  292.      * @return {@link BasicDataSource#isClosed()}.
  293.      */
  294.     boolean isClosed();

  295.     /**
  296.      * See {@link BasicDataSource#isPoolPreparedStatements()}.
  297.      *
  298.      * @return {@link BasicDataSource#isPoolPreparedStatements()}.
  299.      */
  300.     boolean isPoolPreparedStatements();

  301.     /**
  302.      * See {@link BasicDataSource#restart()}
  303.      *
  304.      * @throws SQLException if an error occurs initializing the data source.
  305.      *
  306.      * @since 2.8.0
  307.      */
  308.     default void restart() throws SQLException {
  309.         // do nothing by default?
  310.     }

  311.     /**
  312.      * See {@link BasicDataSource#start()}
  313.      *
  314.      * @throws SQLException if an error occurs initializing the data source.
  315.      *
  316.      * @since 2.8.0
  317.      */
  318.     default void start() throws SQLException {
  319.         // do nothing
  320.     }
  321. }