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

org.mybatis.dynamic.sql.SqlBuilder Maven / Gradle / Ivy

The newest version!
/*
 *    Copyright 2016-2024 the original author or authors.
 *
 *    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
 *
 *       https://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 org.mybatis.dynamic.sql;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.DeleteModel;
import org.mybatis.dynamic.sql.insert.BatchInsertDSL;
import org.mybatis.dynamic.sql.insert.GeneralInsertDSL;
import org.mybatis.dynamic.sql.insert.InsertDSL;
import org.mybatis.dynamic.sql.insert.InsertSelectDSL;
import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL;
import org.mybatis.dynamic.sql.select.ColumnSortSpecification;
import org.mybatis.dynamic.sql.select.CountDSL;
import org.mybatis.dynamic.sql.select.HavingDSL;
import org.mybatis.dynamic.sql.select.MultiSelectDSL;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL.FromGatherer;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.SelectModel;
import org.mybatis.dynamic.sql.select.SimpleSortSpecification;
import org.mybatis.dynamic.sql.select.aggregate.Avg;
import org.mybatis.dynamic.sql.select.aggregate.Count;
import org.mybatis.dynamic.sql.select.aggregate.CountAll;
import org.mybatis.dynamic.sql.select.aggregate.CountDistinct;
import org.mybatis.dynamic.sql.select.aggregate.Max;
import org.mybatis.dynamic.sql.select.aggregate.Min;
import org.mybatis.dynamic.sql.select.aggregate.Sum;
import org.mybatis.dynamic.sql.select.caseexpression.SearchedCaseDSL;
import org.mybatis.dynamic.sql.select.caseexpression.SimpleCaseDSL;
import org.mybatis.dynamic.sql.select.function.Add;
import org.mybatis.dynamic.sql.select.function.Cast;
import org.mybatis.dynamic.sql.select.function.Concat;
import org.mybatis.dynamic.sql.select.function.Concatenate;
import org.mybatis.dynamic.sql.select.function.Divide;
import org.mybatis.dynamic.sql.select.function.Lower;
import org.mybatis.dynamic.sql.select.function.Multiply;
import org.mybatis.dynamic.sql.select.function.OperatorFunction;
import org.mybatis.dynamic.sql.select.function.Substring;
import org.mybatis.dynamic.sql.select.function.Subtract;
import org.mybatis.dynamic.sql.select.function.Upper;
import org.mybatis.dynamic.sql.select.join.EqualTo;
import org.mybatis.dynamic.sql.select.join.EqualToValue;
import org.mybatis.dynamic.sql.select.join.JoinCondition;
import org.mybatis.dynamic.sql.select.join.JoinCriterion;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.Buildable;
import org.mybatis.dynamic.sql.where.WhereDSL;
import org.mybatis.dynamic.sql.where.condition.IsBetween;
import org.mybatis.dynamic.sql.where.condition.IsEqualTo;
import org.mybatis.dynamic.sql.where.condition.IsEqualToColumn;
import org.mybatis.dynamic.sql.where.condition.IsEqualToWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThan;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThanColumn;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThanOrEqualTo;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThanOrEqualToColumn;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThanOrEqualToWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsGreaterThanWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsIn;
import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitive;
import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitiveWhenPresent;
import org.mybatis.dynamic.sql.where.condition.IsInWhenPresent;
import org.mybatis.dynamic.sql.where.condition.IsInWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsLessThan;
import org.mybatis.dynamic.sql.where.condition.IsLessThanColumn;
import org.mybatis.dynamic.sql.where.condition.IsLessThanOrEqualTo;
import org.mybatis.dynamic.sql.where.condition.IsLessThanOrEqualToColumn;
import org.mybatis.dynamic.sql.where.condition.IsLessThanOrEqualToWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsLessThanWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsLike;
import org.mybatis.dynamic.sql.where.condition.IsLikeCaseInsensitive;
import org.mybatis.dynamic.sql.where.condition.IsNotBetween;
import org.mybatis.dynamic.sql.where.condition.IsNotEqualTo;
import org.mybatis.dynamic.sql.where.condition.IsNotEqualToColumn;
import org.mybatis.dynamic.sql.where.condition.IsNotEqualToWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsNotIn;
import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitive;
import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitiveWhenPresent;
import org.mybatis.dynamic.sql.where.condition.IsNotInWhenPresent;
import org.mybatis.dynamic.sql.where.condition.IsNotInWithSubselect;
import org.mybatis.dynamic.sql.where.condition.IsNotLike;
import org.mybatis.dynamic.sql.where.condition.IsNotLikeCaseInsensitive;
import org.mybatis.dynamic.sql.where.condition.IsNotNull;
import org.mybatis.dynamic.sql.where.condition.IsNull;

public interface SqlBuilder {

    // statements

    /**
     * Renders as select count(distinct column) from table...
     *
     * @param column
     *            the column to count
     *
     * @return the next step in the DSL
     */
    static CountDSL.FromGatherer countDistinctColumn(BasicColumn column) {
        return CountDSL.countDistinct(column);
    }

    /**
     * Renders as select count(column) from table...
     *
     * @param column
     *            the column to count
     *
     * @return the next step in the DSL
     */
    static CountDSL.FromGatherer countColumn(BasicColumn column) {
        return CountDSL.count(column);
    }

    /**
     * Renders as select count(*) from table...
     *
     * @param table
     *            the table to count
     *
     * @return the next step in the DSL
     */
    static CountDSL countFrom(SqlTable table) {
        return CountDSL.countFrom(table);
    }

    static DeleteDSL deleteFrom(SqlTable table) {
        return DeleteDSL.deleteFrom(table);
    }

    static DeleteDSL deleteFrom(SqlTable table, String tableAlias) {
        return DeleteDSL.deleteFrom(table, tableAlias);
    }

    static  InsertDSL.IntoGatherer insert(T row) {
        return InsertDSL.insert(row);
    }

    /**
     * Insert a Batch of records. The model object is structured to support bulk inserts with JDBC batch support.
     *
     * @param records
     *            records to insert
     * @param 
     *            the type of record to insert
     *
     * @return the next step in the DSL
     */
    @SafeVarargs
    static  BatchInsertDSL.IntoGatherer insertBatch(T... records) {
        return BatchInsertDSL.insert(records);
    }

    /**
     * Insert a Batch of records. The model object is structured to support bulk inserts with JDBC batch support.
     *
     * @param records
     *            records to insert
     * @param 
     *            the type of record to insert
     *
     * @return the next step in the DSL
     */
    static  BatchInsertDSL.IntoGatherer insertBatch(Collection records) {
        return BatchInsertDSL.insert(records);
    }

    /**
     * Insert multiple records in a single statement. The model object is structured as a single insert statement with
     * multiple values clauses. This statement is suitable for use with a small number of records. It is not suitable
     * for large bulk inserts as it is possible to exceed the limit of parameter markers in a prepared statement.
     *
     * 

For large bulk inserts, see {@link SqlBuilder#insertBatch(Object[])} * @param records * records to insert * @param * the type of record to insert * * @return the next step in the DSL */ @SafeVarargs static MultiRowInsertDSL.IntoGatherer insertMultiple(T... records) { return MultiRowInsertDSL.insert(records); } /** * Insert multiple records in a single statement. The model object is structured as a single insert statement with * multiple values clauses. This statement is suitable for use with a small number of records. It is not suitable * for large bulk inserts as it is possible to exceed the limit of parameter markers in a prepared statement. * *

For large bulk inserts, see {@link SqlBuilder#insertBatch(Collection)} * @param records * records to insert * @param * the type of record to insert * * @return the next step in the DSL */ static MultiRowInsertDSL.IntoGatherer insertMultiple(Collection records) { return MultiRowInsertDSL.insert(records); } static InsertIntoNextStep insertInto(SqlTable table) { return new InsertIntoNextStep(table); } static FromGatherer select(BasicColumn... selectList) { return SelectDSL.select(selectList); } static FromGatherer select(Collection selectList) { return SelectDSL.select(selectList); } static FromGatherer selectDistinct(BasicColumn... selectList) { return SelectDSL.selectDistinct(selectList); } static FromGatherer selectDistinct(Collection selectList) { return SelectDSL.selectDistinct(selectList); } static MultiSelectDSL multiSelect(Buildable selectModelBuilder) { return new MultiSelectDSL(selectModelBuilder); } static UpdateDSL update(SqlTable table) { return UpdateDSL.update(table); } static UpdateDSL update(SqlTable table, String tableAlias) { return UpdateDSL.update(table, tableAlias); } static WhereDSL.StandaloneWhereFinisher where() { return new WhereDSL().where(); } static WhereDSL.StandaloneWhereFinisher where(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return new WhereDSL().where(column, condition, subCriteria); } static WhereDSL.StandaloneWhereFinisher where(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return new WhereDSL().where(initialCriterion, subCriteria); } static WhereDSL.StandaloneWhereFinisher where(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) { return new WhereDSL().where(existsPredicate, subCriteria); } static HavingDSL.StandaloneHavingFinisher having(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return new HavingDSL().having(column, condition, subCriteria); } static HavingDSL.StandaloneHavingFinisher having(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return new HavingDSL().having(initialCriterion, subCriteria); } // where condition connectors static CriteriaGroup group(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return group(column, condition, Arrays.asList(subCriteria)); } static CriteriaGroup group(BindableColumn column, VisitableCondition condition, List subCriteria) { return new CriteriaGroup.Builder() .withInitialCriterion(new ColumnAndConditionCriterion.Builder().withColumn(column) .withCondition(condition).build()) .withSubCriteria(subCriteria) .build(); } static CriteriaGroup group(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) { return group(existsPredicate, Arrays.asList(subCriteria)); } static CriteriaGroup group(ExistsPredicate existsPredicate, List subCriteria) { return new CriteriaGroup.Builder() .withInitialCriterion(new ExistsCriterion.Builder() .withExistsPredicate(existsPredicate).build()) .withSubCriteria(subCriteria) .build(); } static CriteriaGroup group(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return group(initialCriterion, Arrays.asList(subCriteria)); } static CriteriaGroup group(SqlCriterion initialCriterion, List subCriteria) { return new CriteriaGroup.Builder() .withInitialCriterion(initialCriterion) .withSubCriteria(subCriteria) .build(); } static CriteriaGroup group(List subCriteria) { return new CriteriaGroup.Builder() .withSubCriteria(subCriteria) .build(); } static NotCriterion not(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return not(column, condition, Arrays.asList(subCriteria)); } static NotCriterion not(BindableColumn column, VisitableCondition condition, List subCriteria) { return new NotCriterion.Builder() .withInitialCriterion(new ColumnAndConditionCriterion.Builder().withColumn(column) .withCondition(condition).build()) .withSubCriteria(subCriteria) .build(); } static NotCriterion not(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) { return not(existsPredicate, Arrays.asList(subCriteria)); } static NotCriterion not(ExistsPredicate existsPredicate, List subCriteria) { return new NotCriterion.Builder() .withInitialCriterion(new ExistsCriterion.Builder() .withExistsPredicate(existsPredicate).build()) .withSubCriteria(subCriteria) .build(); } static NotCriterion not(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return not(initialCriterion, Arrays.asList(subCriteria)); } static NotCriterion not(SqlCriterion initialCriterion, List subCriteria) { return new NotCriterion.Builder() .withInitialCriterion(initialCriterion) .withSubCriteria(subCriteria) .build(); } static NotCriterion not(List subCriteria) { return new NotCriterion.Builder() .withSubCriteria(subCriteria) .build(); } static AndOrCriteriaGroup or(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withInitialCriterion(ColumnAndConditionCriterion.withColumn(column) .withCondition(condition) .build()) .withConnector("or") //$NON-NLS-1$ .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup or(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withInitialCriterion(new ExistsCriterion.Builder() .withExistsPredicate(existsPredicate).build()) .withConnector("or") //$NON-NLS-1$ .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup or(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withConnector("or") //$NON-NLS-1$ .withInitialCriterion(initialCriterion) .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup or(List subCriteria) { return new AndOrCriteriaGroup.Builder() .withConnector("or") //$NON-NLS-1$ .withSubCriteria(subCriteria) .build(); } static AndOrCriteriaGroup and(BindableColumn column, VisitableCondition condition, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withInitialCriterion(ColumnAndConditionCriterion.withColumn(column) .withCondition(condition) .build()) .withConnector("and") //$NON-NLS-1$ .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup and(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withInitialCriterion(new ExistsCriterion.Builder() .withExistsPredicate(existsPredicate).build()) .withConnector("and") //$NON-NLS-1$ .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup and(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) { return new AndOrCriteriaGroup.Builder() .withConnector("and") //$NON-NLS-1$ .withInitialCriterion(initialCriterion) .withSubCriteria(Arrays.asList(subCriteria)) .build(); } static AndOrCriteriaGroup and(List subCriteria) { return new AndOrCriteriaGroup.Builder() .withConnector("and") //$NON-NLS-1$ .withSubCriteria(subCriteria) .build(); } // join support static JoinCriterion and(BindableColumn joinColumn, JoinCondition joinCondition) { return new JoinCriterion.Builder() .withConnector("and") //$NON-NLS-1$ .withJoinColumn(joinColumn) .withJoinCondition(joinCondition) .build(); } static JoinCriterion on(BindableColumn joinColumn, JoinCondition joinCondition) { return new JoinCriterion.Builder() .withConnector("on") //$NON-NLS-1$ .withJoinColumn(joinColumn) .withJoinCondition(joinCondition) .build(); } // case expressions @SuppressWarnings("java:S100") static SimpleCaseDSL case_(BindableColumn column) { return SimpleCaseDSL.simpleCase(column); } @SuppressWarnings("java:S100") static SearchedCaseDSL case_() { return SearchedCaseDSL.searchedCase(); } static EqualTo equalTo(BindableColumn column) { return new EqualTo<>(column); } static EqualToValue equalTo(T value) { return new EqualToValue<>(value); } // aggregate support static CountAll count() { return new CountAll(); } static Count count(BasicColumn column) { return Count.of(column); } static CountDistinct countDistinct(BasicColumn column) { return CountDistinct.of(column); } static Max max(BindableColumn column) { return Max.of(column); } static Min min(BindableColumn column) { return Min.of(column); } static Avg avg(BindableColumn column) { return Avg.of(column); } static Sum sum(BindableColumn column) { return Sum.of(column); } static Sum sum(BindableColumn column, VisitableCondition condition) { return Sum.of(column, condition); } // constants static Constant constant(String constant) { return Constant.of(constant); } static StringConstant stringConstant(String constant) { return StringConstant.of(constant); } static BoundValue value(T value) { return BoundValue.of(value); } // functions static Add add(BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return Add.of(firstColumn, secondColumn, subsequentColumns); } static Divide divide(BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return Divide.of(firstColumn, secondColumn, subsequentColumns); } static Multiply multiply(BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return Multiply.of(firstColumn, secondColumn, subsequentColumns); } static Subtract subtract(BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return Subtract.of(firstColumn, secondColumn, subsequentColumns); } static CastFinisher cast(String value) { return cast(stringConstant(value)); } static CastFinisher cast(Double value) { return cast(constant(value.toString())); } static CastFinisher cast(BasicColumn column) { return new CastFinisher(column); } /** * Concatenate function that renders as "(x || y || z)". This will not work on some * databases like MySql. In that case, use {@link SqlBuilder#concat(BindableColumn, BasicColumn...)} * * @param firstColumn first column * @param secondColumn second column * @param subsequentColumns subsequent columns * @param type of column * @return a Concatenate instance */ static Concatenate concatenate(BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return Concatenate.concatenate(firstColumn, secondColumn, subsequentColumns); } /** * Concatenate function that renders as "concat(x, y, z)". This version works on more databases * than {@link SqlBuilder#concatenate(BindableColumn, BasicColumn, BasicColumn...)} * * @param firstColumn first column * @param subsequentColumns subsequent columns * @param type of column * @return a Concat instance */ static Concat concat(BindableColumn firstColumn, BasicColumn... subsequentColumns) { return Concat.concat(firstColumn, subsequentColumns); } static OperatorFunction applyOperator(String operator, BindableColumn firstColumn, BasicColumn secondColumn, BasicColumn... subsequentColumns) { return OperatorFunction.of(operator, firstColumn, secondColumn, subsequentColumns); } static Lower lower(BindableColumn column) { return Lower.of(column); } static Substring substring(BindableColumn column, int offset, int length) { return Substring.of(column, offset, length); } static Upper upper(BindableColumn column) { return Upper.of(column); } // conditions for all data types static ExistsPredicate exists(Buildable selectModelBuilder) { return ExistsPredicate.exists(selectModelBuilder); } static ExistsPredicate notExists(Buildable selectModelBuilder) { return ExistsPredicate.notExists(selectModelBuilder); } static IsNull isNull() { return new IsNull<>(); } static IsNotNull isNotNull() { return new IsNotNull<>(); } static IsEqualTo isEqualTo(T value) { return IsEqualTo.of(value); } static IsEqualTo isEqualTo(Supplier valueSupplier) { return isEqualTo(valueSupplier.get()); } static IsEqualToWithSubselect isEqualTo(Buildable selectModelBuilder) { return IsEqualToWithSubselect.of(selectModelBuilder); } static IsEqualToColumn isEqualTo(BasicColumn column) { return IsEqualToColumn.of(column); } static IsEqualTo isEqualToWhenPresent(T value) { return IsEqualTo.of(value).filter(Objects::nonNull); } static IsEqualTo isEqualToWhenPresent(Supplier valueSupplier) { return isEqualToWhenPresent(valueSupplier.get()); } static IsNotEqualTo isNotEqualTo(T value) { return IsNotEqualTo.of(value); } static IsNotEqualTo isNotEqualTo(Supplier valueSupplier) { return isNotEqualTo(valueSupplier.get()); } static IsNotEqualToWithSubselect isNotEqualTo(Buildable selectModelBuilder) { return IsNotEqualToWithSubselect.of(selectModelBuilder); } static IsNotEqualToColumn isNotEqualTo(BasicColumn column) { return IsNotEqualToColumn.of(column); } static IsNotEqualTo isNotEqualToWhenPresent(T value) { return IsNotEqualTo.of(value).filter(Objects::nonNull); } static IsNotEqualTo isNotEqualToWhenPresent(Supplier valueSupplier) { return isNotEqualToWhenPresent(valueSupplier.get()); } static IsGreaterThan isGreaterThan(T value) { return IsGreaterThan.of(value); } static IsGreaterThan isGreaterThan(Supplier valueSupplier) { return isGreaterThan(valueSupplier.get()); } static IsGreaterThanWithSubselect isGreaterThan(Buildable selectModelBuilder) { return IsGreaterThanWithSubselect.of(selectModelBuilder); } static IsGreaterThanColumn isGreaterThan(BasicColumn column) { return IsGreaterThanColumn.of(column); } static IsGreaterThan isGreaterThanWhenPresent(T value) { return IsGreaterThan.of(value).filter(Objects::nonNull); } static IsGreaterThan isGreaterThanWhenPresent(Supplier valueSupplier) { return isGreaterThanWhenPresent(valueSupplier.get()); } static IsGreaterThanOrEqualTo isGreaterThanOrEqualTo(T value) { return IsGreaterThanOrEqualTo.of(value); } static IsGreaterThanOrEqualTo isGreaterThanOrEqualTo(Supplier valueSupplier) { return isGreaterThanOrEqualTo(valueSupplier.get()); } static IsGreaterThanOrEqualToWithSubselect isGreaterThanOrEqualTo( Buildable selectModelBuilder) { return IsGreaterThanOrEqualToWithSubselect.of(selectModelBuilder); } static IsGreaterThanOrEqualToColumn isGreaterThanOrEqualTo(BasicColumn column) { return IsGreaterThanOrEqualToColumn.of(column); } static IsGreaterThanOrEqualTo isGreaterThanOrEqualToWhenPresent(T value) { return IsGreaterThanOrEqualTo.of(value).filter(Objects::nonNull); } static IsGreaterThanOrEqualTo isGreaterThanOrEqualToWhenPresent(Supplier valueSupplier) { return isGreaterThanOrEqualToWhenPresent(valueSupplier.get()); } static IsLessThan isLessThan(T value) { return IsLessThan.of(value); } static IsLessThan isLessThan(Supplier valueSupplier) { return isLessThan(valueSupplier.get()); } static IsLessThanWithSubselect isLessThan(Buildable selectModelBuilder) { return IsLessThanWithSubselect.of(selectModelBuilder); } static IsLessThanColumn isLessThan(BasicColumn column) { return IsLessThanColumn.of(column); } static IsLessThan isLessThanWhenPresent(T value) { return IsLessThan.of(value).filter(Objects::nonNull); } static IsLessThan isLessThanWhenPresent(Supplier valueSupplier) { return isLessThanWhenPresent(valueSupplier.get()); } static IsLessThanOrEqualTo isLessThanOrEqualTo(T value) { return IsLessThanOrEqualTo.of(value); } static IsLessThanOrEqualTo isLessThanOrEqualTo(Supplier valueSupplier) { return isLessThanOrEqualTo(valueSupplier.get()); } static IsLessThanOrEqualToWithSubselect isLessThanOrEqualTo(Buildable selectModelBuilder) { return IsLessThanOrEqualToWithSubselect.of(selectModelBuilder); } static IsLessThanOrEqualToColumn isLessThanOrEqualTo(BasicColumn column) { return IsLessThanOrEqualToColumn.of(column); } static IsLessThanOrEqualTo isLessThanOrEqualToWhenPresent(T value) { return IsLessThanOrEqualTo.of(value).filter(Objects::nonNull); } static IsLessThanOrEqualTo isLessThanOrEqualToWhenPresent(Supplier valueSupplier) { return isLessThanOrEqualToWhenPresent(valueSupplier.get()); } @SafeVarargs static IsIn isIn(T... values) { return IsIn.of(values); } static IsIn isIn(Collection values) { return IsIn.of(values); } static IsInWithSubselect isIn(Buildable selectModelBuilder) { return IsInWithSubselect.of(selectModelBuilder); } @SafeVarargs static IsInWhenPresent isInWhenPresent(T... values) { return IsInWhenPresent.of(values); } static IsInWhenPresent isInWhenPresent(Collection values) { return values == null ? IsInWhenPresent.empty() : IsInWhenPresent.of(values); } @SafeVarargs static IsNotIn isNotIn(T... values) { return IsNotIn.of(values); } static IsNotIn isNotIn(Collection values) { return IsNotIn.of(values); } static IsNotInWithSubselect isNotIn(Buildable selectModelBuilder) { return IsNotInWithSubselect.of(selectModelBuilder); } @SafeVarargs static IsNotInWhenPresent isNotInWhenPresent(T... values) { return IsNotInWhenPresent.of(values); } static IsNotInWhenPresent isNotInWhenPresent(Collection values) { return values == null ? IsNotInWhenPresent.empty() : IsNotInWhenPresent.of(values); } static IsBetween.Builder isBetween(T value1) { return IsBetween.isBetween(value1); } static IsBetween.Builder isBetween(Supplier valueSupplier1) { return isBetween(valueSupplier1.get()); } static IsBetween.WhenPresentBuilder isBetweenWhenPresent(T value1) { return IsBetween.isBetweenWhenPresent(value1); } static IsBetween.WhenPresentBuilder isBetweenWhenPresent(Supplier valueSupplier1) { return isBetweenWhenPresent(valueSupplier1.get()); } static IsNotBetween.Builder isNotBetween(T value1) { return IsNotBetween.isNotBetween(value1); } static IsNotBetween.Builder isNotBetween(Supplier valueSupplier1) { return isNotBetween(valueSupplier1.get()); } static IsNotBetween.WhenPresentBuilder isNotBetweenWhenPresent(T value1) { return IsNotBetween.isNotBetweenWhenPresent(value1); } static IsNotBetween.WhenPresentBuilder isNotBetweenWhenPresent(Supplier valueSupplier1) { return isNotBetweenWhenPresent(valueSupplier1.get()); } // for string columns, but generic for columns with type handlers static IsLike isLike(T value) { return IsLike.of(value); } static IsLike isLike(Supplier valueSupplier) { return isLike(valueSupplier.get()); } static IsLike isLikeWhenPresent(T value) { return IsLike.of(value).filter(Objects::nonNull); } static IsLike isLikeWhenPresent(Supplier valueSupplier) { return isLikeWhenPresent(valueSupplier.get()); } static IsNotLike isNotLike(T value) { return IsNotLike.of(value); } static IsNotLike isNotLike(Supplier valueSupplier) { return isNotLike(valueSupplier.get()); } static IsNotLike isNotLikeWhenPresent(T value) { return IsNotLike.of(value).filter(Objects::nonNull); } static IsNotLike isNotLikeWhenPresent(Supplier valueSupplier) { return isNotLikeWhenPresent(valueSupplier.get()); } // shortcuts for booleans static IsEqualTo isTrue() { return isEqualTo(Boolean.TRUE); } static IsEqualTo isFalse() { return isEqualTo(Boolean.FALSE); } // conditions for strings only static IsLikeCaseInsensitive isLikeCaseInsensitive(String value) { return IsLikeCaseInsensitive.of(value); } static IsLikeCaseInsensitive isLikeCaseInsensitive(Supplier valueSupplier) { return isLikeCaseInsensitive(valueSupplier.get()); } static IsLikeCaseInsensitive isLikeCaseInsensitiveWhenPresent(String value) { return IsLikeCaseInsensitive.of(value).filter(Objects::nonNull); } static IsLikeCaseInsensitive isLikeCaseInsensitiveWhenPresent(Supplier valueSupplier) { return isLikeCaseInsensitiveWhenPresent(valueSupplier.get()); } static IsNotLikeCaseInsensitive isNotLikeCaseInsensitive(String value) { return IsNotLikeCaseInsensitive.of(value); } static IsNotLikeCaseInsensitive isNotLikeCaseInsensitive(Supplier valueSupplier) { return isNotLikeCaseInsensitive(valueSupplier.get()); } static IsNotLikeCaseInsensitive isNotLikeCaseInsensitiveWhenPresent(String value) { return IsNotLikeCaseInsensitive.of(value).filter(Objects::nonNull); } static IsNotLikeCaseInsensitive isNotLikeCaseInsensitiveWhenPresent(Supplier valueSupplier) { return isNotLikeCaseInsensitiveWhenPresent(valueSupplier.get()); } static IsInCaseInsensitive isInCaseInsensitive(String... values) { return IsInCaseInsensitive.of(values); } static IsInCaseInsensitive isInCaseInsensitive(Collection values) { return IsInCaseInsensitive.of(values); } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(String... values) { return IsInCaseInsensitiveWhenPresent.of(values); } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(Collection values) { return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values); } static IsNotInCaseInsensitive isNotInCaseInsensitive(String... values) { return IsNotInCaseInsensitive.of(values); } static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection values) { return IsNotInCaseInsensitive.of(values); } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(String... values) { return IsNotInCaseInsensitiveWhenPresent.of(values); } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(Collection values) { return values == null ? IsNotInCaseInsensitiveWhenPresent.empty() : IsNotInCaseInsensitiveWhenPresent.of(values); } // order by support /** * Creates a sort specification based on a String. This is useful when a column has been * aliased in the select list. For example: * *

     *     select(foo.as("bar"))
     *     .from(baz)
     *     .orderBy(sortColumn("bar"))
     * 
