Package com.mongodb

Examples of com.mongodb.DBObject


      return cursor.hasNext();
    }

    @Override
    public Tuple next() {
      DBObject dbObject = cursor.next();
      return new Tuple( new MongoDBTupleSnapshot( dbObject, metadata, UPDATE ) );
    }
View Full Code Here


      String[] path = DOT_SEPARATOR_PATTERN.split( column );
      Object field = entity;
      int size = path.length;
      for (int index = 0 ; index < size ; index++) {
        String node = path[index];
        DBObject parent = (DBObject) field;
        field = parent.get( node );
        if ( field == null ) {
          if ( index == size - 1 ) {
            field = value;
          }
          else {
            field = new BasicDBObject();
          }
          parent.put( node, field );
        }
      }
    }
  }
View Full Code Here

    this.dbObject = document;
  }

  //not for embedded
  public DBObject getQueryObject() {
    DBObject query = new BasicDBObject();
    query.put( MongoDBDialect.ID_FIELDNAME, dbObject.get( MongoDBDialect.ID_FIELDNAME ) );
    return query;
  }
View Full Code Here

   *
   * @see com.sissi.persistent.PersistentElementBox#pull(com.sissi.context.JID)
   */
  @Override
  public Collection<Element> pull(JID jid) {
    DBObject query = BasicDBObjectBuilder.start().add(Dictionary.FIELD_TO, jid.asStringWithBare()).add("$or", this.activate).add(Dictionary.FIELD_CLASS, this.support).add(Dictionary.FIELD_RESEND, BasicDBObjectBuilder.start("$lt", this.resend).get()).get();
    Elements elements = new Elements(this.config.collection().find(query), this.elements);
    // {"$set:{"activate":false,"$inc":{"resend":1}}}
    this.config.collection().update(query, BasicDBObjectBuilder.start().add("$set", BasicDBObjectBuilder.start(Dictionary.FIELD_ACTIVATE, false).get()).add("$inc", BasicDBObjectBuilder.start(Dictionary.FIELD_RESEND, 1).get()).get(), false, true);
    return elements;
  }
View Full Code Here

   * @param bare
   * @return
   */
  protected MongoMucRelationContext remove(JID from, JID to, boolean bare) {
    // {"roles":bare == true ? jid:from.bare : path:from}
    DBObject remove = BasicDBObjectBuilder.start(Dictionary.FIELD_ROLES, bare ? BasicDBObjectBuilder.start(Dictionary.FIELD_JID, from.asStringWithBare()).get() : BasicDBObjectBuilder.start(Dictionary.FIELD_PATH, from.asString()).get()).get();
    if (ItemAffiliation.NONE.equals(this.ourRelation(from, to).cast(MucRelation.class).affiliation())) {
      // {"affiliations.jid":from.bare}
      // {"informaitons.jid":from.bare}
      remove.put(Dictionary.FIELD_AFFILIATIONS, BasicDBObjectBuilder.start(Dictionary.FIELD_JID, from.asStringWithBare()).get());
      remove.put(Dictionary.FIELD_INFORMATIONS, BasicDBObjectBuilder.start(Dictionary.FIELD_JID, from.asStringWithBare()).get());
    }
    // {"jid":to.bare,"role.path":from}, {"$inc":{"configs.maxusers":-1}, "$pull":...remove...}
    this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, to.asStringWithBare()).add(Dictionary.FIELD_ROLES + "." + Dictionary.FIELD_PATH, from.asString()).get(), BasicDBObjectBuilder.start().add("$inc", this.countDecMaxUsers).add("$pull", remove).get(), false, false, WriteConcern.SAFE);
    return this;
  }
