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

📄 searchkeydao.java

📁 实现了从Google
💻 JAVA
字号:
package com.ct.hotweb.dao;

import java.util.*;

import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.*;

import com.ct.hotweb.bean.*;
import com.ct.hotweb.db.*;
import com.ct.hotweb.util.*;

/**
 * generatedfilename字段已经放弃使用
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class SearchKeyDAO extends DAO {

	private final static String sqlUpdateSearchKey =
		"update searchkey set name=?, Description=?, parentId = ?,"
			+ " CreatedTime=?, LastGenerateTime=?,GeneratedFileName=? where id = ?";

	private final static String sqlInsertSearckKey =
		"insert into searchKey (name, Description, parentId, CreatedTime,"
			+ " LastGenerateTime, GeneratedFileName) values (?, ?, ?, ?, ?, ?)";

	private final static String sqlGetSameLevelSearchKey =
		"select * from searchkey where parentid = ?";

	private final static String sqlDeleteSearchKey =
		"delete from searchkey where id = ?";

	private final static String sqlGetHotWebInfo =
		"select * from hotwebinfo where parentid = ?";

	private final static String sqlDeleteHotWebInfo =
		"delete from hotwebinfo where parentid = ?";

	private final static String sqlInsertHotWebInfo =
		"insert into hotwebinfo (url, title, parentId, content) values (?, ?, ?, ?)";
		
	private final static String sqlGetSameLevelKeyId =
		"select id from searchkey where parentid = ?"; 
		
	public final static String sqlGenErrorSearchKey =
		"insert into searchkeyerrors(id, errorType) values(?, ?)";		
		
	public final static String sqlGetGenErrorSearchKey = 
		"select s.id, s.name, s.Description, s.ParentID, s.CreatedTime, " +
		"s.LastGenerateTime, s.GeneratedFileName " +
		" from searchkey s, searchkeyerrors se where s.id = se.id";
		
	public final static String sqlGetCountGenErrorSearchKey = 
		"select count(*) from searchkey s, searchkeyerrors se where s.id = se.id";
		
	public final static String sqlClearGenErrors =
		"delete from searchkeyerrors";
		
	public final static String sqlRemoveErrors =
		"delete from searchkeyerrors where id = ?";
		
	public final static String sqlExistsSameKey =
		"select count(*) from searchkey where parentid = ? and name = ?";
		
	public void updateSearchKey(SearchKey key) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		String[] v =
			new String[] {
				key.getName(),
				key.getDescription(),
				"" + key.getParentID(),
				key.getCreatedTime(),
				Utils.dateFormat(new Date(System.currentTimeMillis())), 
				key.getGeneratedFileName(),
				"" + key.getId()};
		run.update(SearchKeyDAO.sqlUpdateSearchKey, v);

	}

	public void deleteSearchKey(String id) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		String[] v = new String[] { id };
		run.update(SearchKeyDAO.sqlDeleteSearchKey, v);
	}

	public SearchKey createSearchKey(
		Category cat,
		String keyName,
		String keyDesc)
		throws Exception {
		//创建SearchKey实例
		SearchKey key = new SearchKey();
		key.setName(keyName);
		key.setParentID(cat.getId());
		key.setCreatedTime(
			Utils.dateFormat(new java.util.Date(System.currentTimeMillis())));
		key.setDescription(keyDesc);

		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new ArrayHandler();
		
		//查询是否在同一目录下有相同的Key名字
		String[] argExists = {"" + cat.getId(), key.getName()};
		Object[] exists = (Object[])run.query(sqlExistsSameKey, argExists, h);
		String count = "" + exists[0];
		if (!"0".equals(count)) return null; 
		
		String now =
			Utils.dateFormat(new java.util.Date(System.currentTimeMillis()));
		String[] args = { keyName, keyDesc, "" + cat.getId(), now, "", "" };
		//插入SearchKey
		run.update(sqlInsertSearckKey, args);
		//获取ID
		Object[] lastId = (Object[]) (run.query(sqlGetID, null, h));
		String id = "" + lastId[0];
		key.setId(Integer.parseInt(id, 10));

		return key;
	}

	public List getSameLevelSearchKey(String id) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new BeanListHandler(SearchKey.class);
		return (List) run.query(SearchKeyDAO.sqlGetSameLevelSearchKey, id, h);
	}

	public List getHotWebInfo(SearchKey key) throws Exception {
		if (key == null)
			return new ArrayList();
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new BeanListHandler(HotWebInfo.class);
		return (List) run.query(
			SearchKeyDAO.sqlGetHotWebInfo,
			"" + key.getId(),
			h);
	}

	public void addHotWebInfo(HotWebInfo info) throws Exception {
		if (info == null)
			return;

		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		String[] v =
			new String[] {
				info.getUrl(),
				info.getTitle(),
				"" + info.getParentId(),
				info.getContent()};
		run.update(SearchKeyDAO.sqlInsertHotWebInfo, v);
	}

	public void deleteHotWebInfo(SearchKey key) throws Exception {
		if (key == null)
			return;
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		String[] v = new String[] { "" + key.getId()};
		run.update(SearchKeyDAO.sqlDeleteHotWebInfo, v);
	}
	
	public String[] getSameLevelKeyIds(String id) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new ArrayHandler();
		Object[] objs = (Object[])run.query(SearchKeyDAO.sqlGetSameLevelSearchKey, id, h);
		String[] result = null;
		if (objs == null) return new String[0];
		else result = new String[objs.length];
		for (int i = 0; i < objs.length; i ++) {
			result[i] = "" + objs[i];	
		}
		return result;
	}
	
	public void saveGenSearchKeyError(String id) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		String[] args = {id, super.genErrorType};
		run.update(SearchKeyDAO.sqlGenErrorSearchKey, args);
	}

	public List getAllGenErrorSearchKey() throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new BeanListHandler(SearchKey.class);
		return (List) run.query(SearchKeyDAO.sqlGetGenErrorSearchKey, null, h);
	}
	
	public int getCountGenErrorSearchKey() throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		ResultSetHandler h = new ArrayHandler();
		Object[] o = (Object[])run.query(SearchKeyDAO.sqlGetCountGenErrorSearchKey, null, h);
		String count = "" + o[0];
		return Integer.parseInt(count);
	}
	
	public void clearGenSearchKeyError() throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		run.update(SearchKeyDAO.sqlClearGenErrors, null);		
	}	
	
	public void removeError(String id) throws Exception {
		QueryRunner run = new QueryRunner(DataSourceManager.getDataSource());
		run.update(SearchKeyDAO.sqlRemoveErrors, id);		
	}
	
}

⌨️ 快捷键说明

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