1 package org.apache.torque.dsfactory;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }