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

com.github.chengyuxing.sql.dsl.clause.condition.BetweenCondition Maven / Gradle / Ivy

Go to download

Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql file.

There is a newer version: 9.0.2
Show newest version
package com.github.chengyuxing.sql.dsl.clause.condition;

import com.github.chengyuxing.common.tuple.Pair;
import com.github.chengyuxing.sql.dsl.types.Logic;
import com.github.chengyuxing.sql.dsl.types.StandardOperator;

import java.util.HashMap;
import java.util.Map;

public class BetweenCondition extends Condition {
    public BetweenCondition(String column, StandardOperator operator, Pair value) {
        super(column, operator, value);
    }

    public BetweenCondition(String column, StandardOperator operator, Object value, String valueKey) {
        super(column, operator, value, valueKey);
    }

    public Pair> buildStatement(int index, char namedParamPrefix) {
        //noinspection unchecked
        Pair pair = (Pair) value;
        String a = valueKey + "__" + index + "_0";
        String b = valueKey + "__" + index + "_1";
        String statement = column + operator.padWithSpace() + namedParamPrefix + a + Logic.AND.padWithSpace() + namedParamPrefix + b;
        Map params = new HashMap<>();
        params.put(a, pair.getItem1());
        params.put(b, pair.getItem2());
        return Pair.of(statement, params);
    }
}