001package io.ebean.annotation;
002
003import java.lang.annotation.ElementType;
004import java.lang.annotation.Repeatable;
005import java.lang.annotation.Retention;
006import java.lang.annotation.RetentionPolicy;
007import java.lang.annotation.Target;
008
009/**
010 * An annotation for declaring an index.
011 *
012 * @author rvbiljouw
013 */
014@Target({ElementType.TYPE, ElementType.FIELD})
015@Retention(RetentionPolicy.RUNTIME)
016@Repeatable(Indices.class)
017public @interface Index {
018
019  /**
020   * Name of the index. If left blank a name is derived using the built in naming convention.
021   */
022  String name() default "";
023
024  /**
025   * If set true indicates this is a unique index.
026   */
027  boolean unique() default false;
028
029  /**
030   * If set true with Postgres this index should be created concurrently.
031   * <p>
032   * This attribute currently only applies to Postgres applying to both the
033   * <code>create index</code> and <code>drop index</code> generated DDL.
034   */
035  boolean concurrent() default false;
036
037  /**
038   * When placed on the class (rather than field) you can specify the columns
039   * to include in the index in order.
040   * <p>
041   * When placed on a field, and columnNames are specified, the field-column has to be included.
042   * You can use "${fa}" for alias.
043   */
044  String[] columnNames() default {};
045
046  /**
047   * Platforms this index applies to - default is all platforms.
048   * <p>
049   * This provides an alternative to using extra-dll.xml to specify
050   * platform specific index ddl.
051   * <p>
052   * Changing platforms is NOT detected as part of DB migration
053   * generation (no platform specific DIFF) so using extra-ddl.xml
054   * may be preferred.
055   */
056  Platform[] platforms() default {};
057
058  /**
059   * The full raw SQL definition to create the index.
060   * <p>
061   * The indexName should be provided such that the drop index statement can
062   * be generated as needed.
063   * <p>
064   * This allows for platform specific index creation features as an alternative to using
065   * ebean extra-dll.xml to define extra potentially platform specific DDL.
066   *
067   * <pre>{@code
068   *
069   *   @Index(name = "ix_t_detail_defn",
070   *     definition = "create index ix_t_detail_defn on t_detail using hash (lower(name)) where lower(name) like 'r%'",
071   *     platforms = Platform.POSTGRES)
072   *
073   * }</pre>
074   */
075  String definition() default "";
076
077}