Package com.mongodb

Examples of com.mongodb.BasicDBObjectBuilder


     *      target value
     * @return
     *      internal mong object
     */
    public DBObject getFeatUid(String value) {
        return new BasicDBObjectBuilder().add(UUID, value).get();
    }
View Full Code Here


     *      target value
     * @return
     *      internal mong object
     */
    public DBObject getEnable(boolean value) {
        return new BasicDBObjectBuilder().add(ENABLE, value).get();
    }
View Full Code Here

     *      target value
     * @return
     *      internal mong object
     */
    public DBObject getDescription(String value) {
        return new BasicDBObjectBuilder().add(DESCRIPTION, value).get();
    }
View Full Code Here

     *      target value
     * @return
     *      internal mong object
     */
    public DBObject getStrategy(String value) {
        return new BasicDBObjectBuilder().add(STRATEGY, value).get();
    }
View Full Code Here

     * @param value
     *            target value
     * @return internal mongo object
     */
    public DBObject getExpression(String value) {
        return new BasicDBObjectBuilder().add(EXPRESSION, value).get();
    }
View Full Code Here

     * @param value
     *            target value
     * @return internal mongo object
     */
    public DBObject getGroupName(String value) {
        return new BasicDBObjectBuilder().add(GROUPNAME, value).get();
    }
View Full Code Here

     * @param value
     *            target value
     * @return internal mongo object
     */
    public DBObject getRoles(String value) {
        return new BasicDBObjectBuilder().add(ROLES, value).get();
    }
View Full Code Here

    /**
     * parses the string and validates each part
     */
    public static BasicDBObject parseFieldsString(final String str, final Class clazz, final Mapper mapper, final boolean validate) {
        BasicDBObjectBuilder ret = BasicDBObjectBuilder.start();
        final String[] parts = str.split(",");
        for (String s : parts) {
            s = s.trim();
            int dir = 1;

            if (s.startsWith("-")) {
                dir = -1;
                s = s.substring(1).trim();
            }

            if (validate) {
                final StringBuilder sb = new StringBuilder(s);
                validateQuery(clazz, mapper, sb, FilterOperator.IN, "", true, false);
                s = sb.toString();
            }
            ret = ret.add(s, dir);
        }
        return (BasicDBObject) ret.get();
    }
View Full Code Here

        this.opts = opts;
    }

    @Override
    public void addTo(final DBObject obj) {
        final BasicDBObjectBuilder query;
        switch (getOperator()) {
            case NEAR:
                query = BasicDBObjectBuilder.start(FilterOperator.NEAR.val(), getValue());
                break;
            case NEAR_SPHERE:
                query = BasicDBObjectBuilder.start(FilterOperator.NEAR_SPHERE.val(), getValue());
                break;
            case WITHIN_BOX:
                query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
                break;
            case WITHIN_CIRCLE:
                query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
                break;
            case WITHIN_CIRCLE_SPHERE:
                query = BasicDBObjectBuilder.start().push(FilterOperator.GEO_WITHIN.val()).add(getOperator().val(), getValue());
                break;
            default:
                throw new UnsupportedOperationException(getOperator() + " not supported for geo-query");
        }

        //add options...
        if (opts != null) {
            for (final Map.Entry<String, Object> e : opts.entrySet()) {
                query.append(e.getKey(), e.getValue());
            }
        }

        obj.put(getField(), query.get());
    }
View Full Code Here

    protected <T> void ensureIndex(final DBCollection dbColl,
                                   final String name, final BasicDBObject fields,
                                   final boolean unique, final boolean dropDupsOnCreate,
                                   final boolean background, final boolean sparse,
                                   final int expireAfterSeconds) {
        final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder();
        if (name != null && name.length() != 0) {
            keyOpts.add("name", name);
        }
        if (unique) {
            keyOpts.add("unique", true);
            if (dropDupsOnCreate) {
                keyOpts.add("dropDups", true);
            }
        }

        if (background) {
            keyOpts.add("background", true);
        }
        if (sparse) {
            keyOpts.add("sparse", true);
        }

        if (expireAfterSeconds > -1) {
            keyOpts.add("expireAfterSeconds", expireAfterSeconds);
        }

        final BasicDBObject opts = (BasicDBObject) keyOpts.get();
        if (opts.isEmpty()) {
            LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields);
            dbColl.createIndex(fields);
        } else {
            LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts);
View Full Code Here

TOP

Related Classes of com.mongodb.BasicDBObjectBuilder

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.