Package org.nutz.mongo.entity

Examples of org.nutz.mongo.entity.MongoEntity


   * @param q
   *            查询对象
   * @return 匹配的对象
   */
  public NutMap findAndRemove(String collName, Object q) {
    MongoEntity moe = Mongos.entity(NutMap.class);
    return (NutMap) findAndRemove(collName, moe, q);
  }
View Full Code Here


   *            字段过滤设定
   * @param mcur
   *            对游标的排序等方式的修改
   */
  public <T> void each(Each<T> callback, Class<T> type, Object q, MKeys keys, MCur mcur) {
    MongoEntity moe = Mongos.entity(type);
    _each(callback, moe.getCollectionName(q), moe, q, keys, mcur);
  }
View Full Code Here

   * @param mcur
   *            对游标的排序等方式的修改
   * @return 对象列表
   */
  public void each(Each<NutMap> callback, String collName, Object q, MKeys keys, MCur mcur) {
    MongoEntity moe = Mongos.entity(q);
    _each(callback, collName, moe, q, keys, mcur);
  }
View Full Code Here

   *            查询条件
   * @return 对象
   */
  @SuppressWarnings("unchecked")
  public <T> T findOne(Class<T> type, Object q) {
    MongoEntity moe = Mongos.entity(type);
    // 获得集合
    String collName = moe.getCollectionName(q);
    if (db.collectionExists(collName)) {
      DBCollection coll = db.getCollection(collName);
      // 将 ref 对象转换成 DBObject
      DBObject dbRef = moe.formatObject(q);
      DBObject dbo = null == dbRef ? coll.findOne() : coll.findOne(dbRef);
      // 执行转换
      return (T) moe.toObject(dbo);
    }
    return null;
  }
View Full Code Here

   * @param q
   *            条件,为 null 表示整个集合
   * @return 数量
   */
  public long count(Object enref, Object q) {
    MongoEntity moe = Mongos.entity(enref);
    String collName = moe.getCollectionName(q);
    if (db.collectionExists(collName)) {
      DBCollection coll = db.getCollection(collName);
      DBObject dbq = moe.formatObject(q);
      return null == q ? coll.count() : coll.count(dbq);
    }
    return -1;
  }
View Full Code Here

   * @param field
   *            要计算的字段名
   * @return 数量
   */
  public long sum(Object enref, Object q, String field) {
    MongoEntity moe = Mongos.entity(enref);
    String fieldName = moe.getFieldDbName(field);
    String collName = moe.getCollectionName(q);
    if (db.collectionExists(collName)) {
      DBCollection coll = db.getCollection(collName);
      DBObject dbq = moe.formatObject(q);

      String reduce = "function(obj,prev){prev.csum+=obj." + fieldName + ";}";

      GroupCommand gcmd = new GroupCommandcoll,
                          Mongos.dbo(),
View Full Code Here

   * @param dropIfExists
   *            true 则如果存在,就 drop
   */
  public void create(Class<?> pojoType, boolean dropIfExists) {
    // 得到对应实体
    MongoEntity moe = Mongos.entity(pojoType);

    // 创建集合
    String collName = moe.getCollectionName(null);
    create(collName, dropIfExists, moe.getCappedSize(), moe.getCappedMax());

    // 创建索引
    if (moe.hasIndexes()) {
      for (MongoEntityIndex mei : moe.getIndexes()) {
        DBCollection coll = db.getCollection(collName);
        DBObject keys = moe.formatObject(mei.getFields());
        // 采用默认的名称
        if (Strings.isBlank(mei.getName())) {
          coll.ensureIndex(keys, Mongos.dbo("unique", mei.isUnique()));
        }
        // 采用自定义名称
View Full Code Here

   * @param pojoType
   *            集合的 POJO 类
   *
   */
  public void drop(Class<?> pojoType) {
    MongoEntity moe = Mongos.entity(pojoType);
    drop(moe.getCollectionName(null));
  }
View Full Code Here

TOP

Related Classes of org.nutz.mongo.entity.MongoEntity

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.