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

shz.orm.sql.builder.SqlBuilder Maven / Gradle / Ivy

The newest version!
package shz.orm.sql.builder;

import shz.core.model.PageInfo;
import shz.core.model.Range;
import shz.orm.Tnp;
import shz.orm.sql.ValueType;
import shz.orm.sql.handler.SqlHandler;

import java.util.Collection;
import java.util.List;

public final class SqlBuilder {
    final SqlHandler handler;
    final StringBuilder sb;

    public SqlBuilder(SqlHandler handler, int capacity) {
        this.handler = handler;
        this.sb = new StringBuilder(capacity);
    }

    public SqlBuilder(SqlHandler handler) {
        this(handler, 70);
    }

    public SqlBuilder append(Object obj) {
        sb.append(obj);
        return this;
    }

    public SqlBuilder append(String str) {
        sb.append(str);
        return this;
    }

    public SqlBuilder append(CharSequence s) {
        sb.append(s);
        return this;
    }

    public SqlBuilder append(boolean b) {
        sb.append(b);
        return this;
    }

    public SqlBuilder append(char c) {
        sb.append(c);
        return this;
    }

    public SqlBuilder append(int i) {
        sb.append(i);
        return this;
    }

    public SqlBuilder append(long lng) {
        sb.append(lng);
        return this;
    }

    public SqlBuilder append(float f) {
        sb.append(f);
        return this;
    }

    public SqlBuilder append(double d) {
        sb.append(d);
        return this;
    }

    public String build() {
        return sb.toString();
    }

    ////////////////////////////////////////////////////////////////////////////
    public SqlBuilder placeholder() {
        handler.placeholder(sb);
        return this;
    }

    public SqlBuilder placeholder(int n, CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
        handler.placeholder(sb, n, delimiter, prefix, suffix);
        return this;
    }

    public SqlBuilder escape(Object val) {
        handler.escape(sb, val);
        return this;
    }

    public SqlBuilder wrap(Object val) {
        handler.wrap(sb, val);
        return this;
    }

    public String insert(Tnp tnp, List columns, List values, ValueType type, boolean ignore) {
        handler.insert(sb, tnp, columns, values, type, ignore);
        return build();
    }

    public SqlBuilder update(Tnp tnp, List columns, List values, ValueType type, boolean ignore) {
        handler.update(sb, tnp, columns, values, type, ignore);
        return this;
    }

    public SqlBuilder delete(Tnp tnp) {
        handler.delete(sb, tnp);
        return this;
    }

    public SqlBuilder select(Tnp tnp, List columns) {
        handler.select(sb, tnp, columns);
        return this;
    }

    public SqlBuilder where() {
        handler.where(sb);
        return this;
    }

    public SqlBuilder groupBy() {
        handler.groupBy(sb);
        return this;
    }

    public SqlBuilder having() {
        handler.having(sb);
        return this;
    }

    public SqlBuilder orderBy() {
        handler.orderBy(sb);
        return this;
    }

    public SqlBuilder asc() {
        handler.asc(sb);
        return this;
    }

    public SqlBuilder desc() {
        handler.desc(sb);
        return this;
    }

    public SqlBuilder count(Tnp tnp) {
        handler.count(sb, tnp);
        return this;
    }

    public String page(PageInfo pageInfo) {
        handler.page(sb, pageInfo);
        return build();
    }

    public String count() {
        handler.count(sb);
        return build();
    }

    public SqlBuilder isNull() {
        handler.isNull(sb);
        return this;
    }

    public SqlBuilder isNotNull() {
        handler.isNotNull(sb);
        return this;
    }

    public SqlBuilder eq(Object value, ValueType type) {
        handler.eq(sb, value, type);
        return this;
    }

