/filesearch/SearchLocalFile/src/com/searchlocal/dao/HtmlDao.java
http://filesearch.googlecode.com/ · Java · 175 lines · 107 code · 11 blank · 57 comment · 4 complexity · 524261ec3ec34104841c98b7e8b270c1 MD5 · raw file
- /**
- * $RCSfile: HtmlDao.java
- * $Revision: 1.0
- * $Date: Jan 30, 2011
- *
- * Copyright (C) 2010 SlFile, Inc. All rights reserved.
- *
- * This software is the proprietary information of SlFile, Inc.
- * Use is subject to license terms.
- */
- package com.searchlocal.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Timestamp;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
-
- import com.searchlocal.bean.HtmlFileBean;
- import com.searchlocal.exception.DBException;
- import com.searchlocal.exception.LogicException;
- import com.searchlocal.util.CLogger;
- import com.searchlocal.util.SQLParameterUtil;
- import com.searchlocal.util.SqlUtil;
- import com.searchlocal.util.StringUtils;
-
- /**
- * Html??Dao
- *
- * <p>Title: Html??Dao</p>
- * <p>Description: </p>
- * <p>site: www.slfile.net</p>
- * @author changsong:qianjinfu@gmail.com
- * @version 1.0
- */
- public class HtmlDao extends BaseDao {
-
- /** ?? */
- private static CLogger logger = new CLogger(HtmlDao.class);
-
- /**
- * ???
- */
- public HtmlDao() {
- }
-
- /**
- * ??Html?????
- *
- * @param conn ?????
- * @param sql db??
- * @param elementList ??????
- * @throws DBException
- */
- public static void executeHtmlUpdateSQL(Connection conn, String sql, List<HtmlFileBean> elementList)
- throws DBException {
- HtmlFileBean element = null;
- PreparedStatement stmt;
- try {
- stmt = conn.prepareStatement(sql);
- for (Iterator<HtmlFileBean> iter = elementList.iterator(); iter.hasNext();) {
- element = (HtmlFileBean) iter.next();
- stmt.setString(1, element.getFilename());
- stmt.setString(2, element.getPath());
- stmt.setTimestamp(3, new Timestamp(element.getLastmodify()));
- stmt.setString(4, element.getContent());
-
- if (stmt != null) {
- stmt.executeUpdate();
- }
- }
- } catch (SQLException e) {
- String param = SQLParameterUtil.getBeanToString(element);
- logger.error("DB_E013", sql, param, e);
- throw new DBException("DB_E013", e);
- }
- closeConnection(null, stmt, null);
- }
-
- /**
- * ??Html?
- *
- * @param namesapce ?????
- * @throws DBException
- */
- public boolean createHtmltable(String namesapce) throws LogicException, DBException {
- Connection conn = BaseDao.getConn(namesapce);
- openTransaction(conn);
- boolean success = false;
- // ??SQL
- String presql = SqlUtil.getSqlbyId("createHtmlRecord");
- Map<String, String> paramMap = new HashMap<String, String>();
- paramMap.put("namespace", namesapce);
- String sql = SQLParameterUtil.convertSQL(presql, paramMap);
- try {
- success = execute(sql, conn);
- } catch (DBException e) {
- logger.error("DB_E014", sql, e);
- throw new DBException("DB_E014", e);
- }
- commit(conn);
- closeConnection(null, null, conn);
- return success;
- }
-
- /**
- * ??Html??
- *
- * @param beanList Html????
- * @param filepath ????
- * @param lastmodify ??????
- * @param filename ????
- * @param namespace ???
- * @throws DBException
- * @throws LogicException
- */
- public boolean insertHtmlRecord(List<HtmlFileBean> beanList, String filepath, long lastmodify,
- String filename, String namesapce) throws LogicException, DBException {
- Connection conn = BaseDao.getBaseConn(namesapce);
-
- HtmlFileBean element = null;
- String presql = SqlUtil.getSqlbyId("insertHtmlRecord");
- Map<String, String> paramMap = new HashMap<String, String>();
- paramMap.put("namespace", namesapce);
- String sql = SQLParameterUtil.convertSQL(presql, paramMap);
- try {
- conn.setReadOnly(false);
- openTransaction(conn);
- for (Iterator<HtmlFileBean> iter = beanList.iterator(); iter.hasNext();) {
- element = (HtmlFileBean) iter.next();
- element.setFilename(filename);
- element.setLastmodify(lastmodify);
- element.setPath(filepath);
- }
- executeHtmlUpdateSQL(conn, sql, beanList);
- } catch (Exception e) {
- String param = SQLParameterUtil.getBeanToString(element);
- logger.error("DB_E015", sql, param, e);
- throw new DBException("DB_E015", e);
- }
- commit(conn);
- closeConnection(null, null, conn);
- return true;
- }
-
- /**
- * ??Batch??
- *
- * @param datapath csv????
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean execbatch(String datapath, String namesapce) throws DBException, LogicException {
- Connection conn = BaseDao.getBaseConn(namesapce);
- openTransaction(conn);
- Statement st = null;
- try {
- st = conn.createStatement();
- String sql = "Load Data InFile " + datapath
- + " Into Table t_html FIELDS TERMINATED BY ','";
- sql = StringUtils.editSQL(sql);
- st.execute(sql);
- } catch (SQLException e) {
- throw new DBException("DB_E027", e);
- }
- commit(conn);
- closeConnection(null, st, conn);
- return true;
- }
- }