当前位置: 首页>>代码示例>>Java>>正文


Java BasicDBObject.toMap方法代码示例

本文整理汇总了Java中com.mongodb.BasicDBObject.toMap方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObject.toMap方法的具体用法?Java BasicDBObject.toMap怎么用?Java BasicDBObject.toMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.BasicDBObject的用法示例。


在下文中一共展示了BasicDBObject.toMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DBEntry

import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public DBEntry(BasicDBObject obj){
    super(obj.toMap());
}
 
开发者ID:gidim,项目名称:Babler,代码行数:4,代码来源:DBEntry.java

示例2: onTrigger

import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {

    final List<FlowFile> flowFiles = session.get(batchSize);
    if (flowFiles == null) {
        return;
    }

    ComponentLog logger = this.getLogger();

    final String source = context.getProperty(INSERT_COMMAND_SOURCE).getValue();

    List<InsertOneModel<Document>> documentsToInsert = new ArrayList<>(flowFiles.size());

    /*
     * Collect FlowFiles that are marked for bulk insertion. Matches same
     * index as documentsToInsert
     */
    List<FlowFile> flowFilesAttemptedInsert = new ArrayList<>();

    logger.debug("Attempting to batch insert {} FlowFiles", new Object[]{flowFiles.size()});
    for (FlowFile flowFile : flowFiles) {

        final String payload;

        try {
            switch (source) {
                case "content":
                    final String[] result = new String[1];
                    session.read(flowFile, (in) -> result[0] = IOUtils.toString(in));
                    payload = result[0];
                    break;
                case "attribute":
                    String command = context.getProperty(INSERT_COMMAND_ATTRIBUTE).evaluateAttributeExpressions(flowFile).getValue();
                    payload = flowFile.getAttribute(command);
                    break;
                default:
                    throw new Exception("Invalid source choice: " + source);
            }

            BasicDBObject parse = (BasicDBObject) JSON.parse(payload);
            Document documentToInsert = new Document(parse.toMap());
            logger.debug("Creating InsertOneModel with Document {}", new Object[]{documentToInsert});

            InsertOneModel<Document> iom = new InsertOneModel<>(documentToInsert);
            documentsToInsert.add(iom);

        } catch (Exception e) {
            /*
             * If any FlowFiles error on translation to a Mongo Object, they were not added to
             * the documentsToInsert, so route to failure immediately
             */
            logger.error("Encountered exception while processing FlowFile for Mongo Storage. Routing to failure and continuing.", e);
            FlowFile failureFlowFile = session.putAttribute(flowFile, "mongo.exception", e.getMessage());
            session.transfer(failureFlowFile, REL_FAILURE);
            continue;
        }

        // add to the ordered list so we can determine which fail on bulk
        // write
        flowFilesAttemptedInsert.add(flowFile);
    }

    /*
     * Perform the bulk insert if any documents are there to insert
     */
    if (!documentsToInsert.isEmpty()) {
        logger.debug("Attempting to bulk insert {} documents", new Object[]{documentsToInsert.size()});
        Map<Integer, BulkWriteError> writeErrors = executeBulkInsert(documentsToInsert);

        /*
         * Route FlowFiles to the proper relationship based on the returned
         * errors
         */
        logger.debug("Evaluating FlowFile routing against {} Write Errors for {} FlowFiles", new Object[]{writeErrors.size(), flowFilesAttemptedInsert.size()});
        transferFlowFiles(session, flowFilesAttemptedInsert, writeErrors);
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:79,代码来源:StoreInMongo.java


注:本文中的com.mongodb.BasicDBObject.toMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。