|
17 | 17 | import static com.oracle.nosql.spring.data.Constants.NOTSET_SHARD_KEY; |
18 | 18 |
|
19 | 19 | /** |
20 | | - * Identifies the annotated field as a primary key of the composite |
21 | | - * primary key. |
22 | | - * Order of the primary keys are crucial for distribution of data, it |
23 | | - * is recommended to provide both shard and order elements with this |
24 | | - * annotation. |
| 20 | + * Identifies the annotated field as a component of the composite |
| 21 | + * primary key.<p> |
| 22 | + * |
| 23 | + * Order of the fields affects index selection on queries, and |
| 24 | + * data distribution. Query performance is improved when field 1 |
| 25 | + * through field N appears as query predicates where N is less than |
| 26 | + * or equal to the total fields in the composite key.<p> |
| 27 | + * |
| 28 | + * It is recommended to provide both {@code shardKey} and {@code order} options |
| 29 | + * with this annotation. |
25 | 30 | * <pre> |
26 | | - * Example: |
| 31 | + * Example creating the composite key (country, city, street): |
27 | 32 | * class CompositeKey { |
28 | | - * @NosqlKey(shardKey=true, order = 1) |
29 | | - * private String city; |
| 33 | + * @NosqlKey(shardKey = true, order = 1) |
| 34 | + * private String country; |
30 | 35 | * |
31 | 36 | * @NosqlKey(shardKey = false, order = 2) |
32 | | - * private String area; |
| 37 | + * private String city; |
| 38 | + * |
| 39 | + * @NosqlKey(shardKey = false, order = 3) |
| 40 | + * private String street; |
33 | 41 | * } |
34 | 42 | * </pre> |
35 | | - * @since 1.6.0 |
| 43 | + * Queries using country, or country and city, or country and city and street |
| 44 | + * as filtering predicates are faster than queries specifying only street. |
| 45 | + * |
| 46 | + * @since 1.6.0 |
36 | 47 | */ |
37 | | - |
38 | 48 | @Documented |
39 | 49 | @Retention(value = RetentionPolicy.RUNTIME) |
40 | 50 | @Target(value = {ElementType.ANNOTATION_TYPE, ElementType.FIELD, |
41 | 51 | ElementType.METHOD}) |
42 | 52 | public @interface NosqlKey { |
43 | 53 | /** |
44 | | - * Specifies whether the field is shard key or not. Default value is |
45 | | - * {@link com.oracle.nosql.spring.data.Constants#NOTSET_SHARD_KEY}. |
46 | | - * |
| 54 | + * Specifies whether the field is part of the shard key or not. Default value |
| 55 | + * is {@link com.oracle.nosql.spring.data.Constants#NOTSET_SHARD_KEY}. |
| 56 | + * Shard keys affect distribution of rows across shards and atomicity of |
| 57 | + * operations on a single shard. |
47 | 58 | * @since 1.6.0 |
48 | 59 | */ |
49 | 60 | boolean shardKey() default NOTSET_SHARD_KEY; |
50 | 61 |
|
51 | 62 | /** |
52 | | - * Specifies the order of this primary key related to other primary keys |
53 | | - * of composite key class. |
| 63 | + * Specifies the order of the field related to other fields with the same |
| 64 | + * shardKey value listed in the composite key class.<p> |
54 | 65 | * This ordering is used in table creation DDL to specify PRIMARY KEY and |
55 | | - * SHARD KEY ordering. |
56 | | - * Ordering is done based on below rules. |
57 | | - * <ul> |
58 | | - * <li>SHARD KEYS are placed before non SHARD KEYS.</li> |
59 | | - * <li>For each SHARD and non SHARD group</li> |
60 | | - * <li> |
61 | | - * <ul> |
62 | | - * <li> |
63 | | - * If order is specified it must be specified on all the fields |
64 | | - * otherwise it is an error. |
65 | | - * </li> |
66 | | - * <li> |
67 | | - * If order is specified it must be unique otherwise it is an |
68 | | - * error. |
69 | | - * </li> |
70 | | - * <li> |
71 | | - * If no order is specified then fields are sorted by lower case |
72 | | - * alphabetical order of the field names |
73 | | - * </li> |
74 | | - * </ul> |
75 | | - * </li> |
76 | | - * </ul> |
| 66 | + * SHARD KEY ordering.<p> |
| 67 | + * Ordering is done based on below rules:<ul><li> |
| 68 | + * Shard keys are placed at the beginning.</li><li> |
| 69 | + * When using the <code>order</code> option:<ul><li> |
| 70 | + * It must be specified on all the fields otherwise it is an error. |
| 71 | + * </li><li> |
| 72 | + * It must be unique otherwise it is an error.</li></ul></li><li> |
| 73 | + * If {@code order} is not specified then fields are sorted |
| 74 | + * alphabetically using lower case field names for fields grouped by the |
| 75 | + * same shardKey value.</li></ul><p> |
77 | 76 | * Default value is |
78 | 77 | * {@link com.oracle.nosql.spring.data.Constants#NOTSET_PRIMARY_KEY_ORDER} |
79 | 78 | * |
80 | 79 | * @since 1.6.0 |
81 | 80 | */ |
82 | | - |
83 | 81 | int order() default NOTSET_PRIMARY_KEY_ORDER; |
84 | | - |
85 | 82 | } |
0 commit comments