FileDocCategorySizeDatePackage
TransactionTag.javaAPI DocExample2870Thu Jun 28 16:14:16 BST 2001com.ora.jsp.tags.sql

TransactionTag

public class TransactionTag extends TagSupport
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.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private String
dataSourceName
private Connection
conn
Constructors Summary
Methods Summary
public intdoEndTag()
Commits the transaction, resets the auto commit flag and closes the Connection (so it's returned to the pool).

        try {
            conn.commit();
            conn.setAutoCommit(true);
            conn.close();
        }
        catch (SQLException e) {
            throw new JspException("SQL error: " + e.getMessage());
        }
        return EVAL_PAGE;
    
public intdoStartTag()
Sets the Connection to be used by all nested DB actions.

        conn = getTransactionConnection();
        return EVAL_BODY_INCLUDE;
    
java.sql.ConnectiongetConnection()
Returns the Connection used for the transaction. This method is used by nested DB actions.

        return conn;
    
private java.sql.ConnectiongetTransactionConnection()
Gets a DataSource from the application scope, with the name specified by the dataSource attribute, and prepares it for transaction handling.

        DataSource dataSource = (DataSource)
            pageContext.getAttribute(dataSourceName, PageContext.APPLICATION_SCOPE);
        if (dataSource == null) {
            throw new JspException("dataSource " + dataSourceName + " not found");
        }
        try {
            conn = dataSource.getConnection();
            conn.setAutoCommit(false);
        }
        catch (SQLException e) {
            throw new JspException("SQL error: " + e.getMessage());
        }
        return conn;
    
public voidrelease()
Releases all instance variables.

        dataSourceName =  null;
        conn = null;
        super.release();
    
public voidsetDataSource(java.lang.String dataSourceName)
Sets the dataSource attribute.

param
dataSource the name of the DataSource object available in the application scope

        this.dataSourceName = dataSourceName;