/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

  1. /**
  2. * $RCSfile: FileService.java
  3. * $Revision: 1.0
  4. * $Date: Jan 30, 2011
  5. *
  6. * Copyright (C) 2010 SlFile, Inc. All rights reserved.
  7. *
  8. * This software is the proprietary information of SlFile, Inc.
  9. * Use is subject to license terms.
  10. */
  11. package com.searchlocal.service;
  12. import java.io.File;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.sql.Timestamp;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import com.searchlocal.constants.Constant;
  19. import com.searchlocal.dao.FileDao;
  20. import com.searchlocal.exception.DBException;
  21. import com.searchlocal.exception.LogicException;
  22. import com.searchlocal.param.FileParam;
  23. import com.searchlocal.util.StringUtils;
  24. /**
  25. * ?????
  26. *
  27. * <p>Title: ?????</p>
  28. * <p>Description: </p>
  29. * <p>site: www.slfile.net</p>
  30. * @author changsong:qianjinfu@gmail.com
  31. * @version 1.0
  32. */
  33. public class FileService {
  34. /**
  35. * ??Batch??,????
  36. *
  37. * @param namespace ????
  38. * @throws DBException
  39. * @throws LogicException
  40. */
  41. public boolean execBatch(String namespace) throws DBException, LogicException {
  42. FileDao fileDao = new FileDao();
  43. String filepath = Constant.datapath + Constant.filedatapath + Constant.suffixname;
  44. filepath = StringUtils.editFilePath(filepath);
  45. fileDao.execbatch(filepath, namespace);
  46. File file = new File(filepath);
  47. // ??batch?????
  48. if (file.exists()) {
  49. file.delete();
  50. }
  51. return true;
  52. }
  53. /**
  54. * ??Batch??csv??
  55. *
  56. * @param filebeanList ??????
  57. * @param namespace ????
  58. * @param fileClassify ????
  59. * @throws DBException
  60. * @throws LogicException
  61. */
  62. public int createBatchFile(List<FileParam> filebeanList, String namespace)
  63. throws DBException, LogicException {
  64. // ??csv??
  65. File wordfile = new File(Constant.datapath + Constant.filedatapath + Constant.suffixname);
  66. FileOutputStream out = null;
  67. try {
  68. if (!wordfile.exists()) {
  69. wordfile.createNewFile();
  70. }
  71. out = new FileOutputStream(wordfile, true);
  72. } catch (IOException e) {
  73. // TODO Auto-generated catch block
  74. e.printStackTrace();
  75. }
  76. // ????
  77. for (Iterator<FileParam> iter = filebeanList.iterator(); iter.hasNext();) {
  78. FileParam element = (FileParam) iter.next();
  79. String temp = "";
  80. String path = element.getPath();
  81. path = StringUtils.editFilePathForBatch(path);
  82. temp = path;
  83. temp = temp + "," + new Timestamp(element.getLastModify());
  84. temp = temp + "," + element.getError();
  85. temp = temp + "\r\n";
  86. try {
  87. out.write(temp.getBytes("utf-8"));
  88. } catch (IOException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. // ???
  93. try {
  94. out.close();
  95. } catch (IOException e) {
  96. e.printStackTrace();
  97. }
  98. return filebeanList.size();
  99. }
  100. /**
  101. * ??Batch??csv??
  102. *
  103. * @param beanList ??????
  104. * @param namespace ????
  105. * @throws DBException
  106. * @throws LogicException
  107. */
  108. public boolean insertFileRecord(List<FileParam> beanList, String namespace) throws DBException,
  109. LogicException {
  110. FileDao fileDao;
  111. fileDao = new FileDao();
  112. return fileDao.insertFileRecord(beanList, namespace);
  113. }
  114. /**
  115. * ??Bean??
  116. *
  117. * @param beanList ??????
  118. * @param namespace ????
  119. * @throws DBException
  120. * @throws LogicException
  121. */
  122. public boolean updateFileRecord(List<FileParam> beanList, String namespace) throws DBException,
  123. LogicException {
  124. FileDao fileDao;
  125. fileDao = new FileDao();
  126. return fileDao.updateFileRecord(beanList, namespace);
  127. }
  128. /**
  129. * ????????????
  130. *
  131. * @param namespace ????
  132. * @throws DBException
  133. * @throws LogicException
  134. */
  135. public List<FileParam> getFileRecordList(String namespace) throws DBException, LogicException {
  136. FileDao fileDao;
  137. fileDao = new FileDao();
  138. List<FileParam> fileRecord = fileDao.getFileRecord(namespace);
  139. return fileRecord;
  140. }
  141. /**
  142. * ?????????????
  143. *
  144. * @param namespace ????
  145. * @param path ????
  146. * @throws DBException
  147. * @throws LogicException
  148. */
  149. public boolean deleteFileRecord(String namespace, String path) throws DBException,
  150. LogicException {
  151. FileDao fileDao;
  152. fileDao = new FileDao();
  153. return fileDao.deleteFileRecord(namespace, path);
  154. }
  155. /**
  156. * ?????????????
  157. *
  158. * @param namespace ????
  159. * @param path ??????
  160. * @throws DBException
  161. * @throws LogicException
  162. */
  163. public boolean deleteFileRecords(String namespace, List<String> paths) throws DBException,
  164. LogicException {
  165. FileDao fileDao;
  166. fileDao = new FileDao();
  167. return fileDao.deleteFileRecords(namespace, paths);
  168. }
  169. /**
  170. * ??????????
  171. *
  172. * @param namespace ????
  173. * @throws DBException
  174. * @throws LogicException
  175. */
  176. public boolean deleteRecord(String namespace, String table, String path) throws DBException,
  177. LogicException {
  178. FileDao fileDao;
  179. fileDao = new FileDao();
  180. return fileDao.deleteRecordByPath(namespace, table, path);
  181. }
  182. /**
  183. * ??File??
  184. *
  185. * @param namespace ????
  186. * @throws DBException
  187. * @throws LogicException
  188. */
  189. public boolean createFileTable(String namespace) throws DBException, LogicException {
  190. FileDao fileDao;
  191. fileDao = new FileDao();
  192. return fileDao.createFiletable(namespace);
  193. }
  194. }