Class QueryTagSupport

  • All Implemented Interfaces:
    java.io.Serializable, SQLExecutionTag, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag, javax.servlet.jsp.tagext.TryCatchFinally
    Direct Known Subclasses:
    QueryTag, QueryTag

    public abstract class QueryTagSupport
    extends javax.servlet.jsp.tagext.BodyTagSupport
    implements javax.servlet.jsp.tagext.TryCatchFinally, SQLExecutionTag

    Tag handler for <Query> in JSTL.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.sql.Connection conn  
      protected boolean dataSourceSpecified  
      private boolean isPartOfTransaction  
      protected int maxRows  
      protected boolean maxRowsSpecified  
      private java.util.List parameters  
      protected java.lang.Object rawDataSource  
      private int scope  
      protected java.lang.String sql  
      protected int startRow  
      private java.lang.String var  
      • Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport

        bodyContent
      • Fields inherited from class javax.servlet.jsp.tagext.TagSupport

        id, pageContext
      • Fields inherited from interface javax.servlet.jsp.tagext.BodyTag

        EVAL_BODY_BUFFERED, EVAL_BODY_TAG
      • Fields inherited from interface javax.servlet.jsp.tagext.IterationTag

        EVAL_BODY_AGAIN
      • Fields inherited from interface javax.servlet.jsp.tagext.Tag

        EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryTagSupport()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSQLParameter​(java.lang.Object o)
      Called by nested parameter elements to add PreparedStatement parameter values.
      void doCatch​(java.lang.Throwable t)
      Just rethrows the Throwable.
      int doEndTag()
      Execute the SQL statement, set either through the sql attribute or as the body, and save the result as a variable named by the var attribute in the scope specified by the scope attribute, as an object that implements the Result interface.
      void doFinally()
      Close the Connection, unless this action is used as part of a transaction.
      int doStartTag()
      Prepares for execution by setting the initial state, such as getting the Connection
      private java.sql.Connection getConnection()  
      private void init()  
      private void setParameters​(java.sql.PreparedStatement ps, java.util.List parameters)  
      void setScope​(java.lang.String scopeName)
      Setter method for the scope of the variable to hold the result.
      void setVar​(java.lang.String var)
      Setter method for the name of the variable to hold the result.
      • Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport

        doAfterBody, doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
      • Methods inherited from class javax.servlet.jsp.tagext.TagSupport

        findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.servlet.jsp.tagext.Tag

        getParent, setPageContext, setParent
    • Field Detail

      • var

        private java.lang.String var
      • scope

        private int scope
      • rawDataSource

        protected java.lang.Object rawDataSource
      • dataSourceSpecified

        protected boolean dataSourceSpecified
      • sql

        protected java.lang.String sql
      • maxRows

        protected int maxRows
      • maxRowsSpecified

        protected boolean maxRowsSpecified
      • startRow

        protected int startRow
      • conn

        private java.sql.Connection conn
      • parameters

        private java.util.List parameters
      • isPartOfTransaction

        private boolean isPartOfTransaction
    • Constructor Detail

      • QueryTagSupport

        public QueryTagSupport()
    • Method Detail

      • init

        private void init()
      • setVar

        public void setVar​(java.lang.String var)
        Setter method for the name of the variable to hold the result.
      • setScope

        public void setScope​(java.lang.String scopeName)
        Setter method for the scope of the variable to hold the result.
      • addSQLParameter

        public void addSQLParameter​(java.lang.Object o)
        Called by nested parameter elements to add PreparedStatement parameter values.
        Specified by:
        addSQLParameter in interface SQLExecutionTag
        Parameters:
        o - the PreparedStatement parameter value
      • doStartTag

        public int doStartTag()
                       throws javax.servlet.jsp.JspException
        Prepares for execution by setting the initial state, such as getting the Connection
        Specified by:
        doStartTag in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
        Throws:
        javax.servlet.jsp.JspException
      • doEndTag

        public int doEndTag()
                     throws javax.servlet.jsp.JspException

        Execute the SQL statement, set either through the sql attribute or as the body, and save the result as a variable named by the var attribute in the scope specified by the scope attribute, as an object that implements the Result interface.

        The connection used to execute the statement comes either from the DataSource specified by the dataSource attribute, provided by a parent action element, or is retrieved from a JSP scope attribute named javax.servlet.jstl.sql.dataSource.

        Specified by:
        doEndTag in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
        Throws:
        javax.servlet.jsp.JspException
      • doCatch

        public void doCatch​(java.lang.Throwable t)
                     throws java.lang.Throwable
        Just rethrows the Throwable.
        Specified by:
        doCatch in interface javax.servlet.jsp.tagext.TryCatchFinally
        Throws:
        java.lang.Throwable
      • doFinally

        public void doFinally()
        Close the Connection, unless this action is used as part of a transaction.
        Specified by:
        doFinally in interface javax.servlet.jsp.tagext.TryCatchFinally
      • getConnection

        private java.sql.Connection getConnection()
                                           throws javax.servlet.jsp.JspException,
                                                  java.sql.SQLException
        Throws:
        javax.servlet.jsp.JspException
        java.sql.SQLException
      • setParameters

        private void setParameters​(java.sql.PreparedStatement ps,
                                   java.util.List parameters)
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException