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