001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.db.model;
017
018
019import io.jboot.utils.StrUtil;
020
021import java.io.Serializable;
022
023public class Column implements Serializable {
024    public static final String LOGIC_LIKE = "LIKE";
025    public static final String LOGIC_GT = ">";
026    public static final String LOGIC_GE = ">=";
027    public static final String LOGIC_LT = "<";
028    public static final String LOGIC_LE = "<=";
029    public static final String LOGIC_EQUALS = "=";
030    public static final String LOGIC_NOT_EQUALS = "!=";
031
032    public static final String LOGIC_IS_NULL = "IS NULL";
033    public static final String LOGIC_IS_NOT_NULL = "IS NOT NULL";
034
035    public static final String LOGIC_IN = "IN";
036    public static final String LOGIC_NOT_IN = "NOT IN";
037    public static final String LOGIC_BETWEEN = "BETWEEN";
038    public static final String LOGIC_NOT_BETWEEN = "NOT BETWEEN";
039
040
041    private String name;
042    private Object value;
043    private String logic = LOGIC_EQUALS;
044
045
046    public static Column create(String name) {
047        Column column = new Column();
048        column.setName(name);
049        return column;
050    }
051
052    public static Column create(String name, Object value) {
053        Column column = new Column();
054        column.setName(name);
055        column.setValue(value);
056        return column;
057    }
058
059    public static Column create(String name, Object value, String logic) {
060        Column column = new Column();
061        column.setName(name);
062        column.setValue(value);
063        column.setLogic(logic);
064        return column;
065    }
066
067    public Column logic(String logic) {
068        this.setLogic(logic);
069        return this;
070    }
071
072    public String getName() {
073        return name;
074    }
075
076    public void setName(String name) {
077        this.name = name;
078    }
079
080    public Object getValue() {
081        return value;
082    }
083
084    public void setValue(Object value) {
085        this.value = value;
086    }
087
088    public String getLogic() {
089        return logic;
090    }
091
092    public void setLogic(String logic) {
093        this.logic = logic;
094    }
095
096    public boolean hasPara() {
097        return !LOGIC_IS_NULL.equals(getLogic())
098                && !LOGIC_IS_NOT_NULL.equals(getLogic());
099    }
100
101    public boolean checkAvailable() {
102        if (StrUtil.isBlank(getName())) {
103            return false;
104        }
105        return !hasPara() || getValue() != null;
106    }
107
108}