* * @param name the string to use as a sort specification * @return a sort specification */ static SortSpecification sortColumn(String name) { return SimpleSortSpecification.of(name); } /** * Creates a sort specification based on a column and a table alias. This can be useful in a join * where the desired sort order is based on a column not in the select list. This will likely * fail in union queries depending on database support. * * @param tableAlias the table alias * @param column the column * @return a sort specification */ static SortSpecification sortColumn(String tableAlias, SqlColumn column) { return new ColumnSortSpecification(tableAlias, column); } class InsertIntoNextStep { private final SqlTable table; private InsertIntoNextStep(SqlTable table) { this.table = Objects.requireNonNull(table); } public InsertSelectDSL withSelectStatement(Buildable selectModelBuilder) { return InsertSelectDSL.insertInto(table) .withSelectStatement(selectModelBuilder); } public InsertSelectDSL.SelectGatherer withColumnList(SqlColumn... columns) { return InsertSelectDSL.insertInto(table) .withColumnList(columns); } public InsertSelectDSL.SelectGatherer withColumnList(List> columns) { return InsertSelectDSL.insertInto(table) .withColumnList(columns); } public GeneralInsertDSL.SetClauseFinisher set(SqlColumn column) { return GeneralInsertDSL.insertInto(table) .set(column); } } class CastFinisher { private final BasicColumn column; public CastFinisher(BasicColumn column) { this.column = column; } public Cast as(String targetType) { return new Cast.Builder() .withColumn(column) .withTargetType(targetType) .build(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy