johng 2004/10/19 14:56:55
Modified: java/src/org/apache/xalan/lib/sql XConnection.java
DefaultConnectionPool.java SQLDocument.java
Log:
This patch makes the close() function behave better but still has a
problem when certain iterators are used. This code is at least safe
in all instaces.
It also fixes a minor bug in the default connection pool
PR:
Obtained from: John Gentilin
Submitted by: John Gentilin
Reviewed by:
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.31 +42 -15
xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java
Index: XConnection.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/XConnection.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- XConnection.java 16 Sep 2004 04:22:24 -0000 1.30
+++ XConnection.java 19 Oct 2004 21:56:54 -0000 1.31
@@ -34,11 +34,10 @@
import org.apache.xml.dtm.DTMManager;
import org.apache.xml.dtm.ref.DTMManagerDefault;
import org.apache.xml.dtm.ref.DTMNodeIterator;
+import org.apache.xml.dtm.ref.DTMNodeProxy;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.axes.OneStepIterator;
import org.apache.xpath.objects.XBooleanStatic;
import org.apache.xpath.objects.XNodeSet;
-import org.apache.xpath.objects.XNumber;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -673,7 +672,7 @@
setError(e, doc, doc.checkWarnings());
}
- doc.close();
+ doc.close(m_IsDefaultPool);
doc = null;
}
}
@@ -763,7 +762,9 @@
setError(e, doc, doc.checkWarnings());
}
- doc.close();
+ // If we are using the Default Connection Pool, then
+ // force the connection pool to flush unused connections.
+ doc.close(m_IsDefaultPool);
doc = null;
}
}
@@ -791,7 +792,7 @@
SQLDocument sqldoc = null;
DTMNodeIterator nodei = null;
- sqldoc = locateSQLDocument(o);
+ sqldoc = locateSQLDocument( exprContext, o);
if (sqldoc != null) sqldoc.skip(value);
}
@@ -1073,7 +1074,9 @@
SQLDocument d = (SQLDocument) m_OpenSQLDocuments.elementAt(0);
try
{
- d.close();
+ // If we are using the Default Connection Pool, then
+ // force the connection pool to flush unused connections.
+ d.close(m_IsDefaultPool);
}
catch (Exception se ) {}
@@ -1098,13 +1101,19 @@
* @throws SQLException
*/
- public void close(Object doc) throws SQLException
+ public void close(ExpressionContext exprContext, Object doc) throws
SQLException
{
if (DEBUG)
System.out.println("Entering XConnection.close(" + doc + ")");
- SQLDocument sqlDoc = locateSQLDocument(doc);
- if (sqlDoc != null) sqlDoc.close();
+ SQLDocument sqlDoc = locateSQLDocument(exprContext, doc);
+ if (sqlDoc != null)
+ {
+ // If we are using the Default Connection Pool, then
+ // force the connection pool to flush unused connections.
+ sqlDoc.close(m_IsDefaultPool);
+ m_OpenSQLDocuments.remove(sqlDoc);
+ }
}
@@ -1118,22 +1127,39 @@
* @param doc
* @return
*/
- private SQLDocument locateSQLDocument(Object doc)
+ private SQLDocument locateSQLDocument(ExpressionContext exprContext,
Object doc)
{
try
{
- DTMNodeIterator dtmIter = (DTMNodeIterator)doc;
+ if (doc instanceof DTMNodeIterator)
+ {
+ DTMNodeIterator dtmIter = (DTMNodeIterator)doc;
+ try
+ {
+ DTMNodeProxy root = (DTMNodeProxy)dtmIter.getRoot();
+ return (SQLDocument) root.getDTM();
+ }
+ catch (Exception e)
+ {
+ XNodeSet xNS = (XNodeSet)dtmIter.getDTMIterator();
+ DTMIterator iter = (DTMIterator)xNS.getContainedIter();
+ DTM dtm = iter.getDTM(xNS.nextNode());
+ return (SQLDocument)dtm;
+ }
+ }
+/*
XNodeSet xNS = (XNodeSet)dtmIter.getDTMIterator();
-
OneStepIterator iter = (OneStepIterator)xNS.getContainedIter();
-
DTMManager aDTMManager = (DTMManager)iter.getDTMManager();
-
return (SQLDocument)aDTMManager.getDTM(xNS.nextNode());
+*/
+ setError(new Exception("SQL Extension:close - Can Not Identify
SQLDocument"), exprContext);
+ return null;
}
catch(Exception e)
{
+ setError(e, exprContext);
return null;
}
}
@@ -1197,6 +1223,7 @@
ErrorListener listen = expr.getErrorListener();
if ( listen != null && excp != null )
{
+
listen.warning(
new TransformerException(excp.toString(),
expr.getXPathContext().getSAXLocator(), excp));
1.21 +8 -7
xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java
Index: DefaultConnectionPool.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DefaultConnectionPool.java 23 Feb 2004 10:29:35 -0000 1.20
+++ DefaultConnectionPool.java 19 Oct 2004 21:56:54 -0000 1.21
@@ -24,6 +24,7 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Properties;
import java.util.Vector;
@@ -123,22 +124,22 @@
{
// Iterate over the entire pool closing the
// JDBC Connections.
- for ( int x = 0; x < m_pool.size(); x++ )
+ Iterator i = m_pool.iterator();
+ while(i.hasNext())
{
-
-
PooledConnection pcon =
- (PooledConnection) m_pool.elementAt(x);
+ (PooledConnection) i.next();
// If the PooledConnection is not in use, close it
if ( pcon.inUse() == false )
{
if (DEBUG)
{
- System.err.println("Closing JDBC Connection " + x);
+ System.err.println("Closing JDBC Connection ");
}
-
+
pcon.close();
+ m_pool.remove(pcon);
}
}
1.27 +3 -2
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java
Index: SQLDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- SQLDocument.java 16 Sep 2004 04:17:06 -0000 1.26
+++ SQLDocument.java 19 Oct 2004 21:56:55 -0000 1.27
@@ -965,7 +965,7 @@
* be in a errored state.
*
*/
- public void close( )
+ public void close(boolean flushConnPool )
{
try
{
@@ -1004,6 +1004,7 @@
{
if (m_HasErrors) m_ConnectionPool.releaseConnectionOnError(conn);
else m_ConnectionPool.releaseConnection(conn);
+// if (flushConnPool) m_ConnectionPool.freeUnused();
}
}
catch(Exception e) {}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]