View Javadoc

1   package org.apache.torque.dsfactory;
2   
3   /*
4    * Copyright 2001-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import javax.sql.ConnectionPoolDataSource;
20  import javax.sql.DataSource;
21  
22  import org.apache.commons.configuration.Configuration;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  import org.apache.torque.Torque;
28  import org.apache.torque.TorqueException;
29  import org.apache.torque.pool.TorqueClassicDataSource;
30  
31  /***
32   * A factory that uses the "old" Torque Pools for fetching a DataSource.
33   *
34   * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
35   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
36   * @version $Id: TorqueDataSourceFactory.java,v 1.13.2.3 2004/05/20 04:35:14 seade Exp $
37   * @deprecated as of version 3.1, use SharedPoolDataSourceFactory
38   */
39  public class TorqueDataSourceFactory
40      extends AbstractDataSourceFactory
41      implements DataSourceFactory
42  {
43  
44      /*** The log. */
45      private static Log log = LogFactory.getLog(TorqueDataSourceFactory.class);
46  
47      /*** The wrapped <code>DataSource</code>. */
48      private DataSource ds;
49  
50      /***
51       * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
52       */
53      public DataSource getDataSource()
54      {
55          return ds;
56      }
57  
58      /***
59       * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
60       */
61      public void initialize(Configuration configuration) throws TorqueException
62      {
63          if (configuration == null)
64          {
65              throw new TorqueException(
66                  "Torque cannot be initialized without "
67                      + "a valid configuration. Please check the log files "
68                      + "for further details.");
69          }
70          ConnectionPoolDataSource cpds = initCPDS(configuration);
71          TorqueClassicDataSource tcds = initTorqueClassic(configuration);
72          tcds.setConnectionPoolDataSource(cpds);
73          ds = tcds;
74      }
75  
76      /***
77       * Initializes the TorqueClassicDataSource.
78       *
79       * @param configuration where to read the settings from
80       * @throws TorqueException if a property set fails
81       * @return a configured <code>TorqueClassicDataSource</code>
82       */
83      protected TorqueClassicDataSource initTorqueClassic(
84          Configuration configuration)
85          throws TorqueException
86      {
87          log.debug("Starting initTorqueClassic");
88          TorqueClassicDataSource ds = new TorqueClassicDataSource();
89  
90          Configuration c = null;
91  
92          c = Torque.getConfiguration().subset(DEFAULT_POOL_KEY);
93          applyConfiguration(c, ds);
94  
95          c = configuration.subset(POOL_KEY);
96          applyConfiguration(c, ds);
97          return ds;
98      }
99  }