jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu...@apache.org
Subject cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql TransactionTagSupport.java
Date Tue, 23 Apr 2002 02:07:15 GMT
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 <code>Connection</code> to its initial state and closes

  -     * it.
  +     * Restores the <code>Connection</code> 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:   <mailto:taglibs-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-dev-help@jakarta.apache.org>


Mime
View raw message