SelectBuilder.java

  1. /*
  2.  *    Copyright 2009-2022 the original author or authors.
  3.  *
  4.  *    Licensed under the Apache License, Version 2.0 (the "License");
  5.  *    you may not use this file except in compliance with the License.
  6.  *    You may obtain a copy of the License at
  7.  *
  8.  *       https://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *    Unless required by applicable law or agreed to in writing, software
  11.  *    distributed under the License is distributed on an "AS IS" BASIS,
  12.  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *    See the License for the specific language governing permissions and
  14.  *    limitations under the License.
  15.  */
  16. package org.apache.ibatis.jdbc;

  17. /**
  18.  * @deprecated Use the {@link SQL} Class
  19.  *
  20.  * @author Clinton Begin
  21.  */
  22. @Deprecated
  23. public class SelectBuilder {

  24.   private static final ThreadLocal<SQL> localSQL = new ThreadLocal<>();

  25.   static {
  26.     BEGIN();
  27.   }

  28.   private SelectBuilder() {
  29.     // Prevent Instantiation
  30.   }

  31.   public static void BEGIN() {
  32.     RESET();
  33.   }

  34.   public static void RESET() {
  35.     localSQL.set(new SQL());
  36.   }

  37.   public static void SELECT(String columns) {
  38.     sql().SELECT(columns);
  39.   }

  40.   public static void SELECT_DISTINCT(String columns) {
  41.     sql().SELECT_DISTINCT(columns);
  42.   }

  43.   public static void FROM(String table) {
  44.     sql().FROM(table);
  45.   }

  46.   public static void JOIN(String join) {
  47.     sql().JOIN(join);
  48.   }

  49.   public static void INNER_JOIN(String join) {
  50.     sql().INNER_JOIN(join);
  51.   }

  52.   public static void LEFT_OUTER_JOIN(String join) {
  53.     sql().LEFT_OUTER_JOIN(join);
  54.   }

  55.   public static void RIGHT_OUTER_JOIN(String join) {
  56.     sql().RIGHT_OUTER_JOIN(join);
  57.   }

  58.   public static void OUTER_JOIN(String join) {
  59.     sql().OUTER_JOIN(join);
  60.   }

  61.   public static void WHERE(String conditions) {
  62.     sql().WHERE(conditions);
  63.   }

  64.   public static void OR() {
  65.     sql().OR();
  66.   }

  67.   public static void AND() {
  68.     sql().AND();
  69.   }

  70.   public static void GROUP_BY(String columns) {
  71.     sql().GROUP_BY(columns);
  72.   }

  73.   public static void HAVING(String conditions) {
  74.     sql().HAVING(conditions);
  75.   }

  76.   public static void ORDER_BY(String columns) {
  77.     sql().ORDER_BY(columns);
  78.   }

  79.   public static String SQL() {
  80.     try {
  81.       return sql().toString();
  82.     } finally {
  83.       RESET();
  84.     }
  85.   }

  86.   private static SQL sql() {
  87.     return localSQL.get();
  88.   }

  89. }