Options.java

  1. /*
  2.  *    Copyright 2009-2021 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.  *       http://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.annotations;

  17. import java.lang.annotation.Documented;
  18. import java.lang.annotation.ElementType;
  19. import java.lang.annotation.Repeatable;
  20. import java.lang.annotation.Retention;
  21. import java.lang.annotation.RetentionPolicy;
  22. import java.lang.annotation.Target;

  23. import org.apache.ibatis.mapping.ResultSetType;
  24. import org.apache.ibatis.mapping.StatementType;

  25. /**
  26.  * The annotation that specify options for customizing default behaviors.
  27.  *
  28.  * <p>
  29.  * <b>How to use:</b>
  30.  *
  31.  * <pre>
  32.  * public interface UserMapper {
  33.  *   &#064;Options(useGeneratedKeys = true, keyProperty = "id")
  34.  *   &#064;Insert("INSERT INTO users (name) VALUES(#{name})")
  35.  *   boolean insert(User user);
  36.  * }
  37.  * </pre>
  38.  *
  39.  * @author Clinton Begin
  40.  */
  41. @Documented
  42. @Retention(RetentionPolicy.RUNTIME)
  43. @Target(ElementType.METHOD)
  44. @Repeatable(Options.List.class)
  45. public @interface Options {
  46.   /**
  47.    * The options for the {@link Options#flushCache()}.
  48.    * The default is {@link FlushCachePolicy#DEFAULT}
  49.    */
  50.   enum FlushCachePolicy {
  51.     /** <code>false</code> for select statement; <code>true</code> for insert/update/delete statement. */
  52.     DEFAULT,
  53.     /** Flushes cache regardless of the statement type. */
  54.     TRUE,
  55.     /** Does not flush cache regardless of the statement type. */
  56.     FALSE
  57.   }

  58.   /**
  59.    * Returns whether use the 2nd cache feature if assigned the cache.
  60.    *
  61.    * @return {@code true} if use; {@code false} if otherwise
  62.    */
  63.   boolean useCache() default true;

  64.   /**
  65.    * Returns the 2nd cache flush strategy.
  66.    *
  67.    * @return the 2nd cache flush strategy
  68.    */
  69.   FlushCachePolicy flushCache() default FlushCachePolicy.DEFAULT;

  70.   /**
  71.    * Returns the result set type.
  72.    *
  73.    * @return the result set type
  74.    */
  75.   ResultSetType resultSetType() default ResultSetType.DEFAULT;

  76.   /**
  77.    * Return the statement type.
  78.    *
  79.    * @return the statement type
  80.    */
  81.   StatementType statementType() default StatementType.PREPARED;

  82.   /**
  83.    * Returns the fetch size.
  84.    *
  85.    * @return the fetch size
  86.    */
  87.   int fetchSize() default -1;

  88.   /**
  89.    * Returns the statement timeout.
  90.    *
  91.    * @return the statement timeout
  92.    */
  93.   int timeout() default -1;

  94.   /**
  95.    * Returns whether use the generated keys feature supported by JDBC 3.0
  96.    *
  97.    * @return {@code true} if use; {@code false} if otherwise
  98.    */
  99.   boolean useGeneratedKeys() default false;

  100.   /**
  101.    * Returns property names that holds a key value.
  102.    * <p>
  103.    * If you specify multiple property, please separate using comma(',').
  104.    * </p>
  105.    *
  106.    * @return property names that separate with comma(',')
  107.    */
  108.   String keyProperty() default "";

  109.   /**
  110.    * Returns column names that retrieves a key value.
  111.    * <p>
  112.    * If you specify multiple column, please separate using comma(',').
  113.    * </p>
  114.    *
  115.    * @return column names that separate with comma(',')
  116.    */
  117.   String keyColumn() default "";

  118.   /**
  119.    * Returns result set names.
  120.    * <p>
  121.    * If you specify multiple result set, please separate using comma(',').
  122.    * </p>
  123.    *
  124.    * @return result set names that separate with comma(',')
  125.    */
  126.   String resultSets() default "";

  127.   /**
  128.    * @return A database id that correspond this options
  129.    * @since 3.5.5
  130.    */
  131.   String databaseId() default "";

  132.   /**
  133.    * The container annotation for {@link Options}.
  134.    * @author Kazuki Shimizu
  135.    * @since 3.5.5
  136.    */
  137.   @Documented
  138.   @Retention(RetentionPolicy.RUNTIME)
  139.   @Target(ElementType.METHOD)
  140.   @interface List {
  141.     Options[] value();
  142.   }

  143. }