KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > SimpoolAdapter


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool;
7
8 import org.logicalcobwebs.dbscript.ConnectionAdapterIF;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import java.sql.Connection JavaDoc;
13 import java.sql.DriverManager JavaDoc;
14 import java.sql.SQLException JavaDoc;
15 import java.util.Properties JavaDoc;
16
17 /**
18  * This is the simplest pool you can get. It isn?t thread safe. It isn't robust.
19  * But it is fast. We use it as our bench mark on how could we should strive
20  * to be.
21  *
22  * Provides Simpool connections to the {@link org.logicalcobwebs.dbscript.ScriptFacade ScriptFacade}
23  *
24  * @version $Revision: 1.12 $, $Date: 2006/01/18 14:40:06 $
25  * @author Bill Horsman (bill@logicalcobwebs.co.uk)
26  * @author $Author: billhorsman $ (current maintainer)
27  * @since Proxool 0.5
28  */

29 public class SimpoolAdapter implements ConnectionAdapterIF {
30
31     private static final Log LOG = LogFactory.getLog(SimpoolAdapter.class);
32
33     private Connection JavaDoc[] connections;
34
35     private int index = 0;
36
37     public String JavaDoc getName() {
38         return "simpool";
39     }
40
41     public void setup(String JavaDoc driver, String JavaDoc url, Properties JavaDoc info) throws SQLException JavaDoc {
42
43         try {
44             Class.forName(driver);
45         } catch (ClassNotFoundException JavaDoc e) {
46             throw new SQLException JavaDoc("Couldn't find " + driver);
47         }
48
49         int connectionCount = Integer.parseInt(info.getProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY));
50         connections = new Connection JavaDoc[connectionCount];
51         for (int i = 0; i < connectionCount; i++) {
52             connections[i] = DriverManager.getConnection(url, info);
53         }
54     }
55
56     public Connection JavaDoc getConnection()
57             throws SQLException JavaDoc {
58         Connection JavaDoc c = connections[index];
59         index++;
60         if (index >= connections.length) {
61             index = 0;
62         }
63         return c;
64     }
65
66     public void closeConnection(Connection JavaDoc connection) {
67         // Do nothing !
68
}
69
70     public void tearDown() {
71         try {
72             for (int i = 0; i < connections.length; i++) {
73                 connections[i].close();
74             }
75         } catch (SQLException JavaDoc e) {
76             LOG.error("Problem tearing down " + getName() + " adapter", e);
77         }
78     }
79
80 }
81
82 /*
83  Revision history:
84  $Log: SimpoolAdapter.java,v $
85  Revision 1.12 2006/01/18 14:40:06 billhorsman
86  Unbundled Jakarta's Commons Logging.
87
88  Revision 1.11 2003/03/04 10:24:40 billhorsman
89  removed try blocks around each test
90
91  Revision 1.10 2003/03/03 11:12:05 billhorsman
92  fixed licence
93
94  Revision 1.9 2003/03/01 15:27:24 billhorsman
95  checkstyle
96
97  Revision 1.8 2003/02/19 15:14:25 billhorsman
98  fixed copyright (copy and paste error,
99  not copyright change)
100
101  Revision 1.7 2003/02/06 17:41:03 billhorsman
102  now uses imported logging
103
104  Revision 1.6 2003/01/27 23:32:10 billhorsman
105  encoding fix (no idea how that happened)
106
107  Revision 1.5 2002/11/13 20:23:38 billhorsman
108  change method name, throw exceptions differently, trivial changes
109
110  Revision 1.4 2002/11/09 16:02:20 billhorsman
111  fix doc
112
113  Revision 1.3 2002/11/02 14:22:16 billhorsman
114  Documentation
115
116  Revision 1.2 2002/11/02 12:46:42 billhorsman
117  improved debug
118
119  Revision 1.1 2002/11/02 11:37:48 billhorsman
120  New tests
121
122  Revision 1.1 2002/10/30 21:17:50 billhorsman
123  new performance tests
124
125 */

126
Popular Tags