Package io.ran

Annotation Interface PrimaryKey


@Retention(RUNTIME) @Target(FIELD) public @interface PrimaryKey
@PrimaryKey is used to mark a field in a model class as (part of) the primary key.

If the primary key is a composite key, then the order of the fields in the model class will be used to determine the order of the fields in the keyset.

This order can be overridden by setting the order parameter.

Example:


 public class User {
    @PrimaryKey(order = 1)
 	public Long id;
    @PrimaryKey(order = 0)
 	public String name;
 	public String email;
 }
 

This will create a primary key with the fields "name" and "id" in that order.

If instead the order was not set, the order of the fields in the model class would be used, which would result in a primary key with the fields "id" and "name" in that order.

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Can be set for single-column primary key of type Integer, Long or Short.
    int
    If not set, the order of the fields on the model class will be used for ordering.
  • Element Details

    • order

      int order
      If not set, the order of the fields on the model class will be used for ordering.
      Returns:
      the order in the keyset
      Default:
      -1
    • autoIncrement

      boolean autoIncrement
      Can be set for single-column primary key of type Integer, Long or Short. Not supported for composite primary keys (i.e. multiple fields annotated with @PrimaryKey). If true, inserting an object with the primary key of null will use the database-side auto-increment feature to generate a primary key.

      NOTE: The object will be updated with the generated primary key only if it was inserted via the Valqueries' single-object overloads of insert(), insertOther(), save() or saveOther() methods. The collection overloads do not set any generated primary keys.

      Returns:
      whether the primary key is auto-incrementing
      Default:
      false