Java Code Examples for com.mongodb.BasicDBObjectBuilder#start()

The following examples show how to use com.mongodb.BasicDBObjectBuilder#start() . 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: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
private BasicDBObject parseFieldsString(final String fields) {
    BasicDBObjectBuilder ret = BasicDBObjectBuilder.start();
    final String[] parts = fields.split(",");
    for (String s : parts) {
        s = s.trim();
        int dir = 1;
        if (s.startsWith("-")) {
            dir = -1;
            s = s.substring(1).trim();
        }
        ret = ret.add(s, dir);
    }
    return (BasicDBObject) ret.get();
}
 
Example 2
Source File: MongoRegisterSubmitContext.java    From sissi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(JID invoker, JID group, Fields fields) {
	DBObject entity = super.entities(fields, BasicDBObjectBuilder.start());
	try {
		// {"jid":to.bare,"informations.jid":from.bare},{"$set":{"infomrations.$.information":..entity..}}
		this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, group.asStringWithBare()).add(Dictionary.FIELD_INFORMATIONS + "." + Dictionary.FIELD_JID, invoker.asStringWithBare()).get(), BasicDBObjectBuilder.start("$set", BasicDBObjectBuilder.start(Dictionary.FIELD_INFORMATIONS + ".$." + Dictionary.FIELD_INFORMATION, entity).get()).get(), true, false, WriteConcern.SAFE);
	} catch (MongoException e) {
		// {"jid":to.bare},{"$addToSet"{"informations":{"jid":from.bare,"activate":当前时间,"information":...entity...}}}
		this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, group.asStringWithBare()).get(), BasicDBObjectBuilder.start().add("$addToSet", BasicDBObjectBuilder.start(Dictionary.FIELD_INFORMATIONS, BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, invoker.asStringWithBare()).add(Dictionary.FIELD_ACTIVATE, System.currentTimeMillis()).add(Dictionary.FIELD_INFORMATION, entity).get()).get()).get());
	}
	return true;
}
 
Example 3
Source File: MongoRoomBuilder.java    From sissi with Apache License 2.0 5 votes vote down vote up
public Room push(Fields fields) {
	BasicDBObjectBuilder update = BasicDBObjectBuilder.start();
	for (Field<?> field : fields) {
		RoomConfigParser parser = MongoRoomBuilder.this.parsers.get(field.getName());
		if (parser != null) {
			update.add(Dictionary.FIELD_CONFIGS + "." + parser.field(), parser.parse(field));
		}
	}
	if (!update.isEmpty()) {
		MongoRoomBuilder.this.config.collection().update(this.build(), BasicDBObjectBuilder.start("$set", update.get()).get());
	}
	return this;
}
 
Example 4
Source File: MongoAddressing.java    From sissi with Apache License 2.0 5 votes vote down vote up
/**
 * For FindXxx</p>{"jid",Xxx,"resource":Xxx(如果使用资源)}
 * 
 * @param jid
 * @param usingResource
 * @return
 */
private DBObject buildQueryWithSmartResource(JID jid, boolean usingResource) {
	// JID,Resource
	BasicDBObjectBuilder query = BasicDBObjectBuilder.start(Dictionary.FIELD_JID, jid.asStringWithBare());
	if (usingResource && !jid.isBare()) {
		query.add(Dictionary.FIELD_RESOURCE, jid.resource());
	}
	return query.get();
}
 
Example 5
Source File: BridgeExchangerContext.java    From sissi with Apache License 2.0 5 votes vote down vote up
/**
 * {"host":host,"date":Xxx}
 * 
 * @param host
 * @param date
 * @return
 */
private DBObject build(String host, boolean date) {
	BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(Dictionary.FIELD_HOST, host);
	if (date) {
		builder.add(this.date, System.currentTimeMillis());
	}
	return builder.get();
}