001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.jdbc.metadata;
018
019import javax.sql.DataSource;
020
021/**
022 * Provides access meta-data that is commonly available from most pooled
023 * {@link DataSource} implementations.
024 *
025 * @author Stephane Nicoll
026 * @since 2.0.0
027 */
028public interface DataSourcePoolMetadata {
029
030        /**
031         * Return the usage of the pool as value between 0 and 1 (or -1 if the pool is not
032         * limited).
033         * <ul>
034         * <li>1 means that the maximum number of connections have been allocated</li>
035         * <li>0 means that no connection is currently active</li>
036         * <li>-1 means there is not limit to the number of connections that can be allocated
037         * </li>
038         * </ul>
039         * This may also return {@code null} if the data source does not provide the necessary
040         * information to compute the poll usage.
041         * @return the usage value or {@code null}
042         */
043        Float getUsage();
044
045        /**
046         * Return the current number of active connections that have been allocated from the
047         * data source or {@code null} if that information is not available.
048         * @return the number of active connections or {@code null}
049         */
050        Integer getActive();
051
052        /**
053         * Return the maximum number of active connections that can be allocated at the same
054         * time or {@code -1} if there is no limit. Can also return {@code null} if that
055         * information is not available.
056         * @return the maximum number of active connections or {@code null}
057         */
058        Integer getMax();
059
060        /**
061         * Return the minimum number of idle connections in the pool or {@code null} if that
062         * information is not available.
063         * @return the minimum number of active connections or {@code null}
064         */
065        Integer getMin();
066
067        /**
068         * Return the query to use to validate that a connection is valid or {@code null} if
069         * that information is not available.
070         * @return the validation query or {@code null}
071         */
072        String getValidationQuery();
073
074        /**
075         * The default auto-commit state of connections created by this pool. If not set
076         * ({@code null}), default is JDBC driver default (If set to null then the
077         * java.sql.Connection.setAutoCommit(boolean) method will not be called.)
078         * @return the default auto-commit state or {@code null}
079         */
080        Boolean getDefaultAutoCommit();
081
082}