1 package org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.sql.SQLException; 23 24 import javax.sql.DataSource; 25 26 import org.apache.commons.jcs3.auxiliary.disk.jdbc.JDBCDiskCacheAttributes; 27 28 29 /** 30 * A factory that returns a DataSource. 31 * Borrowed from Apache DB Torque 32 */ 33 public interface DataSourceFactory 34 { 35 /** 36 * Key for the configuration which contains DataSourceFactories 37 */ 38 String DSFACTORY_KEY = "dsfactory"; 39 40 /** 41 * Key for the configuration which contains the fully qualified name 42 * of the factory implementation class 43 */ 44 String FACTORY_KEY = "factory"; 45 46 /** 47 * @return the name of the factory. 48 */ 49 String getName(); 50 51 /** 52 * @return the <code>DataSource</code> configured by the factory. 53 * @throws SQLException if the source can't be returned 54 */ 55 DataSource getDataSource() throws SQLException; 56 57 /** 58 * Initialize the factory. 59 * 60 * @param config the factory settings 61 * @throws SQLException Any exceptions caught during processing will be 62 * rethrown wrapped into a SQLException. 63 */ 64 void initialize(JDBCDiskCacheAttributes config) 65 throws SQLException; 66 67 /** 68 * A hook which is called when the resources of the associated DataSource 69 * can be released. 70 * After close() is called, the other methods may not work any more 71 * (e.g. getDataSource() might return null). 72 * It is not guaranteed that this method does anything. For example, 73 * we do not want to close connections retrieved via JNDI, so the 74 * JndiDataSouurceFactory does not close these connections 75 * 76 * @throws SQLException Any exceptions caught during processing will be 77 * rethrown wrapped into a SQLException. 78 */ 79 void close() 80 throws SQLException; 81 }