Package com.mongodb

Examples of com.mongodb.DBObject


    }

    @Override
    @SuppressWarnings("unchecked")
    public List<AccessToken> loadAll(String username) {
        DBObject query = new BasicDBObject();
        query.put(AccessTokenImpl.USERNAME, username);
        final List<DBObject> objects = query(AccessTokenImpl.class, query);
        List<AccessToken> tokens = Lists.newArrayList();
        for (DBObject tokenObject : objects) {
            final Object id = tokenObject.get("_id");
            final AccessToken accessToken = new AccessTokenImpl((ObjectId) id, tokenObject.toMap());
View Full Code Here


        if (configuration.getRootUsername().equals(username)) {
            LOG.debug("User {} is the built-in admin user", username);
            return new UserImpl.LocalAdminUser(configuration);
        }

        final DBObject query = new BasicDBObject();
        query.put(UserImpl.USERNAME, username);

        final List<DBObject> result = query(UserImpl.class, query);
        if (result == null || result.isEmpty()) {
            return null;
        }

        if (result.size() > 1) {
            final String msg = "There was more than one matching user for username " + username + ". This should never happen.";
            LOG.error(msg);
            throw new RuntimeException(msg);
        }

        final DBObject userObject = result.get(0);
        final Object userId = userObject.get("_id");

        LOG.debug("Loaded user {}/{} from MongoDB", username, userId);
        return new UserImpl((ObjectId) userId, userObject.toMap());
    }
View Full Code Here

        return new UserImpl(Maps.<String, Object>newHashMap());
    }

    @Override
    public List<User> loadAll() {
        final DBObject query = new BasicDBObject();
        final List<DBObject> result = query(UserImpl.class, query);

        final List<User> users = Lists.newArrayList();
        for (DBObject dbObject : result) {
            users.add(new UserImpl((ObjectId) dbObject.get("_id"), dbObject.toMap()));
View Full Code Here

        if (role != null) {
            return null;
        }

        // Role does not exist; insert it...
        DBObject data = m_helper.serialize(roleName, type);

        WriteResult result = coll.insert(data);
       
        if (result.getLastError() != null) {
            result.getLastError().throwOnError();
View Full Code Here

            Role changedRole = event.getRole();

            try {
                DBCollection coll = getCollection();

                DBObject query = getTemplateObject(changedRole);
                DBObject update = m_helper.serializeUpdate(changedRole);

                WriteResult result = coll.update(query, update, false /* upsert */, false /* multi */);

                if (result.getLastError() != null) {
                    result.getLastError().throwOnError();
View Full Code Here

  public void write(Object source, DBObject target) {
    String strPerson = (String) source;
    String[] parsedStrPerson = StringUtils.tokenizeToStringArray(strPerson, ",");
    target.put("fname", parsedStrPerson[0]);
    target.put("lname", parsedStrPerson[1]);
    DBObject innerObject = new BasicDBObject();
    innerObject.put("city", parsedStrPerson[2]);
    innerObject.put("street", parsedStrPerson[3]);
    innerObject.put("zip", parsedStrPerson[4]);
    innerObject.put("state", parsedStrPerson[5]);
    target.put("address", innerObject);
  }
View Full Code Here

    }

    @Test
    public void testStoreOidOnSave() throws Exception {
        DBObject dbObject = new BasicDBObject();
        ObjectId oid = template.requestBody("direct:testStoreOidOnSave", dbObject, ObjectId.class);
        assertEquals(dbObject.get("_id"), oid);
    }
View Full Code Here

            template.requestBody("direct:insert", body);
        }
        assertEquals(100L, testCollection.count());
       
        // Testing the update logic
        DBObject extraField = new BasicDBObject("extraField", true);
        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
        assertEquals("Number of records with 'scientist' field = Darwin on must equal 0", 0, testCollection.count(new BasicDBObject("scientist", "Darwin")));

        DBObject updateObj = new BasicDBObject("$set", new BasicDBObject("scientist", "Darwin"));
       
        Object result = template.requestBodyAndHeader("direct:update", new Object[] {extraField, updateObj}, MongoDbConstants.MULTIUPDATE, true);
        assertTrue(result instanceof WriteResult);
       
        assertEquals("Number of records with 'scientist' field = Darwin on must equal 50 after update", 50,
View Full Code Here

            template.requestBody("direct:insert", body);
        }
        assertEquals(100L, testCollection.count());
       
        // Testing the update logic
        DBObject extraField = new BasicDBObject("extraField", true);
        assertEquals("Number of records with 'extraField' flag on must equal 50", 50L, testCollection.count(extraField));
       
        Object result = template.requestBody("direct:remove", extraField);
        assertTrue(result instanceof WriteResult);
       
View Full Code Here

            }
        });

        assertTrue(result.getOut().getBody() instanceof WriteResult);
        assertEquals("An input header was not returned", "def", result.getOut().getHeader("abc"));
        DBObject b = testCollection.findOne("testInsertString");
        assertNotNull("No record with 'testInsertString' _id", b);
    }
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.