001/*
002 * Copyright 2002-2012 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 *      https://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.jdbc.datasource;
018
019import java.sql.Connection;
020import javax.sql.DataSource;
021
022/**
023 * Extension of the {@code javax.sql.DataSource} interface, to be
024 * implemented by special DataSources that return JDBC Connections
025 * in an unwrapped fashion.
026 *
027 * <p>Classes using this interface can query whether or not the Connection
028 * should be closed after an operation. Spring's DataSourceUtils and
029 * JdbcTemplate classes automatically perform such a check.
030 *
031 * @author Rod Johnson
032 * @author Juergen Hoeller
033 * @see SingleConnectionDataSource#shouldClose
034 * @see DataSourceUtils#releaseConnection
035 * @see org.springframework.jdbc.core.JdbcTemplate
036 */
037public interface SmartDataSource extends DataSource {
038
039        /**
040         * Should we close this Connection, obtained from this DataSource?
041         * <p>Code that uses Connections from a SmartDataSource should always
042         * perform a check via this method before invoking {@code close()}.
043         * <p>Note that the JdbcTemplate class in the 'jdbc.core' package takes care of
044         * releasing JDBC Connections, freeing application code of this responsibility.
045         * @param con the Connection to check
046         * @return whether the given Connection should be closed
047         * @see java.sql.Connection#close()
048         */
049        boolean shouldClose(Connection con);
050
051}