@Test public void test_CreateOrModify_EmptyCollection() { assertTrue(webResourceMetaInfoDao.createOrModify(Collections.EMPTY_LIST, WriteConcern.NONE) == 0); }
@Override public int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern) { if (webResourceMetaInfos == null ) return 0; if (webResourceMetaInfos.isEmpty() ) return 0; final List<String> candiateIds = new ArrayList<String>(); for (WebResourceMetaInfo one : webResourceMetaInfos ) { candiateIds.add(one.getId()); } final BasicDBObject query = new BasicDBObject(); final BasicDBObject retrievedFields = new BasicDBObject(); retrievedFields.put("_id", 1); query.put("_id", new BasicDBObject("$in", candiateIds)); DBCursor existing = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()) .find(query, retrievedFields); final List<String> existingIds = new ArrayList<String>(); while (existing.hasNext()) { final DBObject nextOne = existing.next(); existingIds.add(nextOne.get("_id").toString()); } LOG.debug("WebResourceMetaInfo {} to be created out of total of {}", existingIds.size(), webResourceMetaInfos.size()); final BulkWriteOperation bulk = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()).initializeOrderedBulkOperation(); for (final WebResourceMetaInfo one : webResourceMetaInfos) { if (existingIds.contains(one.getId())) { bulk.find(new BasicDBObject("_id",one.getId())).upsert().replaceOne(morphia.toDBObject(one)); } else { bulk.insert(morphia.toDBObject(one)); } } final BulkWriteResult result = bulk.execute(writeConcern); return webResourceMetaInfos.size(); }
WebResourceMetaInfoDaoImpl implements WebResourceMetaInfoDao { @Override public int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern) { if (webResourceMetaInfos == null ) return 0; if (webResourceMetaInfos.isEmpty() ) return 0; final List<String> candiateIds = new ArrayList<String>(); for (WebResourceMetaInfo one : webResourceMetaInfos ) { candiateIds.add(one.getId()); } final BasicDBObject query = new BasicDBObject(); final BasicDBObject retrievedFields = new BasicDBObject(); retrievedFields.put("_id", 1); query.put("_id", new BasicDBObject("$in", candiateIds)); DBCursor existing = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()) .find(query, retrievedFields); final List<String> existingIds = new ArrayList<String>(); while (existing.hasNext()) { final DBObject nextOne = existing.next(); existingIds.add(nextOne.get("_id").toString()); } LOG.debug("WebResourceMetaInfo {} to be created out of total of {}", existingIds.size(), webResourceMetaInfos.size()); final BulkWriteOperation bulk = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()).initializeOrderedBulkOperation(); for (final WebResourceMetaInfo one : webResourceMetaInfos) { if (existingIds.contains(one.getId())) { bulk.find(new BasicDBObject("_id",one.getId())).upsert().replaceOne(morphia.toDBObject(one)); } else { bulk.insert(morphia.toDBObject(one)); } } final BulkWriteResult result = bulk.execute(writeConcern); return webResourceMetaInfos.size(); } }
WebResourceMetaInfoDaoImpl implements WebResourceMetaInfoDao { @Override public int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern) { if (webResourceMetaInfos == null ) return 0; if (webResourceMetaInfos.isEmpty() ) return 0; final List<String> candiateIds = new ArrayList<String>(); for (WebResourceMetaInfo one : webResourceMetaInfos ) { candiateIds.add(one.getId()); } final BasicDBObject query = new BasicDBObject(); final BasicDBObject retrievedFields = new BasicDBObject(); retrievedFields.put("_id", 1); query.put("_id", new BasicDBObject("$in", candiateIds)); DBCursor existing = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()) .find(query, retrievedFields); final List<String> existingIds = new ArrayList<String>(); while (existing.hasNext()) { final DBObject nextOne = existing.next(); existingIds.add(nextOne.get("_id").toString()); } LOG.debug("WebResourceMetaInfo {} to be created out of total of {}", existingIds.size(), webResourceMetaInfos.size()); final BulkWriteOperation bulk = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()).initializeOrderedBulkOperation(); for (final WebResourceMetaInfo one : webResourceMetaInfos) { if (existingIds.contains(one.getId())) { bulk.find(new BasicDBObject("_id",one.getId())).upsert().replaceOne(morphia.toDBObject(one)); } else { bulk.insert(morphia.toDBObject(one)); } } final BulkWriteResult result = bulk.execute(writeConcern); return webResourceMetaInfos.size(); } WebResourceMetaInfoDaoImpl(DB mongoDB,Morphia morphia,Datastore datastore); }
WebResourceMetaInfoDaoImpl implements WebResourceMetaInfoDao { @Override public int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern) { if (webResourceMetaInfos == null ) return 0; if (webResourceMetaInfos.isEmpty() ) return 0; final List<String> candiateIds = new ArrayList<String>(); for (WebResourceMetaInfo one : webResourceMetaInfos ) { candiateIds.add(one.getId()); } final BasicDBObject query = new BasicDBObject(); final BasicDBObject retrievedFields = new BasicDBObject(); retrievedFields.put("_id", 1); query.put("_id", new BasicDBObject("$in", candiateIds)); DBCursor existing = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()) .find(query, retrievedFields); final List<String> existingIds = new ArrayList<String>(); while (existing.hasNext()) { final DBObject nextOne = existing.next(); existingIds.add(nextOne.get("_id").toString()); } LOG.debug("WebResourceMetaInfo {} to be created out of total of {}", existingIds.size(), webResourceMetaInfos.size()); final BulkWriteOperation bulk = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()).initializeOrderedBulkOperation(); for (final WebResourceMetaInfo one : webResourceMetaInfos) { if (existingIds.contains(one.getId())) { bulk.find(new BasicDBObject("_id",one.getId())).upsert().replaceOne(morphia.toDBObject(one)); } else { bulk.insert(morphia.toDBObject(one)); } } final BulkWriteResult result = bulk.execute(writeConcern); return webResourceMetaInfos.size(); } WebResourceMetaInfoDaoImpl(DB mongoDB,Morphia morphia,Datastore datastore); @Override boolean create(WebResourceMetaInfo webResourceMetaInfo, WriteConcern writeConcern); @Override int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern); @Override WebResourceMetaInfo read(String id); @Override List<WebResourceMetaInfo> read(List<String> ids); @Override boolean update(WebResourceMetaInfo webResourceMetaInfo, WriteConcern writeConcern); @Override WriteResult delete(String id); }
WebResourceMetaInfoDaoImpl implements WebResourceMetaInfoDao { @Override public int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern) { if (webResourceMetaInfos == null ) return 0; if (webResourceMetaInfos.isEmpty() ) return 0; final List<String> candiateIds = new ArrayList<String>(); for (WebResourceMetaInfo one : webResourceMetaInfos ) { candiateIds.add(one.getId()); } final BasicDBObject query = new BasicDBObject(); final BasicDBObject retrievedFields = new BasicDBObject(); retrievedFields.put("_id", 1); query.put("_id", new BasicDBObject("$in", candiateIds)); DBCursor existing = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()) .find(query, retrievedFields); final List<String> existingIds = new ArrayList<String>(); while (existing.hasNext()) { final DBObject nextOne = existing.next(); existingIds.add(nextOne.get("_id").toString()); } LOG.debug("WebResourceMetaInfo {} to be created out of total of {}", existingIds.size(), webResourceMetaInfos.size()); final BulkWriteOperation bulk = mongoDB.getCollection(datastore.getCollection(WebResourceMetaInfo.class).getName()).initializeOrderedBulkOperation(); for (final WebResourceMetaInfo one : webResourceMetaInfos) { if (existingIds.contains(one.getId())) { bulk.find(new BasicDBObject("_id",one.getId())).upsert().replaceOne(morphia.toDBObject(one)); } else { bulk.insert(morphia.toDBObject(one)); } } final BulkWriteResult result = bulk.execute(writeConcern); return webResourceMetaInfos.size(); } WebResourceMetaInfoDaoImpl(DB mongoDB,Morphia morphia,Datastore datastore); @Override boolean create(WebResourceMetaInfo webResourceMetaInfo, WriteConcern writeConcern); @Override int createOrModify(Collection<WebResourceMetaInfo> webResourceMetaInfos, WriteConcern writeConcern); @Override WebResourceMetaInfo read(String id); @Override List<WebResourceMetaInfo> read(List<String> ids); @Override boolean update(WebResourceMetaInfo webResourceMetaInfo, WriteConcern writeConcern); @Override WriteResult delete(String id);  }