Package com.mongodb

Examples of com.mongodb.BasicDBList


        for (Entry<String, JsonElement> entry: tmpMeta.entrySet()) {
          if (entry.getValue().isJsonArray()) {
            doc.addToMetadata(entry.getKey(), MongoDbUtil.encodeArray(entry.getValue().getAsJsonArray()));
          }
          else {
            BasicDBList dbl = new BasicDBList();
            dbl.add(MongoDbUtil.encodeUnknown(entry.getValue()));
            doc.addToMetadata(entry.getKey(), dbl);
          }
        }//TOTEST       
      }
     
View Full Code Here


    list2 = AdvancedQueryPojo.listFromApi(sQueryJson, new TypeToken<List<AdvancedQueryPojo>>(){});
    ////////////////////////////////////////////////
    System.out.println("APL=" + new Gson().toJson(list2));
   
    //API: BasicDBList (like feeds in the full system)
    BasicDBList dbl = new BasicDBList();
    BasicDBObject db01 = new BasicDBObject("index", 1);
    BasicDBObject db02 = new BasicDBObject("index", 2);
    BasicDBObject db03 = new BasicDBObject("index", 3);
    dbl.addAll(Arrays.asList(db01, db02, db03));
    ResponsePojo rp2 = new ResponsePojo(null, dbl, (BasePojoApiMap<BasicDBList>)null);
    System.out.println("DBO=" + rp2.toApi());
   
    //API: test the V0 DocumentPojo, which has a few differences (including a static version for raw modification)
    BasicDBObject docApiDbo = (BasicDBObject) DbManager.getDocument().getMetadata().findOne();
    // (remove a few things to tidy up display)
    docApiDbo.remove("entities");
    docApiDbo.remove("associations");
    docApiDbo.remove("metadata");
    // (remove things as a test)
//    docApiDbo.remove("sourceKey");
//    docApiDbo.remove("source");
//    docApiDbo.remove("mediaType");
    // (sourceKey in <key>#<community> format)
//    docApiDbo.put("sourceKey", docApiDbo.getString("sourceKey")+"#doc_api_test");
    // (display results of API mappings)
    DocumentPojo docApi = DocumentPojo.fromDb(docApiDbo, DocumentPojo.class);
    ResponsePojo rp3 = new ResponsePojo(null, docApi, new DocumentPojoApiMap());

    System.out.println("TIME_DOC_API1_CREATED="+docApi.getCreated());
    System.out.println("DOC_API1=" + rp3.toApi());
    DocumentPojoApiMap.mapToApi(docApiDbo);
    System.out.println("DOC_API2=" + BaseApiPojo.getDefaultBuilder().setPrettyPrinting().create().toJson(docApiDbo));
    DocumentPojo docFromApi = ApiManager.mapFromApi(ApiManager.mapToApi(docApi, null), DocumentPojo.class, null);
    System.out.println("TIME_DOC_API1_CREATED_INV="+docFromApi.getCreated());
   
/////////////////////////////////////////////////////////////////////////////
   
// DB testing:
    System.out.println("Open Community DB collection");
    //OLD:
    //CollectionManager cm = new CollectionManager();
    //DBCollection communityDb = cm.getCommunities();
    //NEW:
    DBCollection communityDb = DbManager.getSocial().getCommunity();
   
    //DB: read/write community object
    ////////////////////////////////////////////////
    //CANONICAL EXAMPLE:
    CommunityPojo cp = CommunityPojo.fromDb(communityDb.findOne(), CommunityPojo.class);
    System.out.println("CP1=" + cp.toDb()); // (converts DBObject to string ie BSON->JSON - should have { $oid } and { $date } objectid/date formats)
    ////////////////////////////////////////////////
    System.out.println("CP2=" + new Gson().toJson(cp)); // (will have complex object id format and string dates)
    //DB: read/write list of community objects
    ////////////////////////////////////////////////
    //CANONICAL EXAMPLE:
    List<CommunityPojo> cpl = CommunityPojo.listFromDb(communityDb.find().limit(3), CommunityPojo.listType());
    System.out.println("CPL1=" + CommunityPojo.listToDb(cpl, CommunityPojo.listType()));
    ////////////////////////////////////////////////
    System.out.println("CPL2=" + BaseDbPojo.getDefaultBuilder().create().toJson(cpl)); // (will have complex object id format and string dates)

    //Expect to see another delay here with the old method, new method should roll on...
    System.out.println("Open Document DB collection");
    //OLD:
    //CollectionManager cm2 = new CollectionManager();
    //DBCollection documentDb = cm2.getFeeds();
    //NEW:
    DBCollection documentDb = DbManager.getDocument().getMetadata();
   
    //DB: Read/write feed with metadata
    BasicDBObject query = new BasicDBObject("metadata", new BasicDBObject("$exists", true)); // (complex query so can't represent using pojos)
    query.put("entities", new BasicDBObject("$size", 3));
    ////////////////////////////////////////////////
    //CANONICAL EXAMPLE:
    DocumentPojo doc = DocumentPojo.fromDb(documentDb.findOne(query), DocumentPojo.class);
    System.out.println("DOC1="+doc.toDb());
    BasicDBList dblTest = (BasicDBList) doc.toDb().get("entities");
    BasicDBObject dboTest = (BasicDBObject) dblTest.get(0);
    if (!dboTest.get("doccount").getClass().toString().equals("class java.lang.Long")) {
      throw new RuntimeException(dboTest.get("doccount").getClass().toString() + " SHOULD BE LONG");
    }
    ////////////////////////////////////////////////
    System.out.println("DOC2="+new Gson().toJson(doc));
