Package com.mongodb

Examples of com.mongodb.BasicDBObjectBuilder


   * @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();
  }
View Full Code Here


    this.jidBuilder = jidBuilder;
    this.filter = this.filter(filters);
  }

  private DBObject filter(List<String> filters) {
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    for (String filter : filters) {
      builder.add(filter, 0);
    }
    return builder.get();
  }
View Full Code Here

    @Override
    public boolean update(JID jid, String affiliation) {
      try {
        // {"affiliations.$.affiliation":Xxx}
        BasicDBObjectBuilder entity = BasicDBObjectBuilder.start().add(Dictionary.FIELD_AFFILIATIONS + ".$." + Dictionary.FIELD_AFFILIATION, affiliation);
        if (ItemAffiliation.OWNER.equals(affiliation)) {
          // {"creator":jid.bare}
          // 如果为Owner则同时更新创建者
          entity.add(Dictionary.FIELD_CREATOR, jid.asStringWithBare());
        }
        // {"jid":group.bare,"affiliations.jid":jid.bare"},{"$set":...entity...}
        return MongoUtils.success(MongoAffiliationBuilder.this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, this.group.asStringWithBare()).add(Dictionary.FIELD_AFFILIATIONS + "." + Dictionary.FIELD_JID, jid.asStringWithBare()).get(), BasicDBObjectBuilder.start().add("$set", entity.get()).get(), true, false, WriteConcern.SAFE));
      } catch (MongoException e) {
        // {"jid":group.bare},{"$addToSet":{"affiliations":{"jid":Xxx,"affiliation":Xxx}}}
        return MongoUtils.success(MongoAffiliationBuilder.this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, this.group.asStringWithBare()).get(), BasicDBObjectBuilder.start("$addToSet", BasicDBObjectBuilder.start(Dictionary.FIELD_AFFILIATIONS, BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, jid.asStringWithBare()).add(Dictionary.FIELD_AFFILIATION, affiliation).get()).get()).get(), true, false, WriteConcern.SAFE));
      }
    }
View Full Code Here

     * {"$set":{"configs.Xxx1":Xxx,"configs.Xxx2":Xxx}}
     *
     * @see com.sissi.ucenter.relation.muc.room.Room#push(com.sissi.field.Fields)
     */
    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;
    }
View Full Code Here

   * @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();
  }
View Full Code Here

    }

    @Override
    protected void append(LoggingEvent e) {

        BasicDBObjectBuilder objectBuilder = BasicDBObjectBuilder.start().
                add("ts", new Date(e.getTimeStamp())).
                add("msg", e.getFormattedMessage()).
                add("level", e.getLevel().toString()).
                add("logger", e.getLoggerName()).
                add("thread", e.getThreadName());
        if(e.hasCallerData()) {
            StackTraceElement st = e.getCallerData()[0];
            String callerData = String.format("%s.%s:%d", st.getClassName(), st.getMethodName(), st.getLineNumber());
            objectBuilder.add("caller", callerData);
        }
        Map<String, String> mdc = e.getMdc();
        if(mdc != null && !mdc.isEmpty()) {
            objectBuilder.add("mdc", new BasicDBObject(mdc) );
        }
        _collection.insert(objectBuilder.get());
    }
View Full Code Here

        }

        // Flush any pending records
        store.getWriter().flush();

        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        builder.add("_id", name);
        if (state.containsField("parent")) {
            builder.add("parent", state.get("parent"));
        }
        if (state.containsField("base")) {
            builder.add("base", state.get("base"));
        }
        builder.add("head", head.toString());
        DBObject nextState = builder.get();

        WriteResult result =
                journals.update(state, nextState, false, false, concern);
        if (result.getN() == 1) {
            state = nextState;
View Full Code Here

                head = newHead;
            }

            base = head;

            BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
            builder.add("_id", name);
            builder.add("parent", state.get("parent"));
            builder.add("base", base.toString());
            builder.add("head", head.toString());
            // TODO: concurrent updates?
            journals.update(state, builder.get(), false, false, concern);
        }
    }
View Full Code Here

    public synchronized boolean setHead(RecordId base, RecordId head) {
        if (!base.equals(getHead())) {
            return false;
        }

        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        builder.add("_id", name);
        if (state.containsField("parent")) {
            builder.add("parent", state.get("parent"));
        }
        if (state.containsField("base")) {
            builder.add("base", state.get("base"));
        }
        builder.add("head", head.toString());
        DBObject nextState = builder.get();

        WriteResult result =
                journals.update(state, nextState, false, false, concern);
        if (result.getN() == 1) {
            state = nextState;
View Full Code Here

                head = newHead;
            }

            base = head;

            BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
            builder.add("_id", name);
            builder.add("parent", state.get("parent"));
            builder.add("base", base.toString());
            builder.add("head", head.toString());
            // TODO: concurrent updates?
            journals.update(state, builder.get(), false, false, concern);
        }
    }
View Full Code Here

TOP

Related Classes of com.mongodb.BasicDBObjectBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.