⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampledatatagiteratorresultsetbytype.java

📁 这是一个mvc模式
💻 JAVA
字号:
package jsp.tags.dapact.samples;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import jsp.tags.dapact.conf.UserClassFactory;
import jsp.tags.dapact.lookup.BaseLookupValue;
import jsp.tags.dapact.tags.data.*;
/**
 * Title:        Data Aware Processing And Control Tags
 * Description:  Tag library for the processing and controlling the input and output of data.
 * Copyright:    LGPL (http://www.gnu.org/copyleft/lesser.html)
 * Compile Date: @compile_date@
 * @author Allen M Servedio
 * @amp_sign@version @VERSION@
 */

/**
 * Sample implementation of the data tag iterator result set using a type and subtype
 * to determine what query to run. These queries are based on the tables and data provided
 * in the sample_tables.sql file.
 */
public class SampleDataTagIteratorResultSetByType extends BaseDataTagIteratorResultSetByType implements ConnectionPoolInf
{
  /**
   * Default constructor...
   */
  public SampleDataTagIteratorResultSetByType()
  {
  }

  /**
   * Release the connection that this object contains.
   */
  public void releaseConnection() throws SQLException
  {
    Connections.releaseConnection(conn);
  }

  /**
   * Retrieves the connection pool that contains the connection for this query (which
   * happens to be this class). Since I intend this to only be used by a
   * page at a time, I am going to let the tag super class close the connection (which
   * is what it will do when it calls this method).
   *
   * @return the connection pool that the super class will use to close the connection.
   */
  protected ConnectionPoolInf getConnectionPool() throws SQLException
  {
    return this;
  }

  /**
   * Returns the prepared statement according type and subtype defined. This example is
   * a bit contrived, but gives you a flavor of some things that can be done. For instance,
   * it uses the subtype name to retrieve the value for the prepared statement.
   *
   * <p>Please keep in mind that a much better way to generate these select statements
   * would be to use one or more factories. The example here was done for simplicity of
   * example.</p>
   *
   * @return a prepared statement for the type property populated by a value from
   * the subtype property.
   */
  protected PreparedStatement getPreparedStatement() throws SQLException
  {
    conn = Connections.getConnection();
    String type = getType();
    String subtype = getSubtype();
    PreparedStatement ps = null;
    BaseLookupValue lookup = UserClassFactory.getLookupValueInstance(getLookupValueName());

    if ("product_types_all".equals(type))
    {
      ps = conn.prepareStatement("select id, prod_type_name from product_type order by prod_type_name");
    }
    else if ("product_type".equals(type))
    {
      ps = conn.prepareStatement("select id, prod_type_name from product_type where id = ? order by prod_type_name");
      String idStr = null;
      idStr = lookup.lookupValue(subtype, idStr, this, pageContext);
      int id = 0;
      if (idStr != null)
      {
        id = Integer.parseInt(idStr);
      }
      ps.setInt(1, id);
    }
    else if ("products_all".equals(type))
    {
      ps = conn.prepareStatement("select products.id, products.product_type_id, product_type.prod_type_name, products.prod_name, products.price from products, product_type where products.product_type_id = product_type.id order by product_type.prod_type_name, products.prod_name");
    }
    else if ("products_by_type".equals(type))
    {
      ps = conn.prepareStatement("select products.id, products.product_type_id, product_type.prod_type_name, products.prod_name, products.price from products, product_type where product_type.id = ? and products.product_type_id = product_type.id order by product_type.prod_type_name, products.prod_name");
      String idStr = null;
      idStr = lookup.lookupValue(subtype, idStr, this, pageContext);
      int id = 0;
      if (idStr != null)
      {
        id = Integer.parseInt(idStr);
      }
      ps.setInt(1, id);
    }
    else if ("one_product".equals(type))
    {
      ps = conn.prepareStatement("select products.id, products.product_type_id, product_type.prod_type_name, products.prod_name, products.price from products, product_type where products.id = ? and products.product_type_id = product_type.id order by product_type.prod_type_name, products.prod_name");
      String idStr = null;
      idStr = lookup.lookupValue(subtype, idStr, this, pageContext);
      int id = 0;
      if (idStr != null)
      {
        id = Integer.parseInt(idStr);
      }
      ps.setInt(1, id);
    }
    return ps;
  }

  private Connection conn;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -