001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012import java.lang.annotation.Retention;
013import java.lang.annotation.Target;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.RUNTIME;
017
018/**
019 * Defines a primary key generator that may be referenced by name when a generator element is specified for
020 * the {@link GeneratedValue} annotation. A sequence generator may be specified on the entity class or on the
021 * primary key field or property. The scope of the generator name is global to the persistence unit (across
022 * all generator types).
023 * <p>
024 * <pre>
025 *   Example:
026 *
027 *   &#064;SequenceGenerator(name="EMP_SEQ", allocationSize=25)
028 * </pre>
029 *
030 * @since Java Persistence 1.0
031 */
032@Target({TYPE, METHOD, FIELD})
033@Retention(RUNTIME)
034public @interface SequenceGenerator {
035  /**
036   * (Required) A unique generator name that can be referenced by one or more classes to be the generator
037   * for primary key values.
038   *
039   * @return name
040   */
041  String name();
042
043  /**
044   * (Optional) The name of the database sequence object from which to obtain primary key values.
045   * <p>
046   * Defaults to a provider-chosen value.
047   *
048   * @return seq name
049   */
050  String sequenceName() default "";
051
052  /**
053   * (Optional) The catalog of the sequence generator.
054   *
055   * @return catalog
056   * @since Java Persistence 2.0
057   */
058  String catalog() default "";
059
060  /**
061   * (Optional) The schema of the sequence generator.
062   *
063   * @return schema
064   * @since Java Persistence 2.0
065   */
066  String schema() default "";
067
068  /**
069   * (Optional) The value from which the sequence object is to start generating.
070   *
071   * @return init value
072   */
073  int initialValue() default 1;
074
075  /**
076   * (Optional) The amount to increment by when allocating sequence numbers from the sequence.
077   *
078   * @return alloc size
079   */
080  int allocationSize() default 50;
081}