Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 50693 invoked by uid 500); 19 Jul 2001 19:10:23 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 50684 invoked by uid 500); 19 Jul 2001 19:10:23 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 19 Jul 2001 19:08:55 -0000 Message-ID: <20010719190855.8772.qmail@icarus.apache.org> From: bloritsch@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/org/apache/cocoon/acting DatabaseAuthenticatorAction.java X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N bloritsch 01/07/19 12:08:55 Modified: src/org/apache/cocoon/acting DatabaseAuthenticatorAction.java Log: Fix incorrect connection handling by DBauthenticatorAction Revision Changes Path 1.5 +58 -40 xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java Index: DatabaseAuthenticatorAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DatabaseAuthenticatorAction.java 2001/07/11 08:47:50 1.4 +++ DatabaseAuthenticatorAction.java 2001/07/19 19:08:55 1.5 @@ -1,4 +1,4 @@ -// $Id: DatabaseAuthenticatorAction.java,v 1.4 2001/07/11 08:47:50 haul Exp $ +// $Id: DatabaseAuthenticatorAction.java,v 1.5 2001/07/19 19:08:55 bloritsch Exp $ package org.apache.cocoon.acting; import java.sql.Connection; @@ -51,7 +51,7 @@ * not verified. * * @author Martin Man <Martin.Man@seznam.cz> - * @version CVS $Revision: 1.4 $ $Date: 2001/07/11 08:47:50 $ + * @version CVS $Revision: 1.5 $ $Date: 2001/07/19 19:08:55 $ */ public class DatabaseAuthenticatorAction extends AbstractDatabaseAction { @@ -62,19 +62,24 @@ Parameters parameters) throws Exception { DataSourceComponent datasource = null; Connection conn = null; + Statement st = null; + ResultSet rs = null; - // read global parameter settings - boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT; - if (this.settings.containsKey("reloadable")) - reloadable = Boolean.getBoolean((String) this.settings.get("reloadable")); - // read local settings + // read global parameter settings + boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT; + + if (this.settings.containsKey("reloadable")) { + reloadable = Boolean.getBoolean((String) this.settings.get("reloadable")); + } + + // read local settings try { Configuration conf = this.getConfiguration ( - parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")), - parameters.getParameterAsBoolean("reloadable",reloadable)); + parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")), + parameters.getParameterAsBoolean("reloadable",reloadable)); boolean cs = true; - String create_session = parameters.getParameter ("create-session", - (String) this.settings.get("create-session")); + String create_session = parameters.getParameter ("create-session", + (String) this.settings.get("create-session")); if (create_session != null && ("no".equals (create_session.trim ()) || "false".equals (create_session.trim ()))) { cs = false; @@ -90,44 +95,57 @@ return null; } - String query = this.getAuthQuery (conf, req); if (query == null) { getLogger ().debug ("DBAUTH: have not got query"); return null; } - try { - getLogger ().debug ("DBAUTH: quuery is: " + query); - Statement st = conn.createStatement (); - ResultSet rs = st.executeQuery (query); - if (rs.next ()) { - getLogger ().debug ("DBAUTH: authorized successfully"); - Session session = null; - if (cs) { - session = req.getSession (false); - if (session != null) - session.invalidate (); - session = req.getSession (true); - if (session == null) - return null; - getLogger ().debug ("DBAUTH: session created"); - } else { - getLogger ().debug ("DBAUTH: leaving session untouched"); - } - HashMap actionMap = this.propagateParameters (conf, rs, - session); - rs.close (); - st.close (); - return Collections.unmodifiableMap (actionMap); + getLogger ().debug ("DBAUTH: quuery is: " + query); + Statement st = conn.createStatement (); + ResultSet rs = st.executeQuery (query); + + if (rs.next ()) { + getLogger ().debug ("DBAUTH: authorized successfully"); + Session session = null; + + if (cs) { + session = req.getSession (false); + if (session != null) + session.invalidate (); + session = req.getSession (true); + if (session == null) + return null; + getLogger ().debug ("DBAUTH: session created"); + } else { + getLogger ().debug ("DBAUTH: leaving session untouched"); } - getLogger ().debug ("DBAUTH: no results for query"); - } catch (Exception e) { - getLogger ().debug ("exception: ", e); - return null; + + HashMap actionMap = this.propagateParameters (conf, rs, + session); + + conn.commit(); + return Collections.unmodifiableMap (actionMap); } + + conn.rollback(); + getLogger ().debug ("DBAUTH: no results for query"); } catch (Exception e) { + if (conn != null) { + try { + conn.rollback(); + } catch (Exception e) {/* ignore */} + } getLogger().debug ("exception: ", e); + return null; + } finally { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (conn != null) { + try { + conn.close(); + } catch (Exception e) {/* ignore */} + } } return null; } @@ -231,5 +249,5 @@ } } -// $Id: DatabaseAuthenticatorAction.java,v 1.4 2001/07/11 08:47:50 haul Exp $ +// $Id: DatabaseAuthenticatorAction.java,v 1.5 2001/07/19 19:08:55 bloritsch Exp $ // vim: set et ts=4 sw=4: ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org