com.ora.jsp.tags.sql
Class DBTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javax.servlet.jsp.tagext.BodyTagSupport
              |
              +--com.ora.jsp.tags.sql.DBTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.BodyTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag, ValueTagParent
Direct Known Subclasses:
QueryTag, UpdateTag

public abstract class DBTag
extends javax.servlet.jsp.tagext.BodyTagSupport
implements ValueTagParent

This class is a custom action for executing a SQL SELECT statement. The statement must be defined in the body of the action. It can contain ? place holders, replaced by the value of elements before execution. The number and order of place holders must match the number and order of elements in the body.

Version:
1.0
Author:
Hans Bergsten, Gefion software
See Also:
Serialized Form

Field Summary
private  java.lang.String dataSourceName
           
private  java.lang.String id
           
private  boolean isExceptionThrown
           
private  boolean isPartOfTransaction
           
private  int scope
           
private  SQLCommandBean sqlCommandBean
           
private  java.lang.String sqlValue
           
private  java.util.Vector values
           
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
pageContext, parent
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
DBTag()
           
 
Method Summary
 void addValue(Value value)
          Adds a value.
 int doAfterBody()
          Sets the SQL statement to the contents of the element's body.
 int doEndTag()
          If the action is included in the body of a tag, gets the connection from the tag.
 int doStartTag()
          Override the default implementation to reset the per-use state set by nested elements.
protected abstract  java.lang.Object execute(SQLCommandBean sqlCommandBean)
          Must be implemented by subclass to perform the appropriate processing.
private  java.sql.Connection getConnection()
          Gets the Connection either from a transaction parent or from the DataSource specified for the action.
 void release()
          Releases all instance variables.
 void setDataSource(java.lang.String dataSourceName)
          Sets the dataSource attribute.
 void setId(java.lang.String id)
          Sets the id attribute.
 void setScope(java.lang.String scopeName)
          Sets the scope attribute.
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Field Detail

sqlCommandBean

private SQLCommandBean sqlCommandBean

dataSourceName

private java.lang.String dataSourceName

id

private java.lang.String id

scope

private int scope

sqlValue

private java.lang.String sqlValue

values

private java.util.Vector values

isExceptionThrown

private boolean isExceptionThrown

isPartOfTransaction

private boolean isPartOfTransaction
Constructor Detail

DBTag

public DBTag()
Method Detail

setDataSource

public void setDataSource(java.lang.String dataSourceName)
Sets the dataSource attribute.
Parameters:
dataSource - the name of the DataSource object available in the application scope

setId

public void setId(java.lang.String id)
Sets the id attribute.
Overrides:
setId in class javax.servlet.jsp.tagext.TagSupport
Parameters:
id - the name for the result variable

setScope

public void setScope(java.lang.String scopeName)
Sets the scope attribute.
Parameters:
scope - the scope for the result variable

addValue

public void addValue(Value value)
Adds a value. This method is called by value tags in the action body.
Specified by:
addValue in interface ValueTagParent
Parameters:
value - a ValueHolder with a value for the PreparedStatement

doStartTag

public int doStartTag()
Override the default implementation to reset the per-use state set by nested elements.
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport

doAfterBody

public int doAfterBody()
                throws javax.servlet.jsp.JspException
Sets the SQL statement to the contents of the element's body.
Overrides:
doAfterBody in class javax.servlet.jsp.tagext.BodyTagSupport

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
If the action is included in the body of a tag, gets the connection from the tag. If not, gets the DataSource from the application scope and asks for a Connection. Executes the SQL query defined in the action element's body, and saves the result as a Vector with Row objects in the specified scope under the specified name.
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport

release

public void release()
Releases all instance variables.
Overrides:
release in class javax.servlet.jsp.tagext.BodyTagSupport

execute

protected abstract java.lang.Object execute(SQLCommandBean sqlCommandBean)
                                     throws java.sql.SQLException,
                                            UnsupportedTypeException
Must be implemented by subclass to perform the appropriate processing.

getConnection

private java.sql.Connection getConnection()
                                   throws javax.servlet.jsp.JspException
Gets the Connection either from a transaction parent or from the DataSource specified for the action.