Java源码示例:org.mongojack.DBQuery

示例1
@Override
public ReportSchedule update(String name, ReportSchedule schedule) {		
	
	if (schedule instanceof ReportScheduleImpl) {
		final ReportScheduleImpl scheduleImpl = (ReportScheduleImpl) schedule;
		LOG.debug("updated schedule: " + scheduleImpl);
		final Set<ConstraintViolation<ReportScheduleImpl>> violations = validator.validate(scheduleImpl);
		if (violations.isEmpty()) {
			//return coll.update(DBQuery.is("name", name), ruleImpl, false, false).getSavedObject();
			return coll.findAndModify(DBQuery.is("name", name), new BasicDBObject(), new BasicDBObject(),
					false, scheduleImpl, true, false);
		} else {
			throw new IllegalArgumentException("Specified object failed validation: " + violations);
		}
	} else
		throw new IllegalArgumentException(
				"Specified object is not of correct implementation type (" + schedule.getClass() + ")!");
}
 
示例2
public static void main(String[] args) throws Exception {
  CLIUtil cliUtil = new CLIUtil(WikiWebServicesExporter.class, HELP_MESSAGE, OPTION_BUILDERS);
  CommandLine cl = cliUtil.parseCommandLine(args);

  String host = cl.getOptionValue(OPTION_INPUT_DB_HOST, DEFAULT_HOST);
  Integer port = Integer.parseInt(cl.getOptionValue(OPTION_INPUT_DB_PORT, DEFAULT_PORT));
  String dbName = cl.getOptionValue(OPTION_INPUT_DB, DEFAULT_DB);
  String collection = cl.getOptionValue(OPTION_INPUT_DB_COLLECTION, DEFAULT_COLLECTION);
  String sequenceCollection = cl.getOptionValue(OPTION_INPUT_SEQUENCE_COLLECTION, DEFAULT_SEQUENCES_COLLECTION);

  LOGGER.info("Attempting to connect to DB %s:%d/%s, collection %s", host, port, dbName, collection);
  Loader loader = new Loader(host, port, UNUSED_SOURCE_DB, dbName, collection, sequenceCollection, DEFAULT_RENDERING_CACHE);

  JacksonDBCollection<Reachable, String> reachables = loader.getJacksonReachablesCollection();

  LOGGER.info("Connected to DB, reading reachables");

  List<Long> exportIds = !cl.hasOption(OPTION_EXPORT_SOME) ?
      Collections.emptyList() :
      Arrays.stream(cl.getOptionValues(OPTION_EXPORT_SOME))
          .map(Long::valueOf)
          .collect(Collectors.toList());

  TSVWriter<String, String> tsvWriter = new TSVWriter<>(HEADER);
  tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE)));
  try {
    DBCursor<Reachable> cursor = exportIds.isEmpty() ? reachables.find() :
        reachables.find(DBQuery.in("_id", exportIds));
    int written = 0;
    while (cursor.hasNext()) {
      final Reachable r = cursor.next();

      Map<String, String> row = new HashMap<String, String>() {{
        put("inchi", r.getInchi());
        put("inchi_key", r.getInchiKey());
        put("display_name", r.getPageName());
        put("image_name", r.getStructureFilename());
      }};
      tsvWriter.append(row);
      tsvWriter.flush();
      written++;
    }
    LOGGER.info("Wrote %d reachables to output TSV", written);
  } finally {
    tsvWriter.close();
  }
}
 
示例3
@Override
public int destroy(String ruleName) {
    Rule rule = coll.findOne(DBQuery.is("name", ruleName));
    removeAlertCondition(rule);
	return coll.remove(DBQuery.is("name", ruleName)).getN();
}
 
示例4
@Override
public ReportSchedule get(String id) {
	ReportSchedule reportSchedule = coll.find(DBQuery.is("_id", id)).next();
	return reportSchedule;
}
 
示例5
@Override
public List<Fortune> list() {
    return fortuneCollection.find(DBQuery.empty(), DBProjection.include("_id", "message")).toArray();
}