001package org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.sql.SQLException; 023 024import javax.sql.DataSource; 025 026import org.apache.commons.jcs3.auxiliary.disk.jdbc.JDBCDiskCacheAttributes; 027 028 029/** 030 * A factory that returns a DataSource. 031 * Borrowed from Apache DB Torque 032 */ 033public interface DataSourceFactory 034{ 035 /** 036 * Key for the configuration which contains DataSourceFactories 037 */ 038 String DSFACTORY_KEY = "dsfactory"; 039 040 /** 041 * Key for the configuration which contains the fully qualified name 042 * of the factory implementation class 043 */ 044 String FACTORY_KEY = "factory"; 045 046 /** 047 * @return the name of the factory. 048 */ 049 String getName(); 050 051 /** 052 * @return the <code>DataSource</code> configured by the factory. 053 * @throws SQLException if the source can't be returned 054 */ 055 DataSource getDataSource() throws SQLException; 056 057 /** 058 * Initialize the factory. 059 * 060 * @param config the factory settings 061 * @throws SQLException Any exceptions caught during processing will be 062 * rethrown wrapped into a SQLException. 063 */ 064 void initialize(JDBCDiskCacheAttributes config) 065 throws SQLException; 066 067 /** 068 * A hook which is called when the resources of the associated DataSource 069 * can be released. 070 * After close() is called, the other methods may not work any more 071 * (e.g. getDataSource() might return null). 072 * It is not guaranteed that this method does anything. For example, 073 * we do not want to close connections retrieved via JNDI, so the 074 * JndiDataSouurceFactory does not close these connections 075 * 076 * @throws SQLException Any exceptions caught during processing will be 077 * rethrown wrapped into a SQLException. 078 */ 079 void close() 080 throws SQLException; 081}