Return-Path: Delivered-To: apmail-jakarta-taglibs-dev-archive@apache.org Received: (qmail 21220 invoked from network); 23 Apr 2002 02:07:33 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 23 Apr 2002 02:07:33 -0000 Received: (qmail 15082 invoked by uid 97); 23 Apr 2002 02:07:19 -0000 Delivered-To: qmlist-jakarta-archive-taglibs-dev@jakarta.apache.org Received: (qmail 14936 invoked by uid 97); 23 Apr 2002 02:07:16 -0000 Mailing-List: contact taglibs-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tag Libraries Developers List" Reply-To: "Tag Libraries Developers List" Delivered-To: mailing list taglibs-dev@jakarta.apache.org Received: (qmail 14920 invoked by uid 97); 23 Apr 2002 02:07:16 -0000 Date: 23 Apr 2002 02:07:15 -0000 Message-ID: <20020423020715.10795.qmail@icarus.apache.org> From: luehe@apache.org To: jakarta-taglibs-cvs@apache.org Subject: cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql TransactionTagSupport.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N luehe 02/04/22 19:07:15 Modified: standard/src/org/apache/taglibs/standard/tag/common/sql TransactionTagSupport.java Log: Fixed 8346: TransactionTagSupport has several issues Revision Changes Path 1.9 +84 -55 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java Index: TransactionTagSupport.java =================================================================== RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TransactionTagSupport.java 16 Apr 2002 00:01:34 -0000 1.8 +++ TransactionTagSupport.java 23 Apr 2002 02:07:15 -0000 1.9 @@ -78,60 +78,50 @@ public abstract class TransactionTagSupport extends TagSupport implements TryCatchFinally { - private static final int DEFAULT_ISOLATION = -1; + //********************************************************************* + // Private constants - private int isolation = DEFAULT_ISOLATION; + private static final String TRANSACTION_READ_COMMITTED + = "read_committed"; + private static final String TRANSACTION_READ_UNCOMMITTED + = "read_uncommitted"; + private static final String TRANSACTION_REPEATABLE_READ + = "repeatable_read"; + private static final String TRANSACTION_SERIALIZABLE + = "serializable"; + + + //********************************************************************* + // Protected state - /* - * The following properties take expression values, so the - * setter methods are implemented by the expression type - * specific subclasses. - */ protected Object rawDataSource; protected DataSource dataSource; - /* - * Instance variables that are not for attributes - */ + + //********************************************************************* + // Private state + private Connection conn; - private int origIsolation; private DataSourceUtil dsUtil; + private int isolation; + private int origIsolation; - //********************************************************************* - // Public utility methods - /** - * Setter method for the transaction isolation level. - */ - public void setIsolation(String isolation) - throws JspTagException { + //********************************************************************* + // Constructor and initialization - if ("TRANSACTION_READ_COMMITTED".equals(isolation)) { - this.isolation = Connection.TRANSACTION_READ_COMMITTED; - } - if ("TRANSACTION_READ_UNCOMMITTED".equals(isolation)) { - this.isolation = Connection.TRANSACTION_READ_UNCOMMITTED; - } - if ("TRANSACTION_REPEATABLE_READ".equals(isolation)) { - this.isolation = Connection.TRANSACTION_REPEATABLE_READ; - } - if ("TRANSACTION_SERIALIZABLE".equals(isolation)) { - this.isolation = Connection.TRANSACTION_SERIALIZABLE; - } - else { - throw new JspTagException( - Resources.getMessage("TRANSACTION_INVALID_ISOLATION")); - } + public TransactionTagSupport() { + super(); + init(); } - /** - * Called by nested parameter elements to get a reference to - * the Connection. - */ - public Connection getSharedConnection() { - return conn; + private void init() { + conn = null; + dsUtil = null; + isolation = Connection.TRANSACTION_NONE; } + //********************************************************************* // Tag logic @@ -149,20 +139,20 @@ try { conn = getConnection(); - int origIsolation = conn.getTransactionIsolation(); + origIsolation = conn.getTransactionIsolation(); if (origIsolation == Connection.TRANSACTION_NONE) { throw new JspTagException( Resources.getMessage("TRANSACTION_NO_SUPPORT")); } - if (isolation != DEFAULT_ISOLATION && - origIsolation != isolation) { + if ((isolation != Connection.TRANSACTION_NONE) + && (isolation != origIsolation)) { conn.setTransactionIsolation(isolation); } conn.setAutoCommit(false); - } - catch (SQLException e) { + } catch (SQLException e) { throw new JspTagException( - Resources.getMessage("ERROR_GET_CONNECTION", e.getMessage())); + Resources.getMessage("ERROR_GET_CONNECTION", + e.getMessage())); } return EVAL_BODY_INCLUDE; @@ -174,10 +164,10 @@ public int doEndTag() throws JspException { try { conn.commit(); - } - catch (SQLException e) { + } catch (SQLException e) { throw new JspTagException( - Resources.getMessage("TRANSACTION_COMMIT_ERROR", e.getMessage())); + Resources.getMessage("TRANSACTION_COMMIT_ERROR", + e.getMessage())); } return EVAL_PAGE; } @@ -189,30 +179,69 @@ if (conn != null) { try { conn.rollback(); + } catch (SQLException e) { + // Ignore to not hide orignal exception } - catch (SQLException e) {} // Ignore to not hide orignal exception } throw t; } /** - * Restores the Connection to its initial state and closes - * it. + * Restores the Connection to its initial state and + * closes it. */ public void doFinally() { if (conn != null) { try { - if (isolation != DEFAULT_ISOLATION && - origIsolation != isolation) { + if ((isolation != Connection.TRANSACTION_NONE) + && (isolation != origIsolation)) { conn.setTransactionIsolation(origIsolation); } conn.setAutoCommit(true); conn.close(); + } catch (SQLException e) { + // Not much we can do } - catch (SQLException e) {} // Not much we can do } conn = null; } + + // Releases any resources we may have (or inherit) + public void release() { + init(); + } + + + //********************************************************************* + // Public utility methods + + /** + * Setter method for the transaction isolation level. + */ + public void setIsolation(String iso) throws JspTagException { + + if (TRANSACTION_READ_COMMITTED.equals(iso)) { + isolation = Connection.TRANSACTION_READ_COMMITTED; + } else if (TRANSACTION_READ_UNCOMMITTED.equals(iso)) { + isolation = Connection.TRANSACTION_READ_UNCOMMITTED; + } else if (TRANSACTION_REPEATABLE_READ.equals(iso)) { + isolation = Connection.TRANSACTION_REPEATABLE_READ; + } else if (TRANSACTION_SERIALIZABLE.equals(iso)) { + isolation = Connection.TRANSACTION_SERIALIZABLE; + } else { + throw new JspTagException( + Resources.getMessage("TRANSACTION_INVALID_ISOLATION")); + } + } + + /** + * Called by nested parameter elements to get a reference to + * the Connection. + */ + public Connection getSharedConnection() { + return conn; + } + //********************************************************************* // Private utility methods -- To unsubscribe, e-mail: For additional commands, e-mail: