cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Seiderer <Peter.Seide...@ciselant.de>
Subject Cache database connections for sql processor
Date Tue, 06 Jun 2000 21:23:07 GMT
Hello,

the following patch adds the caching of database connections
to the sql processor. This speeds up the sql processor and
has the advantage that subsequent queries are executed in the
same session, e.g. making the use of the oracle sequence.nextval and
sequence.currval in subsequent queries in one xml document possible.

Peter


diff -ur cocoon-1.7.4/src/org/apache/cocoon/processor/sql/SQLProcessor.java cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java
--- cocoon-1.7.4/src/org/apache/cocoon/processor/sql/SQLProcessor.java	Mon Jan 12 03:18:12
1970
+++ cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java	Tue Jun  6 14:29:15 2000
@@ -98,6 +98,8 @@
      */
     public Document process(Document document, Dictionary parameters) throws Exception {
         HttpServletRequest request = (HttpServletRequest)parameters.get("request");
+        Hashtable connections = new Hashtable();
+        Connection conn = null;
         try {
             ConnectionDefs cdefs = new ConnectionDefs(document);
             NodeList query_nodes = document.getElementsByTagName("query");
@@ -136,13 +138,28 @@
                         }
                     }
                 }
-                Connection conn = cdefs.getConnection(query_props.getProperty("connection"));
+
+                String conn_name = query_props.getProperty("connection");
+                if (connections.containsKey(conn_name)) {
+                    conn = (Connection) connections.get(conn_name);
+                } else {     
+                    conn = (Connection) cdefs.getConnection(conn_name);
+                    connections.put(conn_name, conn);
+                }
+                
                 processQuery(document,parameters,query_element,query_props,conn);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
 
+        Enumeration conn_list = connections.elements();
+        while(conn_list.hasMoreElements()) {
+            Connection c = (Connection) conn_list.nextElement();
+            c.close();
+        }
+        connections.clear();
+
         return document;
     }
 
@@ -302,9 +319,7 @@
 			if (!auto_commit) {
             	conn.rollback();
 			}
-        } finally {
-          conn.close();
-        }
+        } 
     }
 
     /**
 
-- 
------------------------------------------------------------------------
Peter Seiderer                     E-Mail:  Peter.Seiderer@ciselant.de
(Diplom-Informatiker Univ.)                   (PGP-key available)
                                   WWW   :  http://www.ciselant.de
------------------------------------------------------------------------

Mime
View raw message