Moved to connection validation check, rather than using an own.

Implemented unimplemented connection methods.
This commit is contained in:
Robin Kupper
2011-05-03 10:47:44 +02:00
parent 96400cb1ca
commit 7d0ef7b264

View File

@@ -1,17 +1,3 @@
/**
* <b>Purpose:</b>Wrapper for JDBCConnectionDriver.<br>
* <b>Description:</b>http://java.sun.com/developer/onlineTraining/Programming/JDCBook/
* conpool.html<br>
* <b>Copyright:</b>Licensed under the Apache License, Version 2.0.
* http://www.apache.org/licenses/LICENSE-2.0<br>
* <b>Company:</b> SIMPL<br>
*
* @author schneimi
* @version $Id: JDCConnectionDriver.java 1224 2010-04-28 14:17:34Z
* michael.schneidt@arcor.de $<br>
* @link http://code.google.com/p/simpl09/
*/
package de.diddiz.util;
import java.sql.Array;
@@ -23,7 +9,6 @@ import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
@@ -58,7 +43,7 @@ public class ConnectionPool {
for (int i = 0; i < connections.size(); i++) {
c = connections.elementAt(i);
if (c.lease()) {
if (c.validate())
if (c.isValid())
return c;
else {
c.terminate();
@@ -68,7 +53,7 @@ public class ConnectionPool {
}
c = new JDCConnection(DriverManager.getConnection(url, user, password));
c.lease();
if (!c.validate()) {
if (!c.isValid()) {
c.terminate();
throw new SQLException("Failed to validate a brand new connection");
}
@@ -81,7 +66,7 @@ public class ConnectionPool {
final Enumeration<JDCConnection> connlist = connections.elements();
while (connlist != null && connlist.hasMoreElements()) {
final JDCConnection conn = connlist.nextElement();
if (conn.inUse() && stale > conn.getLastUse() && !conn.validate())
if (conn.inUse() && stale > conn.getLastUse() && !conn.isValid())
removeConnection(conn);
}
}
@@ -127,7 +112,7 @@ public class ConnectionPool {
public void terminate() {
try {
conn.close();
} catch (SQLException ex) {}
} catch (final SQLException ex) {}
}
public synchronized boolean lease() {
@@ -140,27 +125,6 @@ public class ConnectionPool {
}
}
public boolean validate() {
Statement state = null;
ResultSet rs = null;
try {
conn.getMetaData();
state = conn.createStatement();
rs = state.executeQuery("/* ping */");
if (rs.next() && rs.getInt(1) == 1)
return true;
} catch (final SQLException ex) {
} finally {
try {
if (rs != null)
rs.close();
if (state != null)
state.close();
} catch (final SQLException ex) {}
}
return false;
}
public boolean inUse() {
return inuse;
}
@@ -271,7 +235,7 @@ public class ConnectionPool {
@Override
public Blob createBlob() throws SQLException {
return createBlob();
return conn.createBlob();
}
@Override
@@ -321,91 +285,105 @@ public class ConnectionPool {
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
return null;
return conn.getTypeMap();
}
public boolean isValid() {
try {
return conn.isValid(1);
} catch (final SQLException ex) {
return false;
}
}
@Override
public boolean isValid(int timeout) throws SQLException {
return false;
return conn.isValid(timeout);
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
return null;
return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
return null;
return conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
return null;
return conn.prepareStatement(sql, autoGeneratedKeys);
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
return null;
return conn.prepareStatement(sql, columnIndexes);
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
return null;
return conn.prepareStatement(sql, columnNames);
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
return null;
return conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
return null;
return conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
conn.releaseSavepoint(savepoint);
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
conn.rollback(savepoint);
}
@Override
public void setClientInfo(Properties properties) throws SQLClientInfoException {
conn.setClientInfo(properties);
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
conn.setClientInfo(name, value);
}
@Override
public void setHoldability(int holdability) throws SQLException {
conn.setHoldability(holdability);
}
@Override
public Savepoint setSavepoint() throws SQLException {
return null;
return conn.setSavepoint();
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
return null;
return conn.setSavepoint(name);
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
conn.setTypeMap(map);
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
return conn.isWrapperFor(iface);
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
return null;
return conn.unwrap(iface);
}
}
}