From eaae598234bcacb3c874981b4f31c0bc760b662c Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Mon, 9 Jan 2017 15:05:14 +0800 Subject: [PATCH] --- src/javax/persistence/Index.java | 68 +++++++++++++++++++++ src/javax/persistence/Table.java | 23 +++++++ src/javax/persistence/UniqueConstraint.java | 52 ++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 src/javax/persistence/Index.java create mode 100644 src/javax/persistence/UniqueConstraint.java diff --git a/src/javax/persistence/Index.java b/src/javax/persistence/Index.java new file mode 100644 index 000000000..5899a0330 --- /dev/null +++ b/src/javax/persistence/Index.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 Oracle Corporation. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Linda DeMichiel - Java Persistence 2.1 + * + ******************************************************************************/ +package javax.persistence; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Used in schema generation to specify creation of an index. + *

+ * Note that it is not necessary to specify an index for a primary key, + * as the primary key index will be created automatically. + * + *

+ * The syntax of the columnList element is a + * column_list, as follows: + * + *

+ *    column::= index_column [,index_column]*
+ *    index_column::= column_name [ASC | DESC]
+ * 
+ * + *

If ASC or DESC is not specified, + * ASC (ascending order) is assumed. + * + * @see Table + * @see SecondaryTable + * @see CollectionTable + * @see JoinTable + * @see TableGenerator + * + * @since Java Persistence 2.1 + * + */ +@Target({}) +@Retention(RUNTIME) +public @interface Index { + + /** + * (Optional) The name of the index; defaults to a provider-generated name. + */ + String name() default ""; + + /** + * (Required) The names of the columns to be included in the index, + * in order. + */ + String columnList(); + + /** + * (Optional) Whether the index is unique. + */ + boolean unique() default false; + +} diff --git a/src/javax/persistence/Table.java b/src/javax/persistence/Table.java index d25dc26c7..353f62af0 100644 --- a/src/javax/persistence/Table.java +++ b/src/javax/persistence/Table.java @@ -59,4 +59,27 @@ public @interface Table { */ String catalog() default ""; + /** + * (Optional) Unique constraints that are to be placed on + * the table. These are only used if table generation is in + * effect. These constraints apply in addition to any constraints + * specified by the Column and JoinColumn + * annotations and constraints entailed by primary key mappings. + *

+ * Defaults to no additional constraints. + */ + UniqueConstraint[] uniqueConstraints() default {}; + + /** + * (Optional) Indexes for the table. These are only used if + * table generation is in effect. Note that it is not necessary + * to specify an index for a primary key, as the primary key + * index will be created automatically. + * + * @since Java Persistence 2.1 + */ + Index[] indexes() default {}; + + String comment() default ""; + } diff --git a/src/javax/persistence/UniqueConstraint.java b/src/javax/persistence/UniqueConstraint.java new file mode 100644 index 000000000..2351b4511 --- /dev/null +++ b/src/javax/persistence/UniqueConstraint.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Linda DeMichiel - Java Persistence 2.1 + * Linda DeMichiel - Java Persistence 2.0 + * + ******************************************************************************/ +package javax.persistence; + +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Specifies that a unique constraint is to be included in + * the generated DDL for a primary or secondary table. + * + *

+ *    Example:
+ *    @Entity
+ *    @Table(
+ *        name="EMPLOYEE", 
+ *        uniqueConstraints=
+ *            @UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"})
+ *    )
+ *    public class Employee { ... }
+ * 
+ * + * @since Java Persistence 1.0 + */ +@Target({}) +@Retention(RUNTIME) +public @interface UniqueConstraint { + + /** (Optional) Constraint name. A provider-chosen name will be chosen + * if a name is not specified. + * + * @since Java Persistence 2.0 + */ + String name() default ""; + + /** (Required) An array of the column names that make up the constraint. */ + String[] columnNames(); +}