001package org.apache.commons.jcs.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.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
027
028
029/**
030 * A factory that returns a DataSource.
031 * Borrowed from Apache DB Torque
032 *
033 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
034 * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
035 * @version $Id: DataSourceFactory.java 1336091 2012-05-09 11:09:40Z tfischer $
036 */
037public interface DataSourceFactory
038{
039    /**
040     * Key for the configuration which contains DataSourceFactories
041     */
042    String DSFACTORY_KEY = "dsfactory";
043
044    /**
045     *  Key for the configuration which contains the fully qualified name
046     *  of the factory implementation class
047     */
048    String FACTORY_KEY = "factory";
049
050    /**
051     * @return the name of the factory.
052     */
053    String getName();
054
055    /**
056     * @return the <code>DataSource</code> configured by the factory.
057     * @throws SQLException if the source can't be returned
058     */
059    DataSource getDataSource() throws SQLException;
060
061    /**
062     * Initialize the factory.
063     *
064     * @param config the factory settings
065     * @throws SQLException Any exceptions caught during processing will be
066     *         rethrown wrapped into a SQLException.
067     */
068    void initialize(JDBCDiskCacheAttributes config)
069        throws SQLException;
070
071    /**
072     * A hook which is called when the resources of the associated DataSource
073     * can be released.
074     * After close() is called, the other methods may not work any more
075     * (e.g. getDataSource() might return null).
076     * It is not guaranteed that this method does anything. For example,
077     * we do not want to close connections retrieved via JNDI, so the
078     * JndiDataSouurceFactory does not close these connections
079     *
080     * @throws SQLException Any exceptions caught during processing will be
081     *         rethrown wrapped into a SQLException.
082     */
083    void close()
084        throws SQLException;
085}