    public SqlBuilder eq(Object value) {
        handler.eq(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder eq() {
        handler.eq(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder neq(Object value, ValueType type) {
        handler.neq(sb, value, type);
        return this;
    }

    public SqlBuilder neq(Object value) {
        handler.neq(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder neq() {
        handler.neq(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder gt(Object value, ValueType type) {
        handler.gt(sb, value, type);
        return this;
    }

    public SqlBuilder gt(Object value) {
        handler.gt(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder gt() {
        handler.gt(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder ge(Object value, ValueType type) {
        handler.ge(sb, value, type);
        return this;
    }

    public SqlBuilder ge(Object value) {
        handler.ge(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder ge() {
        handler.ge(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder lt(Object value, ValueType type) {
        handler.lt(sb, value, type);
        return this;
    }

    public SqlBuilder lt(Object value) {
        handler.lt(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder lt() {
        handler.lt(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder le(Object value, ValueType type) {
        handler.le(sb, value, type);
        return this;
    }

    public SqlBuilder le(Object value) {
        handler.le(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder le() {
        handler.le(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder between(Range range, ValueType type) {
        handler.between(sb, range, type);
        return this;
    }

    public SqlBuilder between() {
        handler.between(sb);
        return this;
    }

    public SqlBuilder in(Collection collection, ValueType type) {
        handler.in(sb, collection, type);
        return this;
    }

    public SqlBuilder in(int n) {
        handler.in(sb, n);
        return this;
    }

    public SqlBuilder notIn(Collection collection, ValueType type) {
        handler.notIn(sb, collection, type);
        return this;
    }

    public SqlBuilder notIn(int n) {
        handler.notIn(sb, n);
        return this;
    }

    public SqlBuilder like(Object value, ValueType type) {
        handler.like(sb, value, type);
        return this;
    }

    public SqlBuilder like(Object value) {
        handler.like(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder like() {
        handler.like(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder likeLeft(Object value, ValueType type) {
        handler.likeLeft(sb, value, type);
        return this;
    }

    public SqlBuilder likeLeft(Object value) {
        handler.likeLeft(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder likeLeft() {
        handler.likeLeft(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder likeRight(Object value, ValueType type) {
        handler.likeRight(sb, value, type);
        return this;
    }

    public SqlBuilder likeRight(Object value) {
        handler.likeRight(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder likeRight() {
        handler.likeRight(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder notLike(Object value, ValueType type) {
        handler.notLike(sb, value, type);
        return this;
    }

    public SqlBuilder notLike(Object value) {
        handler.notLike(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder notLike() {
        handler.notLike(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder notLikeLeft(Object value, ValueType type) {
        handler.notLikeLeft(sb, value, type);
        return this;
    }

    public SqlBuilder notLikeLeft(Object value) {
        handler.notLikeLeft(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder notLikeLeft() {
        handler.notLikeLeft(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder notLikeRight(Object value, ValueType type) {
        handler.notLikeRight(sb, value, type);
        return this;
    }

    public SqlBuilder notLikeRight(Object value) {
        handler.notLikeRight(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder notLikeRight() {
        handler.notLikeRight(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder regexp(Object value, ValueType type) {
        handler.regexp(sb, value, type);
        return this;
    }

    public SqlBuilder regexp(Object value) {
        handler.regexp(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder regexp() {
        handler.regexp(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    public SqlBuilder notRegexp(Object value, ValueType type) {
        handler.notRegexp(sb, value, type);
        return this;
    }

    public SqlBuilder notRegexp(Object value) {
        handler.notRegexp(sb, value, ValueType.NORMAL);
        return this;
    }

    public SqlBuilder notRegexp() {
        handler.notRegexp(sb, null, ValueType.PLACEHOLDER);
        return this;
    }

    //////////////////////////////////////////////////////symbol
    public SqlBuilder and() {
        sb.append(" AND ");
        return this;
    }

    public SqlBuilder or() {
        sb.append(" OR ");
        return this;
    }

    public SqlBuilder space() {
        sb.append(' ');
        return this;
    }

    public SqlBuilder begin() {
        sb.append('(');
        return this;
    }

    public SqlBuilder close() {
        sb.append(')');
        return this;
    }

    public SqlBuilder comma() {
        sb.append(',');
        return this;
    }

    public SqlBuilder dot() {
        sb.append('.');
        return this;
    }

    public SqlBuilder plus() {
        sb.append('+');
        return this;
    }

    public SqlBuilder minus() {
        sb.append('-');
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy