本文整理汇总了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());
}
示例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);
}
}