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