You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by mk...@apache.org on 2005/03/16 19:04:53 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionFactoryPooledImpl.java
mkalen 2005/03/16 10:04:53
Modified: src/java/org/apache/ojb/broker/accesslayer Tag:
OJB_1_0_RELEASE ConnectionFactoryPooledImpl.java
Log:
Use a PreparedStatement for the validation query to increase JDBC-driver cachability (driver dependent).
Revision Changes Path
No revision
No revision
1.15.2.3 +13 -11 db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
Index: ConnectionFactoryPooledImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
retrieving revision 1.15.2.2
retrieving revision 1.15.2.3
diff -u -r1.15.2.2 -r1.15.2.3
--- ConnectionFactoryPooledImpl.java 11 Mar 2005 11:27:47 -0000 1.15.2.2
+++ ConnectionFactoryPooledImpl.java 16 Mar 2005 18:04:52 -0000 1.15.2.3
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.accesslayer;
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -142,7 +142,7 @@
/**
* Inner class - {@link org.apache.commons.pool.PoolableObjectFactory}
- * used as factory for connection pooling
+ * used as factory for connection pooling.
*/
class ConPoolFactory extends BasePoolableObjectFactory
{
@@ -170,19 +170,21 @@
if (log.isDebugEnabled()) log.debug(e);
isValid = false;
}
- if(isValid && jcd.getConnectionPoolDescriptor().getValidationQuery() != null)
+ final String validationQuery;
+ validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery();
+ if (isValid && validationQuery != null)
{
- isValid = validateConnection(con , jcd.getConnectionPoolDescriptor().getValidationQuery());
+ isValid = validateConnection(con, validationQuery);
}
return isValid;
}
private boolean validateConnection(Connection conn, String query)
{
- Statement stmt = null;
+ PreparedStatement stmt = null;
ResultSet rset = null;
boolean isValid = false;
- if(failedValidationQuery > 100)
+ if (failedValidationQuery > 100)
{
--failedValidationQuery;
throw new OJBRuntimeException("Validation of connection "+conn+" using validation query '"+
@@ -190,9 +192,8 @@
}
try
{
- // TODO: mkalen: use prepared statement!
- stmt = conn.createStatement();
- rset = stmt.executeQuery(query);
+ stmt = conn.prepareStatement(query);
+ rset = stmt.executeQuery();
if (rset.next())
{
failedValidationQuery = 0;
@@ -255,4 +256,5 @@
}
}
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org