1 /* 2 * Copyright 2002-2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jdbc.datasource; 18 19 import java.sql.Connection; 20 21 import javax.sql.DataSource; 22 23 /** 24 * Extension of the <code>javax.sql.DataSource</code> interface, to be 25 * implemented by special DataSources that return JDBC Connections 26 * in an unwrapped fashion. 27 * 28 * <p>Classes using this interface can query whether or not the Connection 29 * should be closed after an operation. Spring's DataSourceUtils and 30 * JdbcTemplate classes automatically perform such a check. 31 * 32 * @author Rod Johnson 33 * @author Juergen Hoeller 34 * @see SingleConnectionDataSource#shouldClose 35 * @see DataSourceUtils#releaseConnection 36 * @see org.springframework.jdbc.core.JdbcTemplate 37 */ 38 public interface SmartDataSource extends DataSource { 39 40 /** 41 * Should we close this Connection, obtained from this DataSource? 42 * <p>Code that uses Connections from a SmartDataSource should always 43 * perform a check via this method before invoking <code>close()</code>. 44 * <p>Note that the JdbcTemplate class in the 'jdbc.core' package takes care of 45 * releasing JDBC Connections, freeing application code of this responsibility. 46 * @param con the Connection to check 47 * @return whether the given Connection should be closed 48 * @see java.sql.Connection#close() 49 */ 50 boolean shouldClose(Connection con); 51 52 } 53