Fixed connection pool not working at all

This commit is contained in:
Robin Kupper
2011-04-20 00:42:21 +02:00
parent fc65c72bf7
commit 0e28e66c07

View File

@@ -77,14 +77,12 @@ public class ConnectionPool implements Driver {
private class JDCConnection implements Connection private class JDCConnection implements Connection
{ {
private ConnectionService pool;
private Connection conn; private Connection conn;
private boolean inuse; private boolean inuse;
private long timestamp; private long timestamp;
public JDCConnection(Connection conn, ConnectionService pool) { public JDCConnection(Connection conn) {
this.conn = conn; this.conn = conn;
this.pool = pool;
this.inuse = false; this.inuse = false;
this.timestamp = 0; this.timestamp = 0;
} }
@@ -116,18 +114,14 @@ public class ConnectionPool implements Driver {
return timestamp; return timestamp;
} }
public void close() throws SQLException { public void close() {
pool.returnConnection(this); expireLease();
} }
protected void expireLease() { protected void expireLease() {
inuse = false; inuse = false;
} }
protected Connection getConnection() {
return conn;
}
public PreparedStatement prepareStatement(String sql) throws SQLException { public PreparedStatement prepareStatement(String sql) throws SQLException {
return conn.prepareStatement(sql); return conn.prepareStatement(sql);
} }
@@ -393,15 +387,15 @@ public class ConnectionPool implements Driver {
c = connections.elementAt(i); c = connections.elementAt(i);
if (c.lease()) { if (c.lease()) {
if (c.validate()) if (c.validate())
return c.getConnection(); return c;
else else
removeConnection(c); removeConnection(c);
} }
} }
c = new JDCConnection(DriverManager.getConnection(url, user, password), this); c = new JDCConnection(DriverManager.getConnection(url, user, password));
c.lease(); c.lease();
connections.addElement(c); connections.addElement(c);
return c.getConnection(); return c;
} }
public synchronized void returnConnection(JDCConnection conn) { public synchronized void returnConnection(JDCConnection conn) {
@@ -423,8 +417,7 @@ public class ConnectionPool implements Driver {
while (true) { while (true) {
try { try {
Thread.sleep(delay); Thread.sleep(delay);
} catch (InterruptedException e) { } catch (InterruptedException e) {}
}
pool.reapConnections(); pool.reapConnections();
} }
} }