01: /**
02: * Library name : Primrose - A Java Database Connection Pool.
03: * Published by Ben Keeping, http://primrose.org.uk .
04: * Copyright (C) 2004 Ben Keeping, primrose.org.uk
05: * Email: Use "Contact Us Form" on website
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */package uk.org.primrose.test;
21:
22: import uk.org.primrose.pool.core.ExternalPoolConfigProvider;
23: import uk.org.primrose.GeneralException;
24: import java.util.Properties;
25:
26: /**
27: * This class is a very simple example of how to provide your own
28: * settings to a pool at runtime - possibly using an external datastore
29: * via LDAP, or from a relational db.
30: *
31: * The example 'datasource' here is just a Properties object - but it does highlight
32: * how you may implement your own.
33: *
34: * If you wish to accept defaults for values, then leave them out of the config
35: * and a default value will be used by the pool. For example, if you do not specify
36: * 'idleTime', then a value of 120000 (2 minutes) will be used.
37: *
38: * See the ExternalPoolConfigProvider class for more info ...
39: *
40: */
41: public class ExamplePoolConfigProvider implements
42: ExternalPoolConfigProvider {
43: Properties poolOneProps = new Properties();
44: Properties poolTwoProps = new Properties();
45:
46: public ExamplePoolConfigProvider() {
47: // Set up our pretend datasources for two pools ...
48: poolOneProps.put("base", "10");
49: poolOneProps.put("log",
50: "C:/java/primrose_3.0/poolone_${yyyy-MM-dd}.log");
51: poolOneProps.put("logLevel", "verbose,info,warn,error,crisis");
52: poolOneProps.put("driverClass",
53: "oracle.jdbc.driver.OracleDriver");
54: poolOneProps.put("driverURL",
55: "jdbc:oracle:thin:@192.168.154.3:1521:EXHCDEV1");
56: poolOneProps.put("user", "hcr");
57: poolOneProps.put("password", "dev");
58: poolOneProps.put("killActiveConnectionsOverAge", "120000");
59: poolOneProps.put("cycleConnections", "1000");
60: poolOneProps.put("connectionAutoCommit", "true");
61: poolOneProps.put("checkSQL", "select 1 from dual");
62: poolOneProps.put("connectionTransactionIsolation",
63: "TRANSACTION_READ_COMMITTED");
64:
65: poolTwoProps.put("base", "5");
66: poolTwoProps.put("log",
67: "C:/java/primrose_3.0/pooltwo_${yyyy-MM-dd}.log");
68: poolTwoProps.put("idleTime", "5000");
69: poolTwoProps.put("logLevel", "info,warn,error,crisis");
70: poolTwoProps.put("driverClass",
71: "oracle.jdbc.driver.OracleDriver");
72: poolTwoProps.put("driverURL",
73: "jdbc:oracle:thin:@192.168.154.3:1521:EXHCDEV1");
74: poolTwoProps.put("user", "oraquery");
75: poolTwoProps.put("password", "dev");
76: poolTwoProps.put("killActiveConnectionsOverAge", "120000");
77: }
78:
79: public String getConfigItem(String poolName, String itemName)
80: throws GeneralException {
81: // Depending on which pool is being loaded, return our appropriate values
82: if (poolName.equals("poolOne")) {
83: return poolOneProps.getProperty(itemName);
84: } else if (poolName.equals("poolTwo")) {
85: return poolTwoProps.getProperty(itemName);
86: } else {
87: throw new GeneralException("Unknown pool name :'"
88: + poolName + "'");
89: }
90: }
91: }
|