morgand     01/08/09 09:07:20

  Modified:    dbtags/src/org/apache/taglibs/dbtags/preparedstatement
                        PreparedStatementImplTag.java
               dbtags/src/org/apache/taglibs/dbtags/statement
                        StatementImplTag.java
  Log:
  Ciot's patch that allows subclasses to redefine how to create the statement or 
prepared
  statement.  Works for me.
  
  Revision  Changes    Path
  1.7       +18 -9     
jakarta-taglibs/dbtags/src/org/apache/taglibs/dbtags/preparedstatement/PreparedStatementImplTag.java
  
  Index: PreparedStatementImplTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-taglibs/dbtags/src/org/apache/taglibs/dbtags/preparedstatement/PreparedStatementImplTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PreparedStatementImplTag.java     2001/07/02 18:19:18     1.6
  +++ PreparedStatementImplTag.java     2001/08/09 16:07:20     1.7
  @@ -75,14 +75,14 @@
    * Technically, the object is not added to the page context until after
    * the query tag is executed, because PreparedStatement objects cannot
    * be instantiated without a query.</p>
  - * 
  + *
    * <p>JSP Tag Lib Descriptor
    * <pre>
    * &lt;name>preparedStatement&lt;/name>
    * 
&lt;tagclass>org.apache.taglibs.dbtags.preparedstatement.PreparedStatementImplTag&lt;/tagclass>
    * 
&lt;teiclass>org.apache.taglibs.dbtags.connection.PreparedStatementTEI&lt;/teiclass>
    * &lt;bodycontent>JSP&lt;/bodycontent>
  - * &lt;info>JSP tag preparedstatement, used the enclosed query, 
  + * &lt;info>JSP tag preparedstatement, used the enclosed query,
    * resultset/execute and set* tags to perform a database operation.&lt;/info>
    *   &lt;attribute>
    *     &lt;name>id&lt;/name>
  @@ -95,12 +95,12 @@
    *     &lt;rtexprvalue>false&lt;/rtexprvalue>
    *   &lt;/attribute>
    * </pre>
  - * 
  + *
    * @author Morgan Delagrange
    */
  -public class PreparedStatementImplTag extends BodyTagSupport 
  +public class PreparedStatementImplTag extends BodyTagSupport
       implements StatementTag {
  -  
  +
     private String _connId               = null;
     private PreparedStatement _statement = null;
     private int _rowCount = -1;
  @@ -110,12 +110,21 @@
       if(conn == null) {
         throw new JspTagException("There is no such connection'"+_connId+"'");
       }
  -    _statement = conn.prepareStatement(query);
  +    _statement = createStatement ( conn, query );
       pageContext.setAttribute(getId(), _statement);
     }
   
     /**
  -   * 
  +   * Let subclass redefine how to create the statement
  +   */
  +  protected PreparedStatement createStatement ( Connection theConnection, String 
theQuery ) throws SQLException
  +  {
  +    return theConnection.prepareStatement ( theQuery );
  +  }
  +
  +
  +  /**
  +   *
      * @param connId
      */
     public void setConn(String connId) {
  @@ -124,7 +133,7 @@
   
     /**
      * Get the PreparedStatement contained within this tag
  -   * 
  +   *
      * @return the PreparedStatement
      */
     public PreparedStatement getPreparedStatement() {
  @@ -155,7 +164,7 @@
       // _statement is set by the setQuery tag, not by the start tag.
       // Unlike Statements, PreparedStatements cannot be instantiated
       // without a query.
  -    
  +
       return EVAL_BODY_TAG;
     }
   
  
  
  
  1.8       +19 -10    
jakarta-taglibs/dbtags/src/org/apache/taglibs/dbtags/statement/StatementImplTag.java
  
  Index: StatementImplTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-taglibs/dbtags/src/org/apache/taglibs/dbtags/statement/StatementImplTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StatementImplTag.java     2001/07/02 18:19:45     1.7
  +++ StatementImplTag.java     2001/08/09 16:07:20     1.8
  @@ -70,7 +70,7 @@
    * <p>JSP tag statement.  According to the TEI, the java.sql.Statement
    * object specified in the "id" attribute is available within the scope
    * of the statement tags.  </p>
  - * 
  + *
    * <p>JSP Tag Lib Descriptor
    * <pre>
    * &lt;name>statement&lt;/name>
  @@ -90,11 +90,11 @@
    *     &lt;rtexprvalue>false&lt;/rtexprvalue>
    *   &lt;/attribute>
    * </pre>
  - * 
  + *
    * @author Morgan Delagrange
    */
   public class StatementImplTag extends BodyTagSupport implements StatementTag{
  -  
  +
     private Statement _statement = null;
     private String _query        = null;
     private String _connId       = null;
  @@ -126,7 +126,7 @@
     public void setTotalRowCount(int rowCount) {
       _rowCount = rowCount;
     }
  -  
  +
     public int doStartTag() throws JspTagException {
       if (_connId == null) {
         throw new JspTagException("Connection id has not been set.");
  @@ -137,16 +137,25 @@
         if(conn == null) {
           throw new JspTagException("There is no such connection'"+_connId+"'");
         }
  -      _statement = conn.createStatement();
  +      _statement = createStatement ( conn );
         pageContext.setAttribute(getId(), _statement);
       } catch (SQLException e) {
         throw new JspTagException(e.toString());
       }
  -    
  +
       return EVAL_BODY_TAG;
     }
   
   
  +  /**
  +   * Let subclass redefine how to create the statement
  +   */
  +  protected Statement createStatement ( Connection theConnection ) throws 
SQLException
  +  {
  +    return theConnection.createStatement();
  +  }
  +
  +
     public int doAfterBody() throws JspTagException
     {
         // Automatically trim the contents of this tag
  @@ -157,10 +166,10 @@
         }
         return EVAL_PAGE;
     }
  -  
  +
     public int doEndTag() {
       pageContext.removeAttribute(getId());
  -    
  +
       try {
         _statement.close();
       } catch (SQLException e) {
  @@ -170,11 +179,11 @@
   
       return EVAL_PAGE;
     }
  -      
  +
     public void release() {
       _connId=null;
       _statement = null;
       _query=null;
     }
  -  
  +
   }
  
  
  

Reply via email to