Package com.oracle.nosql.spring.data.core.mapping

# Annotation Interface NosqlKey

@Documented @Retention(RUNTIME) @Target({ANNOTATION_TYPE,FIELD,METHOD}) public @interface NosqlKey
Identifies the annotated field as a component of the composite primary key.

Order of the fields affects index selection on queries, and data distribution. Query performance is improved when field 1 through field N appears as query predicates where N is less than or equal to the total fields in the composite key.

It is recommended to provide both `shardKey` and `order` options with this annotation.

         Example creating the composite key (country, city, street):
         class CompositeKey {
              @NosqlKey(shardKey = true, order = 1)
              private String country;

              @NosqlKey(shardKey = false, order = 2)
              private String city;

              @NosqlKey(shardKey = false, order = 3)
              private String street;
         }

Queries using country, or country and city, or country and city and street as filtering predicates are faster than queries specifying only street.

Since:
  1.6.0

- ## Optional Element Summary

  Optional Elements
  Modifier and Type
  Optional Element
  Description
  `int`
  `order`
  Specifies the order of the field related to other fields listed in the composite key class.
  `boolean`
  `shardKey`
  Specifies whether the field is part of the shard key or not.

- ## Element Details

  - ### shardKey

    boolean shardKey
    Specifies whether the field is part of the shard key or not. Default value is `Constants.NOTSET_SHARD_KEY`. Shard keys affect distribution of rows across shards and atomicity of operations on a single shard.
    Since:
      1.6.0
    Default:
      `true`

  - ### order

    int order
    Specifies the order of the field related to other fields listed in the composite key class.

    This ordering is used in table creation DDL to specify PRIMARY KEY and SHARD KEY ordering.

    Ordering is done based on below rules:

    - Shard keys are placed at the beginning.
    - When using the `order` option:
      - It must be specified on all the fields otherwise it is an error.
      - It must be unique otherwise it is an error.
      - Order of the shard keys must be less than the order of non shard keys otherwise it is an error.
    - If `order` is not specified then fields are sorted alphabetically using lower case field names for fields grouped by the same shardKey value.

    Default value is `Constants.NOTSET_PRIMARY_KEY_ORDER`

    Since:
      1.6.0
    Default:
      `-1`