View Javadoc
1   /*
2    *    Copyright 2016-2024 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.mybatis.dynamic.sql.configuration;
17  
18  import org.mybatis.dynamic.sql.exception.NonRenderingWhereClauseException;
19  
20  /**
21   * This class can be used to change some behaviors of the framework. Every configurable statement
22   * contains a unique instance of this class, so changes here will only impact a single statement.
23   * If you intend to change the behavior for all statements, use the {@link GlobalConfiguration}.
24   * Initial values for this class in each statement are set from the {@link GlobalConfiguration}.
25   * Configurable behaviors are detailed below:
26   *
27   * <dl>
28   *     <dt>nonRenderingWhereClauseAllowed</dt>
29   *     <dd>If false (default), the framework will throw a {@link NonRenderingWhereClauseException}
30   *         if a where clause is specified in the statement, but it fails to render because all
31   *         optional conditions do not render. For example, if an "in" condition specifies an
32   *         empty list of values. If no criteria are specified in a where clause, the framework
33   *         assumes that no where clause was intended and will not throw an exception.
34   *     </dd>
35   * </dl>
36   *
37   * @see GlobalConfiguration
38   *
39   * @since 1.4.1
40   *
41   * @author Jeff Butler
42   */
43  public class StatementConfiguration {
44      private boolean isNonRenderingWhereClauseAllowed =
45              GlobalContext.getConfiguration().isIsNonRenderingWhereClauseAllowed();
46  
47      public boolean isNonRenderingWhereClauseAllowed() {
48          return isNonRenderingWhereClauseAllowed;
49      }
50  
51      public StatementConfiguration setNonRenderingWhereClauseAllowed(boolean nonRenderingWhereClauseAllowed) {
52          isNonRenderingWhereClauseAllowed = nonRenderingWhereClauseAllowed;
53          return this;
54      }
55  }