/filesearch/SearchLocalFile/src/com/searchlocal/service/FileService.java
http://filesearch.googlecode.com/ · Java · 209 lines · 101 code · 15 blank · 93 comment · 3 complexity · 495957e74761d6c237be1f6f267419bf MD5 · raw file
- /**
- * $RCSfile: FileService.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.service;
-
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.sql.Timestamp;
- import java.util.Iterator;
- import java.util.List;
-
- import com.searchlocal.constants.Constant;
- import com.searchlocal.dao.FileDao;
- import com.searchlocal.exception.DBException;
- import com.searchlocal.exception.LogicException;
- import com.searchlocal.param.FileParam;
- import com.searchlocal.util.StringUtils;
-
- /**
- * ?????
- *
- * <p>Title: ?????</p>
- * <p>Description: </p>
- * <p>site: www.slfile.net</p>
- * @author changsong:qianjinfu@gmail.com
- * @version 1.0
- */
- public class FileService {
-
- /**
- * ??Batch??,????
- *
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean execBatch(String namespace) throws DBException, LogicException {
- FileDao fileDao = new FileDao();
- String filepath = Constant.datapath + Constant.filedatapath + Constant.suffixname;
- filepath = StringUtils.editFilePath(filepath);
-
- fileDao.execbatch(filepath, namespace);
- File file = new File(filepath);
- // ??batch?????
- if (file.exists()) {
- file.delete();
- }
- return true;
- }
-
- /**
- * ??Batch??csv??
- *
- * @param filebeanList ??????
- * @param namespace ????
- * @param fileClassify ????
- * @throws DBException
- * @throws LogicException
- */
- public int createBatchFile(List<FileParam> filebeanList, String namespace)
- throws DBException, LogicException {
- // ??csv??
- File wordfile = new File(Constant.datapath + Constant.filedatapath + Constant.suffixname);
- FileOutputStream out = null;
- try {
- if (!wordfile.exists()) {
- wordfile.createNewFile();
- }
- out = new FileOutputStream(wordfile, true);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- // ????
- for (Iterator<FileParam> iter = filebeanList.iterator(); iter.hasNext();) {
- FileParam element = (FileParam) iter.next();
- String temp = "";
- String path = element.getPath();
- path = StringUtils.editFilePathForBatch(path);
- temp = path;
- temp = temp + "," + new Timestamp(element.getLastModify());
- temp = temp + "," + element.getError();
- temp = temp + "\r\n";
- try {
- out.write(temp.getBytes("utf-8"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // ???
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return filebeanList.size();
- }
-
- /**
- * ??Batch??csv??
- *
- * @param beanList ??????
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean insertFileRecord(List<FileParam> beanList, String namespace) throws DBException,
- LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.insertFileRecord(beanList, namespace);
- }
-
- /**
- * ??Bean??
- *
- * @param beanList ??????
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean updateFileRecord(List<FileParam> beanList, String namespace) throws DBException,
- LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.updateFileRecord(beanList, namespace);
- }
-
- /**
- * ????????????
- *
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public List<FileParam> getFileRecordList(String namespace) throws DBException, LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- List<FileParam> fileRecord = fileDao.getFileRecord(namespace);
- return fileRecord;
- }
-
- /**
- * ?????????????
- *
- * @param namespace ????
- * @param path ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean deleteFileRecord(String namespace, String path) throws DBException,
- LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.deleteFileRecord(namespace, path);
- }
-
- /**
- * ?????????????
- *
- * @param namespace ????
- * @param path ??????
- * @throws DBException
- * @throws LogicException
- */
- public boolean deleteFileRecords(String namespace, List<String> paths) throws DBException,
- LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.deleteFileRecords(namespace, paths);
- }
-
- /**
- * ??????????
- *
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean deleteRecord(String namespace, String table, String path) throws DBException,
- LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.deleteRecordByPath(namespace, table, path);
- }
-
- /**
- * ??File??
- *
- * @param namespace ????
- * @throws DBException
- * @throws LogicException
- */
- public boolean createFileTable(String namespace) throws DBException, LogicException {
- FileDao fileDao;
- fileDao = new FileDao();
- return fileDao.createFiletable(namespace);
- }
- }