View Javadoc
1   package org.apache.commons.jcs.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.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
27  
28  
29  /**
30   * A factory that returns a DataSource.
31   * Borrowed from Apache DB Torque
32   *
33   * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
34   * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
35   * @version $Id: DataSourceFactory.java 1336091 2012-05-09 11:09:40Z tfischer $
36   */
37  public interface DataSourceFactory
38  {
39      /**
40       * Key for the configuration which contains DataSourceFactories
41       */
42      String DSFACTORY_KEY = "dsfactory";
43  
44      /**
45       *  Key for the configuration which contains the fully qualified name
46       *  of the factory implementation class
47       */
48      String FACTORY_KEY = "factory";
49  
50      /**
51       * @return the name of the factory.
52       */
53      String getName();
54  
55      /**
56       * @return the <code>DataSource</code> configured by the factory.
57       * @throws SQLException if the source can't be returned
58       */
59      DataSource getDataSource() throws SQLException;
60  
61      /**
62       * Initialize the factory.
63       *
64       * @param config the factory settings
65       * @throws SQLException Any exceptions caught during processing will be
66       *         rethrown wrapped into a SQLException.
67       */
68      void initialize(JDBCDiskCacheAttributes config)
69          throws SQLException;
70  
71      /**
72       * A hook which is called when the resources of the associated DataSource
73       * can be released.
74       * After close() is called, the other methods may not work any more
75       * (e.g. getDataSource() might return null).
76       * It is not guaranteed that this method does anything. For example,
77       * we do not want to close connections retrieved via JNDI, so the
78       * JndiDataSouurceFactory does not close these connections
79       *
80       * @throws SQLException Any exceptions caught during processing will be
81       *         rethrown wrapped into a SQLException.
82       */
83      void close()
84          throws SQLException;
85  }