001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool;
007:
008: import org.logicalcobwebs.dbscript.ConnectionAdapterIF;
009: import org.apache.commons.logging.Log;
010: import org.apache.commons.logging.LogFactory;
011:
012: import java.sql.Connection;
013: import java.sql.DriverManager;
014: import java.sql.SQLException;
015: import java.util.Properties;
016:
017: /**
018: * This is the simplest pool you can get. It isn\ufffdt thread safe. It isn't robust.
019: * But it is fast. We use it as our bench mark on how could we should strive
020: * to be.
021: *
022: * Provides Simpool connections to the {@link org.logicalcobwebs.dbscript.ScriptFacade ScriptFacade}
023: *
024: * @version $Revision: 1.12 $, $Date: 2006/01/18 14:40:06 $
025: * @author Bill Horsman (bill@logicalcobwebs.co.uk)
026: * @author $Author: billhorsman $ (current maintainer)
027: * @since Proxool 0.5
028: */
029: public class SimpoolAdapter implements ConnectionAdapterIF {
030:
031: private static final Log LOG = LogFactory
032: .getLog(SimpoolAdapter.class);
033:
034: private Connection[] connections;
035:
036: private int index = 0;
037:
038: public String getName() {
039: return "simpool";
040: }
041:
042: public void setup(String driver, String url, Properties info)
043: throws SQLException {
044:
045: try {
046: Class.forName(driver);
047: } catch (ClassNotFoundException e) {
048: throw new SQLException("Couldn't find " + driver);
049: }
050:
051: int connectionCount = Integer
052: .parseInt(info
053: .getProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY));
054: connections = new Connection[connectionCount];
055: for (int i = 0; i < connectionCount; i++) {
056: connections[i] = DriverManager.getConnection(url, info);
057: }
058: }
059:
060: public Connection getConnection() throws SQLException {
061: Connection c = connections[index];
062: index++;
063: if (index >= connections.length) {
064: index = 0;
065: }
066: return c;
067: }
068:
069: public void closeConnection(Connection connection) {
070: // Do nothing !
071: }
072:
073: public void tearDown() {
074: try {
075: for (int i = 0; i < connections.length; i++) {
076: connections[i].close();
077: }
078: } catch (SQLException e) {
079: LOG.error("Problem tearing down " + getName() + " adapter",
080: e);
081: }
082: }
083:
084: }
085:
086: /*
087: Revision history:
088: $Log: SimpoolAdapter.java,v $
089: Revision 1.12 2006/01/18 14:40:06 billhorsman
090: Unbundled Jakarta's Commons Logging.
091:
092: Revision 1.11 2003/03/04 10:24:40 billhorsman
093: removed try blocks around each test
094:
095: Revision 1.10 2003/03/03 11:12:05 billhorsman
096: fixed licence
097:
098: Revision 1.9 2003/03/01 15:27:24 billhorsman
099: checkstyle
100:
101: Revision 1.8 2003/02/19 15:14:25 billhorsman
102: fixed copyright (copy and paste error,
103: not copyright change)
104:
105: Revision 1.7 2003/02/06 17:41:03 billhorsman
106: now uses imported logging
107:
108: Revision 1.6 2003/01/27 23:32:10 billhorsman
109: encoding fix (no idea how that happened)
110:
111: Revision 1.5 2002/11/13 20:23:38 billhorsman
112: change method name, throw exceptions differently, trivial changes
113:
114: Revision 1.4 2002/11/09 16:02:20 billhorsman
115: fix doc
116:
117: Revision 1.3 2002/11/02 14:22:16 billhorsman
118: Documentation
119:
120: Revision 1.2 2002/11/02 12:46:42 billhorsman
121: improved debug
122:
123: Revision 1.1 2002/11/02 11:37:48 billhorsman
124: New tests
125:
126: Revision 1.1 2002/10/30 21:17:50 billhorsman
127: new performance tests
128:
129: */
|