All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sirius.db.mongo.constraints.MongoConstraint Maven / Gradle / Ivy

Go to download

Provides a modern and highly flexible ORM and lightweight connectivity for JDBC, MongoDB, Redis, Elasticsearch.

There is a newer version: 7.4
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.db.mongo.constraints;

import org.bson.Document;
import sirius.db.mixing.query.constraints.Constraint;

/**
 * Defines a constraint which is accepted by {@link sirius.db.mongo.MongoQuery} and most probably generated by
 * {@link MongoFilterFactory}.
 *
 * @see sirius.db.mongo.QueryBuilder#FILTERS
 */
public class MongoConstraint extends Constraint {

    protected String key;
    protected Object object;

    /**
     * Creates a new constraint for the given field.
     *
     * @param key    the field to filter
     * @param object the constraint most probably as BSON object or list
     */
    public MongoConstraint(String key, Object object) {
        this.key = key;
        this.object = object;
    }

    @Override
    public void asString(StringBuilder builder) {
        builder.append(key);
        builder.append(": ");
        if (object instanceof Document) {
            builder.append(((Document) object).toJson());
        } else {
            builder.append(object.toString());
        }
    }

    public String getKey() {
        return key;
    }

    public Object getObject() {
        return object;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy