com.landawn.abacus.condition.Criteria Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-query Show documentation
Show all versions of abacus-query Show documentation
Abacus Data Access and Analysis
/*
* Copyright (C) 2015 HaiYang Li
*
* 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 com.landawn.abacus.condition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.landawn.abacus.condition.ConditionFactory.CF;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NamingPolicy;
import com.landawn.abacus.util.SortDirection;
import com.landawn.abacus.util.Strings;
import com.landawn.abacus.util.WD;
/**
* At present, Supports
* {@code Where, OrderBy, GroupBy, Having, Join, Limit, ForUpdate, Union, UnionAll, Intersect, Except} clause. Each
* {@code clause} is independent. A {@code clause} should not be included in another {@code clause}. If there more than
* one {@code clause}, they should be composed in one {@code Criteria} condition.
*
* @author Haiyang Li
* @since 0.8
*/
public class Criteria extends AbstractCondition {
private static final Set aggregationOperators = N.newHashSet();
static {
aggregationOperators.add(Operator.UNION_ALL);
aggregationOperators.add(Operator.UNION);
aggregationOperators.add(Operator.INTERSECT);
aggregationOperators.add(Operator.EXCEPT);
aggregationOperators.add(Operator.MINUS);
}
private String preselect = null;
private List conditionList;
/**
*
*/
public Criteria() {
super(Operator.EMPTY);
conditionList = new ArrayList<>();
}
/**
*
*
* @return
*/
public String preselect() {
return preselect;
}
/**
* Gets the joins.
*
* @return
*/
public List getJoins() {
final List joins = new ArrayList<>();
for (final Condition cond : conditionList) {
if (cond instanceof Join) {
joins.add((Join) cond);
}
}
return joins;
}
/**
* Gets the where.
*
* @return
*/
public Cell getWhere() {
return (Cell) find(Operator.WHERE);
}
/**
* Gets the group by.
*
* @return
*/
public Cell getGroupBy() {
return (Cell) find(Operator.GROUP_BY);
}
/**
* Gets the having.
*
* @return
*/
public Cell getHaving() {
return (Cell) find(Operator.HAVING);
}
/**
* Gets the aggregation.
*
* @return
*/
@SuppressWarnings("unchecked")
public List getAggregation() {
List result = null;
for (final Condition cond : conditionList) {
if (aggregationOperators.contains(cond.getOperator())) {
if (result == null) {
result = new ArrayList<>();
}
result.add((Cell) cond);
}
}
if (result == null) {
result = N.emptyList();
}
return result;
}
/**
* Gets the order by.
*
* @return
*/
public Cell getOrderBy() {
return (Cell) find(Operator.ORDER_BY);
}
/**
* Gets the limit.
*
* @return
*/
public Limit getLimit() {
return (Limit) find(Operator.LIMIT);
}
/**
* Gets the conditions.
*
* @return
*/
public List getConditions() {
return conditionList;
}
/**
*
* @param operator
* @return
*/
public List get(final Operator operator) {
final List conditions = new ArrayList<>();
for (final Condition cond : conditionList) {
if (cond.getOperator() == operator) {
conditions.add(cond);
}
}
return conditions;
}
/**
*
* @param conditions
*/
void add(final Condition... conditions) {
addConditions(conditions);
}
/**
*
* @param conditions
*/
void add(final Collection extends Condition> conditions) {
addConditions(conditions);
}
/**
*
* @param operator
*/
void remove(final Operator operator) {
final List conditions = get(operator);
remove(conditions);
}
/**
*
* @param conditions
*/
void remove(final Condition... conditions) {
for (final Condition cond : conditions) {
conditionList.remove(cond); // NOSONAR
}
}
/**
*
* @param conditions
*/
void remove(final Collection extends Condition> conditions) {
conditionList.removeAll(conditions);
}
/**
* Clear.
*/
public void clear() {
conditionList.clear();
}
/**
* Gets the parameters.
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List | |
© 2015 - 2025 Weber Informatics LLC | Privacy Policy