/** 更新数据库下载状态 一般用于数据库初始化* */ @Override public void updateDownloadComplete(YandeCG yandeCG) { DBObject mongoYandeCG = new BasicDBObject(); mongoYandeCG.put("_id", yandeCG.getMd5()); DBObject mongoYandeCGNew = new BasicDBObject(); mongoYandeCGNew.put("_id", yandeCG.getMd5()); mongoYandeCGNew.put("id", yandeCG.getId()); mongoYandeCGNew.put("md5", yandeCG.getMd5()); mongoYandeCGNew.put("downComplete", yandeCG.isDownComplete()); mongoYandeCGNew.put("tags", yandeCG.getTags()); mongoYandeCGNew.put("source", yandeCG.getSource()); mongoYandeCGNew.put("file_url", yandeCG.getFile_url()); mongoYandeCGNew.put("file_size", yandeCG.getFile_size()); WriteResult num = collection.update(mongoYandeCG, mongoYandeCGNew); logger.info("完成更新YandeCG下载状态 受影响的行数: " + num.getN()); }
/** * 存储单个对象YandeCG * * @author felixerio * */ @Override public void saveYandeCG(YandeCG yandeCG) { System.out.println("查询ID:" + yandeCG.getId()); DBObject dBObject = collection.findOne(new BasicDBObject("id", yandeCG.getId())); if (null == dBObject) { DBObject mongoYandeCG = new BasicDBObject(); mongoYandeCG.put("_id", yandeCG.getMd5()); mongoYandeCG.put("id", yandeCG.getId()); mongoYandeCG.put("md5", yandeCG.getMd5()); mongoYandeCG.put("downComplete", Boolean.FALSE); mongoYandeCG.put("tags", yandeCG.getTags()); mongoYandeCG.put("source", yandeCG.getSource()); mongoYandeCG.put("file_url", yandeCG.getFile_url()); mongoYandeCG.put("file_size", yandeCG.getFile_size()); mongoYandeCG.put("local_url", yandeCG.getLocal_url()); collection.save(mongoYandeCG); } else { System.out.println("数据已经存在 将略过此次存储 ID:" + yandeCG.getId()); } }
/** * 存储YandeCG List文件 * * @author felixerio * */ @Override public void saveListYandeCG(List<YandeCG> yandeCGList) { int num = yandeCGList.size(); for (int i = 0; i < num; i++) { logger.info("批量保存任务 正在处理第 " + i + " 个任务"); YandeCG yandeCG = new YandeCG(); yandeCG = yandeCGList.get(i); DBObject mongoYandeCG = new BasicDBObject(); mongoYandeCG.put("_id", yandeCG.getMd5()); mongoYandeCG.put("id", yandeCG.getId()); mongoYandeCG.put("md5", yandeCG.getMd5()); mongoYandeCG.put("downComplete", yandeCG.isDownComplete()); mongoYandeCG.put("tags", yandeCG.getTags()); mongoYandeCG.put("source", yandeCG.getSource()); mongoYandeCG.put("file_url", yandeCG.getFile_url()); mongoYandeCG.put("file_size", yandeCG.getFile_size()); mongoYandeCG.put("local_url", yandeCG.getLocal_url()); logger.info("批量保存任务 完成处理第 " + i + " 个任务"); logger.info(collection.save(mongoYandeCG).getN()); } mg.close(); }