sirius.db.mongo.constraints.MongoConstraint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirius-db Show documentation
Show all versions of sirius-db Show documentation
Provides a modern and highly flexible ORM and lightweight connectivity for JDBC, MongoDB, Redis, Elasticsearch.
/*
* 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;
}
}