01: /*
02: * Distributed as part of c3p0 v.0.9.1.2
03: *
04: * Copyright (C) 2005 Machinery For Change, Inc.
05: *
06: * Author: Steve Waldman <swaldman@mchange.com>
07: *
08: * This library is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU Lesser General Public License version 2.1, as
10: * published by the Free Software Foundation.
11: *
12: * This software 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
15: * GNU Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public License
18: * along with this software; see the file LICENSE. If not, write to the
19: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: */
22:
23: package com.mchange.v2.c3p0.test;
24:
25: import javax.naming.*;
26: import javax.sql.*;
27: import com.mchange.v2.c3p0.*;
28:
29: public final class JndiBindTest {
30: public static void main(String[] argv) {
31: try {
32: String driverClass = null;
33: String jdbc_url = null;
34: String username = null;
35: String password = null;
36: String dmds_name = null;
37: String cpds_name = null;
38: String pbds_name = null;
39:
40: if (argv.length == 7) {
41: driverClass = argv[0];
42: jdbc_url = argv[1];
43: username = argv[2];
44: password = argv[3];
45: dmds_name = argv[4];
46: cpds_name = argv[5];
47: pbds_name = argv[6];
48: } else if (argv.length == 5) {
49: driverClass = argv[0];
50: jdbc_url = argv[1];
51: username = null;
52: password = null;
53: dmds_name = argv[2];
54: cpds_name = argv[3];
55: pbds_name = argv[4];
56: } else
57: usage();
58:
59: if (!jdbc_url.startsWith("jdbc:"))
60: usage();
61:
62: DataSource dmds = DriverManagerDataSourceFactory.create(
63: driverClass, jdbc_url, username, password);
64: WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource();
65: cpds.setNestedDataSource(dmds);
66: DataSource pbds = PoolBackedDataSourceFactory.create(
67: driverClass, jdbc_url, username, password);
68:
69: InitialContext ctx = new InitialContext();
70: ctx.rebind(dmds_name, dmds);
71: System.out.println("DriverManagerDataSource bounds as "
72: + dmds_name);
73: ctx.rebind(cpds_name, cpds);
74: System.out.println("ConnectionPoolDataSource bounds as "
75: + cpds_name);
76: ctx.rebind(pbds_name, pbds);
77: System.out.println("PoolDataSource bounds as " + pbds_name);
78: } catch (Exception e) {
79: e.printStackTrace();
80: }
81: }
82:
83: private static void usage() {
84: System.err.println("java " + JndiBindTest.class.getName()
85: + " \\");
86: System.err.println("\t<jdbc_driver_class> \\");
87: System.err.println("\t<jdbc_url> [<username> <password>] \\");
88: System.err.println("\t<dmds_name> <cpds_name> <pbds_name>");
89: System.exit(-1);
90: }
91: }
|