Skip to content

Commit 5c51782

Browse files
Merge branch 'feature/composite-key' of https://github.com/oracle/nosql-spring-sdk into feature/composite-key
2 parents 5c4c53c + 98d0b75 commit 5c51782

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

src/main/java/com/oracle/nosql/spring/data/core/mapping/NosqlId.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616
/**
1717
* Identifies the primary key field of the entity. Primary key can be of a
1818
* basic type or of a type that represents a composite primary key. This
19-
* field corresponds to the {@literal PRIMARY KEY} of the corresponding Nosql
19+
* field corresponds to the {@code PRIMARY KEY} of the corresponding Nosql
2020
* table. Only one field of the entity can be annotated with this annotation.
21+
*
22+
* If using a composite primary key, the fields comprising the composite key
23+
* must have distinct names when viewed in lower case, otherwise an error is
24+
* raised.
2125
*/
22-
2326
@Id
2427
@Retention(RetentionPolicy.RUNTIME)
2528
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
2629
public @interface NosqlId {
30+
/**
31+
* Specifies if values for the field are automatically generated. Valid only
32+
* for int, Integer, long, Long, BigInteger, BigDecimal,
33+
*/
2734
boolean generated() default false;
2835
}

src/main/java/com/oracle/nosql/spring/data/core/mapping/NosqlKey.java

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,66 @@
1717
import static com.oracle.nosql.spring.data.Constants.NOTSET_SHARD_KEY;
1818

1919
/**
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.
2530
* <pre>
26-
* Example:
31+
* Example creating the composite key (country, city, street):
2732
* class CompositeKey {
28-
* &#64;NosqlKey(shardKey=true, order = 1)
29-
* private String city;
33+
* &#64;NosqlKey(shardKey = true, order = 1)
34+
* private String country;
3035
*
3136
* &#64;NosqlKey(shardKey = false, order = 2)
32-
* private String area;
37+
* private String city;
38+
*
39+
* &#64;NosqlKey(shardKey = false, order = 3)
40+
* private String street;
3341
* }
3442
* </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
3647
*/
37-
3848
@Documented
3949
@Retention(value = RetentionPolicy.RUNTIME)
4050
@Target(value = {ElementType.ANNOTATION_TYPE, ElementType.FIELD,
4151
ElementType.METHOD})
4252
public @interface NosqlKey {
4353
/**
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.
4758
* @since 1.6.0
4859
*/
4960
boolean shardKey() default NOTSET_SHARD_KEY;
5061

5162
/**
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>
5465
* 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>
7776
* Default value is
7877
* {@link com.oracle.nosql.spring.data.Constants#NOTSET_PRIMARY_KEY_ORDER}
7978
*
8079
* @since 1.6.0
8180
*/
82-
8381
int order() default NOTSET_PRIMARY_KEY_ORDER;
84-
8582
}

0 commit comments

Comments
 (0)