Bug 8319 - sql:transaction dataSource attribute not taking precedence
Summary: sql:transaction dataSource attribute not taking precedence
Status: RESOLVED FIXED
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.0
Hardware: All All
: P3 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-19 23:10 UTC by Lance Andersen
Modified: 2004-11-16 19:05 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lance Andersen 2002-04-19 23:10:07 UTC
javax.servlet.jsp.jspl.sql.dataSource is taking precedence over the
sql:transaction dataSource attribute.


<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="sql_rt" uri="http://java.sun.com/jstl/sql_rt" %>
<%@ taglib prefix="tck" uri="http://java.sun.com/jstltck/jstltck-util" %>
<%@ page import="javax.sql.*,java.util.*" %>

<tck:test testName="positiveTxDataSourceConfigDataSourceTest">

  
   <!-- EL: Validate sql:transaction, sql:query actions and
javax.servlet.jsp.jstl.sql.dataSource
            configuration parameter  specifying a DataSource Object -->

   <h1>Validating sql:transaction, sql:query actions, the
javax.servlet.jsp.jstl.sql.dataSource 
   configuration parameter  specifying a DataSource Object using EL</h1>
   <p>

   <%-- Configure javax.servlet.jsp.jstl.sql.dataSource --%>
   <tck:config configVar="datasource" op="set" 
               value='<%= (DataSource) pageContext.getAttribute("jstlDS",
PageContext.APPLICATION_SCOPE) %>'/>

   <sql:transaction>
      <sql:query var="resultSet"  >
         <c:out value="${sqlProps.Simple_Select_Query}" />
      </sql:query>
   </sql:transaction>

   <c:choose>
      <c:when test="${resultSet.rowCount != JSTL_TAB1_ROWS}">
         <H2>ERROR:</H2>
         While using the configuration parameter <strong>
         javax.servlet.jsp.jstl.sql.dataSource</strong>, and the query: <strong>
         "<c:out value="${sqlProps.Simple_Select_Query}" />" , the expected
         number of rows <strong>"<c:out value="${JSTL_TAB1_ROWS}" />"</strong>
         was not returned. The actual number of rows returned was
         <strong>"<c:out value="${resultSet.rowCount}" />"<strong>.
         <p>
      </c:when>
      <c:otherwise>
         While using the configuration parameter <strong>
         javax.servlet.jsp.jstl.sql.dataSource</strong>, specifying a DataSource
         Object, the query succeeded.
         <p>
      </c:otherwise>
   </c:choose>

   <%-- Validate that the dataSource attribute overrides the config param --%>
   <tck:config configVar="datasource" op="set" value='<%= new Integer(1) %>'/>

   <c:catch var="e"  >
      <sql:transaction dataSource="${applicationScope.jstlDS}" >
         <sql:query var="resultSet1"  >
             <c:out value="${sqlProps.Select_Jstl_Tab1_By_Id_Query}" />
         </sql:query>
      </sql:transaction>
   </c:catch>

   <c:choose>
      <c:when test="${!empty e}">
         <H2>ERROR:</H2>
         javax.servlet.jsp.jstl.sql.dataSource <strong>did</strong> take
         precedence over the <strong>dataSource</strong> attribute!  
         The Exception that was raised
         is: <strong><c:out value='${e}' escapeXml='false' /></strong>.
         <p>
      </c:when>
      <c:otherwise>
         The dataSource attribute <strong>did</strong> take precedence over 
          javax.servlet.jsp.jstl.sql.dataSource. The query executed without
          an error.
         <p>
      </c:otherwise>
   </c:choose>

 
   <!-- RT: Validate sql:transaction, sql:query actions and
javax.servlet.jsp.jstl.sql.dataSource
            configuration parameter  specifying a DataSource Object -->

   <h1>Validating sql:transaction, sql:query actions, the
javax.servlet.jsp.jstl.sql.dataSource 
   configuration parameter  specifying a DataSource Object using RT</h1>
   <p>

 <%-- Configure javax.servlet.jsp.jstl.sql.dataSource --%>
   <tck:config configVar="datasource" op="set" 
               value='<%= (DataSource) pageContext.getAttribute("jstlDS",
PageContext.APPLICATION_SCOPE) %>'/>

       <sql_rt:transaction>
          <sql_rt:query var="resultSet2"  >           
            
<%=((Properties)pageContext.getAttribute("sqlProps",PageContext.APPLICATION_SCOPE)).getProperty("Simple_Select_Query")
%>
          </sql_rt:query>
       </sql_rt:transaction>

   <c:choose>
      <c:when test="${resultSet2.rowCount != JSTL_TAB1_ROWS}">
         <H2>ERROR:</H2>
         While using the configuration parameter <strong>
         javax.servlet.jsp.jstl.sql.dataSource</strong>, specifying a DataSource
         Object,  the query: <strong>
         "<c:out value="${sqlProps.Simple_Select_Query}" />" , the expected
         number of rows <strong>"<c:out value="${JSTL_TAB1_ROWS}" />"</strong>
         was not returned. The actual number of rows returned was
         <strong>"<c:out value="${resultSet2.rowCount}" />"<strong>.
         <p>
      </c:when>
      <c:otherwise>
         While using the configuration parameter <strong>
         javax.servlet.jsp.jstl.sql.dataSource</strong>, specifying a DataSource
         Object, the query succeeded.
         <p>
      </c:otherwise>
   </c:choose>


   <%-- Validate that the dataSource attribute overrides the config param --%>
   <tck:config configVar="datasource" op="set" value='<%= new Integer(1) %>'/>

   <c:catch var="e2"  >

       <sql_rt:transaction 
           dataSource='<%=(DataSource) pageContext.getAttribute("jstlDS",
PageContext.APPLICATION_SCOPE) %>'  >

          <sql_rt:query var="resultSet4" >
            
<%=((Properties)pageContext.getAttribute("sqlProps",PageContext.APPLICATION_SCOPE)).getProperty("Simple_Select_Query")
%>
          </sql_rt:query>
       </sql_rt:transaction>
 
   </c:catch>

   <c:choose>
      <c:when test="${!empty e2}">
         <H2>ERROR:</H2>
         javax.servlet.jsp.jstl.sql.dataSource <strong>did</strong> take
         precedence over the <strong>dataSource</strong> attribute!  
         The Exception that was raised
         is: <strong><c:out value='${e2}' escapeXml='false' /></strong>.
         <p>
      </c:when>
      <c:otherwise>
         The dataSource attribute <strong>did</strong> take precedence over 
          javax.servlet.jsp.jstl.sql.dataSource. The query executed without
          an error.
         <p>
      </c:otherwise>
   </c:choose>


  <tck:config configVar="datasource" op="remove" />
  
</tck:tes
Comment 1 Jan Luehe 2002-04-22 22:14:12 UTC
Fixed.
Comment 2 Lance Andersen 2002-04-23 13:08:23 UTC
This now works for sql:transaction but fails for sql_rt:transaction
Comment 3 Jan Luehe 2002-04-24 01:13:30 UTC
OK, we were passing the test below (named
"positiveTxDataSourceConfigDataSourceTest"), but the test we really should have
passed in order for this bug to be fixed is named
"positiveTxDataSourceConfigPrecedenceTest.jsp". We now pass this test, too.