Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package br.com.anteros.nosql.persistence.mongodb.query;
import static br.com.anteros.core.utils.ObjectUtils.nullSafeHashCode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import org.bson.BSON;
import org.bson.BsonRegularExpression;
import org.bson.Document;
import org.bson.types.Binary;
import com.mongodb.BasicDBList;
import br.com.anteros.core.utils.Assert;
import br.com.anteros.core.utils.Base64;
import br.com.anteros.core.utils.CollectionUtils;
import br.com.anteros.core.utils.ObjectUtils;
import br.com.anteros.core.utils.StringUtils;
import br.com.anteros.nosql.persistence.session.query.Example;
import br.com.anteros.nosql.persistence.session.query.NoSQLCriteria;
public class MongoCriteria implements CriteriaDefinition, NoSQLCriteria {
private static final Object NOT_SET = new Object();
private String key;
private List criteriaChain;
private LinkedHashMap criteria = new LinkedHashMap();
private Object isValue = NOT_SET;
public static MongoCriteria of() {
return new MongoCriteria();
}
public static MongoCriteria where(String key) {
return new MongoCriteria(key);
}
public static MongoCriteria byExample(Object example) {
return byExample(Example.of(example));
}
public static MongoCriteria byExample(Example> example) {
return new MongoCriteria().alike(example);
}
protected MongoCriteria() {
this.criteriaChain = new ArrayList();
}
protected MongoCriteria(String key) {
this.criteriaChain = new ArrayList();
this.criteriaChain.add(this);
this.key = key;
}
protected MongoCriteria(List criteriaChain, String key) {
this.criteriaChain = criteriaChain;
this.criteriaChain.add(this);
this.key = key;
}
public MongoCriteria and(String key) {
return new MongoCriteria(this.criteriaChain, key);
}
public MongoCriteria is(Object o) {
if (!isValue.equals(NOT_SET)) {
throw new InvalidMongoDbApiUsageException(
"Multiple 'is' values declared. You need to use 'and' with multiple criteria");
}
if (lastOperatorWasNot()) {
throw new InvalidMongoDbApiUsageException("Invalid query: 'not' can't be used with 'is' - use 'ne' instead.");
}
this.isValue = o;
return this;
}
private boolean lastOperatorWasNot() {
return !this.criteria.isEmpty() && "$not".equals(this.criteria.keySet().toArray()[this.criteria.size() - 1]);
}
public MongoCriteria ne(Object o) {
criteria.put("$ne", o);
return this;
}
public MongoCriteria lt(Object o) {
criteria.put("$lt", o);
return this;
}
public MongoCriteria lte(Object o) {
criteria.put("$lte", o);
return this;
}
public MongoCriteria gt(Object o) {
criteria.put("$gt", o);
return this;
}
public MongoCriteria gte(Object o) {
criteria.put("$gte", o);
return this;
}
public MongoCriteria in(Object... o) {
if (o.length > 1 && o[1] instanceof Collection) {
throw new InvalidMongoDbApiUsageException(
"You can only pass in one argument of type " + o[1].getClass().getName());
}
criteria.put("$in", Arrays.asList(o));
return this;
}
public MongoCriteria in(Collection> c) {
criteria.put("$in", c);
return this;
}
public MongoCriteria nin(Object... o) {
return nin(Arrays.asList(o));
}
public MongoCriteria nin(Collection> o) {
criteria.put("$nin", o);
return this;
}
public MongoCriteria mod(Number value, Number remainder) {
List