View Full Code Here

      }
    } catch (MongoException e) {
      String role = ItemRole.toString(this.mapping[this.vcardContext.exists(this.jidBuilder.build(relation.jid())) ? ItemAffiliation.parse(relation.cast(MucRelation.class).affiliation()).ordinal() : ItemAffiliation.OWNER.ordinal()]);
      // 如果已存在岗位(新增用户)
      if (this.affiliation(from, this.jidBuilder.build(relation.jid()), null) != null) {
        DBObject query = this.buildQuery(relation.jid());
        query.put(Dictionary.FIELD_AFFILIATIONS + "." + Dictionary.FIELD_JID, from.asStringWithBare());
        // {"jid":jid,"affiliations.jid":from.bare}, {"$inc":{"configs.maxusers":1},"$set":{"affiliations.nick":relation.name,"$addToSet":{"roles":全部属性}}
        this.config.collection().update(query, BasicDBObjectBuilder.start().add("$inc", this.countIncMaxUsers).add("$set", BasicDBObjectBuilder.start(Dictionary.FIELD_AFFILIATIONS + ".$." + Dictionary.FIELD_NICK, relation.name()).get()).add("$addToSet", BasicDBObjectBuilder.start().add(Dictionary.FIELD_ROLES, BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, from.asStringWithBare()).add(Dictionary.FIELD_PATH, from.asString()).add(Dictionary.FIELD_RESOURCE, from.resource()).add(Dictionary.FIELD_NICK, relation.name()).add(Dictionary.FIELD_ROLE, role).add(Dictionary.FIELD_ACTIVATE, System.currentTimeMillis()).get()).get()).get(), true, false, WriteConcern.SAFE);
      } else {
       
        // {"jid":jid}, {"$setOnInsert", {...plus...,"configs.activate":true,"creator":from.bare,"$inc":{"configs.maxusers":1},"$addToSet":{"affiliations":...全部属性...,"roles":...全部属性...}
View Full Code Here

    protected JIDGroup(List<?> db) {
      if (db == null) {
        return;
      }
      for (Object each : db) {
        DBObject jid = DBObject.class.cast(each);
        super.add(MongoMucRelationContext.this.jidBuilder.build(MongoUtils.asString(jid, Dictionary.FIELD_JID)).resource(MongoUtils.asString(jid, Dictionary.FIELD_RESOURCE)));
      }
    }
View Full Code Here

     * @return
     */
    private MongoRelations prepareAffiliations(DBObject db) {
      List<?> affiliations = MongoUtils.asList(db, Dictionary.FIELD_AFFILIATIONS);
      for (Object each : affiliations) {
        DBObject affiliation = DBObject.class.cast(each);
        this.affiliations.put(MongoUtils.asString(affiliation, Dictionary.FIELD_JID), MongoUtils.asString(affiliation, Dictionary.FIELD_AFFILIATION));
      }
      return this;
    }
View Full Code Here

      }
      return this;
    }

    private MongoRelations prepareRelations(DBObject db) {
      DBObject relation = new BasicDBObject();
      // 恒定信息: JID, 创建者
      relation.put(Dictionary.FIELD_JID, MongoUtils.asString(db, Dictionary.FIELD_JID));
      relation.put(Dictionary.FIELD_CREATOR, MongoUtils.asString(db, Dictionary.FIELD_CREATOR));
      // 加载Roles
      for (Object each : MongoUtils.asList(db, Dictionary.FIELD_ROLES)) {
        DBObject roles = DBObject.class.cast(each);
        relation.put(Dictionary.FIELD_ROLES, roles);
        // 加载岗位
        relation.put(Dictionary.FIELD_AFFILIATION, this.affiliations.get(roles.get(Dictionary.FIELD_JID)));
        super.add(new MongoRelation(relation));
      }
      return this;
    }
View Full Code Here

    private String name;

    public MongoRelation(DBObject db) {
      this.creator = MongoUtils.asString(db, Dictionary.FIELD_CREATOR);
      this.affiliation = MongoUtils.asString(db, Dictionary.FIELD_AFFILIATION);
      DBObject roles = MongoUtils.asDBObject(db, Dictionary.FIELD_ROLES);
      this.jid = MongoUtils.asString(roles, Dictionary.FIELD_JID);
      this.role = MongoUtils.asString(roles, Dictionary.FIELD_ROLE);
      this.name = MongoUtils.asString(roles, Dictionary.FIELD_NICK);
      this.resource = MongoUtils.asString(roles, Dictionary.FIELD_RESOURCE);
    }
View Full Code Here

TOP

Related Classes of com.mongodb.DBObject

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.