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

📄 exampledao.java

📁 网上购物系统
💻 JAVA
字号:
// ----------------------------------------------------------
// $Id: $
// Copyright (c) SHSAFE 2005-2006. All Rights Reserved.
// ----------------------------------------------------------
package example.common.dao;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Map;
import java.util.Properties;

import com.shsafe.common.database.DatabaseConnection;
import com.shsafe.common.database.dao.DynamicDAO;

/**
 * @author Michael J Chane
 * @version $Revision: $ $Date: $
 */
public class ExampleDAO extends DynamicDAO {

  /**
   * SQL definition
   */
  protected Properties definition;
  
  /**
   * Creates a new <code>ExampleDAO</code> object.
   * 
   * @param connection
   * @throws SQLException
   */
  public ExampleDAO(DatabaseConnection connection) throws SQLException {
    super(connection);
    definition = new Properties();

    InputStream in = null;
    try {
      // Current ClassLoader
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      // Definition filename
      String filename = getClass().getName().replace('.', '/') + ".properties";
      in = classLoader.getResourceAsStream(filename);
      definition.load(in);
    } catch (IOException ex) {
      log.error("Loading failed!", ex);
      throw new RuntimeException("Loading SQL definition failed!", ex);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ex) {
          log.error("IOException!", ex);
        }
      }
    }
  }

  /**
   * Retrieves the SQL statment for the specified statement ID and parameters.
   * The subclasses must implement this method and the returned statement should
   * be capable of receiving the two parameters defined as
   * <code>PAGE_INFO_OFFSET</code> and <code>PAGE_INFO_COUNT</code>.
   * 
   * @param key
   *          the specified statement ID
   * @param param
   *          the specified statement parameters
   * @param offset
   *          the data offset
   * @param count
   *          the data count
   * @return the SQL Statement for the specified statement ID and data map
   * @see com.shsafe.common.database.dao.BaseDAO#createStatement(java.lang.String,
   *      java.util.Map, int, int)
   */
  @Override
  protected String createStatement(String key,
                                   Map<String, Object> param,
                                   int offset,
                                   int count) {
    return new StringBuffer(createStatement(key, param)).append(" LIMIT :")
        .append(PAGE_INFO_COUNT).append(" OFFSET :").append(PAGE_INFO_OFFSET)
        .toString();
  }

  /**
   * Retrieves the original SQL Statement for the specified statement ID and
   * parameters. The subclasses must implement this method.
   * 
   * @param key
   *          the specified statement ID
   * @param param
   *          the specified statement parameters
   * @return the SQL Statement for the specified statement ID and data map
   * @see com.shsafe.common.database.dao.BaseDAO#getOriginalStatement(java.lang.String,
   *      java.util.Map)
   */
  @Override
  protected String getOriginalStatement(String key, Map<String, Object> param) {
    
    System.out.println(definition.getProperty(key));
    return definition.getProperty(key);
    
  }

}

⌨️ 快捷键说明

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