com.ursful.framework.orm.query.BaseQueryImpl Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 @ursful.com
*
* 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.ursful.framework.orm.query;
import com.ursful.framework.orm.support.*;
import com.ursful.framework.orm.IBaseQuery;
import com.ursful.framework.orm.annotation.RdTable;
import com.ursful.framework.orm.utils.ORMUtils;
import org.springframework.core.annotation.AnnotationUtils;
import java.util.*;
public class BaseQueryImpl extends QueryImpl implements IBaseQuery {
private Class> table;
private Class> returnClass;
private List returnColumns = new ArrayList();
private List fixedReturnColumns = new ArrayList();
private List groups = new ArrayList();
private List groupCountsSelectColumns = new ArrayList();
public IBaseQuery orderDesc(String name){
orders.add(new Order(new Column(name), Order.DESC));
return this;
}
public IBaseQuery whereIsNull(String name){
addCondition(new Condition().and(new Expression(new Column(name), ExpressionType.CDT_IS_NULL)));
return this;
}
public IBaseQuery whereIsNotNull(String name){
addCondition(new Condition().and(new Expression(new Column(name), ExpressionType.CDT_IS_NOT_NULL)));
return this;
}
public IBaseQuery whereIsEmpty(String name){
addCondition(new Condition().and(new Expression(new Column(name), ExpressionType.CDT_IS_EMPTY)));
return this;
}
public IBaseQuery whereIsNotEmpty(String name){
addCondition(new Condition().and(new Expression(new Column(name), ExpressionType.CDT_IS_NOT_EMPTY)));
return this;
}
public IBaseQuery where(String name, ExpressionType type){
if(ExpressionType.CDT_IS_NULL == type
|| ExpressionType.CDT_IS_NOT_NULL == type
|| ExpressionType.CDT_IS_EMPTY == type
|| ExpressionType.CDT_IS_NOT_EMPTY == type
) {
addCondition(new Condition().and(new Expression(new Column(name), type)));
}
return this;
}
@Override
public IBaseQuery whereEqual(String name, Object value) {
return where(name, value, ExpressionType.CDT_EQUAL);
}
@Override
public IBaseQuery whereNotEqual(String name, Object value) {
return where(name, value, ExpressionType.CDT_NOT_EQUAL);
}
@Override
public IBaseQuery whereLike(String name, String value) {
return where(name, value, ExpressionType.CDT_LIKE);
}
@Override
public IBaseQuery whereNotLike(String name, String value) {
return where(name, value, ExpressionType.CDT_NOT_LIKE);
}
@Override
public IBaseQuery whereStartWith(String name, String value) {
return where(name, value, ExpressionType.CDT_START_WITH);
}
@Override
public IBaseQuery whereEndWith(String name, String value) {
return where(name, value, ExpressionType.CDT_END_WITH);
}
@Override
public IBaseQuery whereNotStartWith(String name, String value) {
return where(name, value, ExpressionType.CDT_NOT_START_WITH);
}
@Override
public IBaseQuery whereNotEndWith(String name, String value) {
return where(name, value, ExpressionType.CDT_NOT_END_WITH);
}
@Override
public IBaseQuery whereLess(String name, Object value) {
return where(name, value, ExpressionType.CDT_LESS);
}
@Override
public IBaseQuery whereLessEqual(String name, Object value) {
return where(name, value, ExpressionType.CDT_LESS_EQUAL);
}
@Override
public IBaseQuery whereMore(String name, Object value) {
return where(name, value, ExpressionType.CDT_MORE);
}
@Override
public IBaseQuery whereMoreEqual(String name, Object value) {
return where(name, value, ExpressionType.CDT_MORE_EQUAL);
}
@Override
public IBaseQuery whereIn(String name, Collection value) {
return where(name, value, ExpressionType.CDT_IN);
}
@Override
public IBaseQuery whereNotIn(String name, Collection value) {
return where(name, value, ExpressionType.CDT_NOT_IN);
}
@Override
public IBaseQuery whereInValues(String name, Object... values) {
List