Java Code Examples for com.mongodb.client.model.InsertManyOptions#ordered()

The following examples show how to use com.mongodb.client.model.InsertManyOptions#ordered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoAliasServiceImpl.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void saveAliasList(int chainId, List<AliasInfo> aliasInfoList) {
    if (aliasInfoList.isEmpty()) {
        return;
    }
    List<Document> documentList = new ArrayList<>();
    for (AliasInfo info : aliasInfoList) {
        Document document = DocumentTransferTool.toDocument(info, "address");
        documentList.add(document);
    }
    InsertManyOptions options = new InsertManyOptions();
    options.ordered(false);
    mongoDBService.insertMany(ALIAS_TABLE + chainId, documentList, options);
}
 
Example 2
Source File: MongoTransactionServiceImpl.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void saveCoinDataList(int chainId, List<CoinDataInfo> coinDataList) {
    if (coinDataList.isEmpty()) {
        return;
    }
    List<Document> documentList = new ArrayList<>();
    for (CoinDataInfo info : coinDataList) {
        documentList.add(info.toDocument());
    }
    InsertManyOptions options = new InsertManyOptions();
    options.ordered(false);
    mongoDBService.insertMany(COINDATA_TABLE + chainId, documentList, options);
}
 
Example 3
Source File: MongoPunishServiceImpl.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void savePunishList(int chainId, List<PunishLogInfo> punishLogList) {
    if (punishLogList.isEmpty()) {
        return;
    }

    List<Document> documentList = new ArrayList<>();
    for (PunishLogInfo punishLog : punishLogList) {
        documentList.add(DocumentTransferTool.toDocument(punishLog));
    }
    InsertManyOptions options = new InsertManyOptions();
    options.ordered(false);
    mongoDBService.insertMany(PUNISH_TABLE + chainId, documentList, options);
}
 
Example 4
Source File: MongoCaptureUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
public HashMap<String, Object> capture(List<BsonDocument> bsonDocumentList) {
	HashMap<String, Object> retMsg = new HashMap<String, Object>();
	MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("EventData",
			BsonDocument.class);
	try {
		InsertManyOptions option = new InsertManyOptions();
		option.ordered(false);
		collection.insertMany(bsonDocumentList, option);
	} catch (MongoBulkWriteException e) {
		retMsg.put("error", e.getMessage());
		return retMsg;
	}
	retMsg.put("eventCaptured", bsonDocumentList.size());
	return retMsg;
}
 
Example 5
Source File: MongoCaptureUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
public HashMap<String, Object> capture(List<BsonDocument> bsonDocumentList) {
	HashMap<String, Object> retMsg = new HashMap<String, Object>();
	MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("EventData",
			BsonDocument.class);
	try {
		InsertManyOptions option = new InsertManyOptions();
		option.ordered(false);
		collection.insertMany(bsonDocumentList, option);
	} catch (MongoBulkWriteException e) {
		retMsg.put("error", e.getMessage());
		return retMsg;
	}
	retMsg.put("eventCaptured", bsonDocumentList.size());
	return retMsg;
}
 
Example 6
Source File: MongoTransactionServiceImpl.java    From nuls-v2 with MIT License 4 votes vote down vote up
public void saveTxList(int chainId, List<TransactionInfo> txList) {
        if (txList.isEmpty()) {
            return;
        }
        long time1, time2;
        time1 = System.currentTimeMillis();
//        //当交易记录表超过100万条时,首先删除要最开始保存的记录
//        totalCount += txList.size();
//        if (totalCount > 1000000) {
//            int deleteCount = (int) (totalCount - 1000000);
//            BasicDBObject fields = new BasicDBObject();
//            fields.append("_id", 1);
//            List<Document> docList = this.mongoDBService.pageQuery(TX_TABLE + chainId, null, fields, Sorts.ascending("createTime"), 1, deleteCount);
//            List<String> hashList = new ArrayList<>();
//            for (Document document : docList) {
//                hashList.add(document.getString("_id"));
//            }
//            mongoDBService.delete(TX_TABLE + chainId, Filters.in("_id", hashList));
////            time2 = System.currentTimeMillis();
////            System.out.println("-----------delete, use: " + (time2 - time1));
////            time1 = System.currentTimeMillis();
//            totalCount = 1000000;
//        }

        InsertManyOptions options = new InsertManyOptions();
        options.ordered(false);

        List<Document> documentList = new ArrayList<>();

        int i = 0;
        for (TransactionInfo txInfo : txList) {
            if (txUnConfirmHashSet.contains(txInfo.getHash())) {
                deleteUnConfirmTx(chainId, txInfo.getHash());
            }
            documentList.add(txInfo.toDocument());
            i++;
            if (i == 1000) {
                mongoDBService.insertMany(TX_TABLE + chainId, documentList, options);
                documentList.clear();
                i = 0;
            }
        }
        if (documentList.size() != 0) {
            mongoDBService.insertMany(TX_TABLE + chainId, documentList, options);
        }
//        time2 = System.currentTimeMillis();
//        System.out.println("-----------insertMany, use: " + (time2 - time1));
    }