View Full Code Here

        getJComponentBoundUnit(Item.addKey).visible = false;
    }

    @Override
    protected DBObject createDBObject() {
        return new BasicDBList();
    }
View Full Code Here

        return new BasicDBList();
    }

    @Override
    protected void addField(String key, Object val) {
        BasicDBList list = (BasicDBList) value;
        list.add(val);
    }
View Full Code Here

      _javascript.setupJavascript(context.getConfiguration().get("arguments"), context, null);
      _javascript._engine.put("_query", context.getConfiguration().get("mongo.input.query"));
     
      // Set up cache if one is specified
      InfiniteMongoConfig config = new InfiniteMongoConfig(context.getConfiguration());
      BasicDBList caches = config.getCacheList();
      if ((null != caches) && !caches.isEmpty()) {       
        try {
          CacheUtils.addJSONCachesToEngine(caches, _javascript._engine, _javascript._secManager, (config.getLimit() > 0));
        } catch (Exception e) {
          throw new RuntimeException("Error setting up caches: " + caches);
        }
View Full Code Here

      _javascript.setupJavascript(context.getConfiguration().get("arguments"), context, context);
      _javascript._engine.put("_query", context.getConfiguration().get("mongo.input.query"));

      // Set up cache if one is specified
      InfiniteMongoConfig config = new InfiniteMongoConfig(context.getConfiguration());
      BasicDBList caches = config.getCacheList();
      if ((null != caches) && !caches.isEmpty()) {       
        try {
          CacheUtils.addJSONCachesToEngine(caches, _javascript._engine, _javascript._secManager, (config.getLimit() > 0));
        } catch (Exception e) {
          throw new RuntimeException("Error setting up caches: " + caches);
        }
View Full Code Here

        new DbJob() {
            @Override
            public Object doRun() throws Exception {
                BasicDBObject result = new BasicDBObject();
                BasicDBList shardList = new BasicDBList();
                BasicDBObject stats = getStats();
                BasicDBObject shards = (BasicDBObject) stats.get("shards");
                if (shards == null || shards.isEmpty())
                    return null;
                   
                long totalChunks = 0;
                long totalSize = stats.getLong("size");
                long totalCount = stats.getLong("count");

                for (Entry shard : shards.entrySet()) {
                    String shardName = (String) shard.getKey();
                    BasicDBObject shardStats = (BasicDBObject) shard.getValue();

                    BasicDBObject query = new BasicDBObject("ns", getCollectionNode().getCollection().getFullName());
                    query.put("shard", shardName);
                    long numChunks = config.getCollection("chunks").count(query);
                    totalChunks += numChunks;

                    double estChunkData = numChunks <= 0 ? 0 : shardStats.getLong("size") / numChunks;
                    long estChunkCount = numChunks <= 0 ? 0 : (long) Math.floor(shardStats.getLong("count") / numChunks);

                    BasicDBObject shardDetails = new BasicDBObject("shard", shardName);
                    shardDetails.put("data", shardStats.getLong("size"));
                    shardDetails.put("pctData", totalSize <= 0 ? 0 : (shardStats.getLong("size") * 100.0) / totalSize);
                    shardDetails.put("docs", shardStats.getLong("count"));
                    shardDetails.put("pctDocs", totalCount <= 0 ? 0 : (shardStats.getLong("count") * 100.0) / totalCount);
                    shardDetails.put("chunks", numChunks);
                    if (shardStats.containsField("avgObjSize"))
                    shardDetails.put("avgDocSize", shardStats.getDouble("avgObjSize"));
                    shardDetails.put("estimatedDataPerChunk", estChunkData);
                    shardDetails.put("estimatedDocsPerChunk", estChunkCount);
                    shardList.add(shardDetails);
                }
                result.put("shards", shardList);

                BasicDBObject total = new BasicDBObject();
                total.put("data", totalSize);
View Full Code Here

                Object res = handleSpecialFields(subdoc);
                if (res != null) {
                    doc.put(field, res);
                }
            } else if (val instanceof BasicDBList) {
                BasicDBList sublist = (BasicDBList) val;
                handleSpecialFields(sublist);
            }
        }
        return null;
    }
View Full Code Here

//        return new BasicDBObject("$" + op, param);
//    }

    BasicDBObject getAggregateCommand(String collection) {
        BasicDBObject cmd = new BasicDBObject("aggregate", collection);
        BasicDBList list = new BasicDBList();
        cmd.put("pipeline", list);
        for (BasicDBObject op : operationList) {
            list.add(op);
        }
        return cmd;
    }
View Full Code Here

    @Override
    protected void updateComponentCustom(JDialog old) {
        BasicDBObject cmd = (BasicDBObject) JSON.parse(pipeline);
        if (cmd != null && cmd.containsField("pipeline")) {
            BasicDBList list = (BasicDBList) cmd.get("pipeline");
            operationList.clear();
            for (Object op : list) {
                operationList.add((BasicDBObject) op);
            }
            refreshAggList();
View Full Code Here

TOP

Related Classes of com.mongodb.BasicDBList

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.