Package mungbean.query

Examples of mungbean.query.Query


    public void dropDatabase() {
        database.mapCollection("$cmd").command(new Command("dropDatabase"));
    }

    public Collection<String> getCollectionNames() {
        List<Map<String, Object>> names = database.mapCollection("system.namespaces").query(new Query());
        HashSet<String> result = new HashSet<String>();
        for (Map<String, Object> name : names) {
            result.add(String.valueOf(name.get("name")).split("\\.")[1]);
        }
        result.remove("system");
View Full Code Here


        }
        return results.get(0);
    }

    private QueryBuilder idQuery(final ObjectId id) {
        return new Query().setLimit(1).field("_id").is(id);
    }
View Full Code Here

            }
        }

        public void databaseTests() {
            DBCollection<Map<String, Object>> collection = context.openCollection("foo");
            long initialCount = collection.query(new Count(), new Query());
            collection.save(doc);

            List<Map<String, Object>> results = collection.query(idQuery);
            specify(results.size(), does.equal(1));
            specify(results.get(0).get("foo"), does.equal("bar"));
            collection.query(new Distinct<List<Object>>("foo"), new Query()).contains("bar");
            specify(collection.query(new Count(), new Query()), does.equal(initialCount + 1));
            runGroup(collection);
            specify(collection.query(new Count(), idQuery), does.equal(1));
            collection.delete(idQuery);
            specify(collection.query(idQuery).size(), does.equal(0));
            specify(context.dbAdmin().getCollectionNames(), containsExactly("foo"));
            specify(collection.query(new Count(), new Query()), does.equal(initialCount));
        }
View Full Code Here

        }

        public void runGroup(DBCollection<Map<String, Object>> collection) {
            HashMap<String, Double> initialValues = new HashMap<String, Double>();
            initialValues.put("foo", 0D);
            List<Map<String, Object>> result = collection.query(new Group(new String[] { "foo" }, initialValues, "function(obj, prev){ prev.csum=5; }"), new Query());
            specify(result.get(0).get("csum"), does.equal(5D));
        }
View Full Code Here

            final DBCollection<Map<String, Object>> collection = context.openCollection("foo");
            for (int a = 0; a < 10; a++) {
                collection.save(newDoc(new ObjectId(), a));
            }

            specify(collection.query(new Distinct<List<Object>>("foo"), new Query().field("foo").greaterThan(5)), containsExactly(6, 7, 8, 9));

            List<Map<String, Object>> values = collection.query(new Query().field("foo").orderDescending().greaterThan(3).lessThan(8));
            specify(values.size(), does.equal(4));
            specify(values.get(0).get("foo"), does.equal(7));
            specify(values.get(3).get("foo"), does.equal(4));
        }
View Full Code Here

            final DBCollection<Map<String, Object>> collection = context.openCollection("foo2");
            for (int a = 0; a < 10; a++) {
                collection.save(newDoc(new ObjectId(), a));
            }

            collection.update(new Query().field("foo").greaterThan(3), new Update().field("foo").increment(5));
            specify(collection.query(new Query().field("foo").is(9)).size(), does.equal(2));
        }
View Full Code Here

        }

        public void structuralUpdatesCanBeDone() {
            final DBCollection<Map<String, Object>> collection = context.openCollection("foo2");
            collection.save(newDoc(new ObjectId(), 1));
            collection.update(new Query().field("foo").is(1), new Update().field("list").set(list("1", "2", "3")));
            specify(collection.query(new Query().field("list").is(list("1", "2", "3"))).size(), does.equal(1));
        }
View Full Code Here

            final DBCollection<Map<String, Object>> collection = context.openCollection("foo2");
            for (int a = 0; a < 10; a++) {
                collection.save(newDoc(new ObjectId(), a));
            }

            collection.update(new Query().field("foo").greaterThan(3), new Update().increment(map("foo", 5)));
            specify(collection.query(new Query().field("foo").is(9)).size(), does.equal(2));
        }
View Full Code Here

            for (int a = 0; a < 10; a++) {
                collection.save(newDoc(new ObjectId(), a));
            }
            MapReduce mapReduce = new MapReduce("function(){emit(this.foo%2==0?\"even\":\"odd\",1); }", "function(k, vals){ var sum=0; for(var i in vals) sum += vals[i]; return sum;}");
            mapReduce.setVerbose(true);
            MapReduceResult result = collection.query(mapReduce, new Query());
            specify(result.wasOk());
        }
View Full Code Here

        public void objectWithIdCanBeStored() {
            final DBCollection<TestObjectWithId> collection = context.openCollection("foo", TestObjectWithId.class);
            final TestObjectWithId item = collection.save(new TestObjectWithId("foo", 123));
            TestObjectWithId itemFromDb = collection.find(item.id());

            specify(collection.query(new Query().field("name").is("foo")).get(0).value(), does.equal(123));

            specify(itemFromDb.id(), does.equal(item.id()));
            collection.delete(item.id());
            specify(new Block() {
                @Override
View Full Code Here

TOP

Related Classes of mungbean.query.Query

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.