All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xin.xihc.jba.sql.clause.NotIn Maven / Gradle / Ivy

There is a newer version: 1.8.12
Show newest version
package xin.xihc.jba.sql.clause;

import xin.xihc.jba.sql.KV;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * NOT IN 条件
 *
 * @author Leo.Xi
 * @date 2020/3/5
 * @since 1.0
 **/
public class NotIn extends Clause> {

    public NotIn(String columnName, Collection value) {
        super(columnName, value);
    }

    @Override
    public Collection value() {
        if (this.value != null) {
            Iterator iterator = this.value.iterator();
            LinkedList temp = new LinkedList<>();
            while (iterator.hasNext()) {
                Object next = iterator.next();
                if (next != null && next.getClass().isEnum()) {// 处理枚举
                    temp.add(next.toString());
                } else {
                    temp.add(next);
                }
            }
            return temp;
        }
        return null;
    }

    @Override
    public String operation() {
        return " NOT IN ";
    }

    @Override
    public String toSql(KV kv) {
        String key = kv.add(this.value());
        return this.columnName + this.operation() + "(:" + key + ")";
    }

}