Interface Entity.Key

Enclosing interface:
Entity

public static sealed interface Entity.Key
Represents a unique column combination for a given entity.
  • Method Details

    • type

      EntityType type()
      Returns:
      the entity type
    • definition

      EntityDefinition definition()
      Returns:
      the entity definition
    • columns

      Collection<Column<?>> columns()
      Returns the columns comprising this key, in an unspecified order. For the primary key columns in the correct (indexed) order use EntityDefinition.PrimaryKey.columns() via EntityDefinition.primaryKey().
      Returns:
      the columns comprising this key in no particular order
    • primary

      boolean primary()
      Indicates whether this key represents an actual primary key or a pseudo primary key.

      Returns false for pseudo primary keys created for entities without defined primary keys. Pseudo primary keys contain all column values and enable basic CRUD operations on entities without proper PKs.

      Returns:
      true if this is an actual primary key, false if this is a pseudo primary key
      See Also:
    • isNull

      boolean isNull()
      Returns:
      true if this key contains no values or if it contains a null value for a non-nullable key attribute
    • isNull

      boolean isNull(Column<?> column)
      Returns true if a null value is mapped to the given column or no mapping exists.
      Parameters:
      column - the column
      Returns:
      true if the value mapped to the given column is null or none exists
    • column

      <T> Column<T> column()
      Returns this keys column. Note that this method throws an exception if this key is a composite key.
      Type Parameters:
      T - the column type
      Returns:
      the key column, useful for single column keys
      Throws:
      IllegalStateException - in case this is a composite key
      NoSuchElementException - in case this key contains no values
    • value

      <T> @Nullable T value()
      Returns the value of this key. Note that this method throws an exception if this key is a composite key.
      Type Parameters:
      T - the value type
      Returns:
      the first value contained in this key, useful for single attribute keys
      Throws:
      IllegalStateException - in case this is a composite key
      NoSuchElementException - in case this key contains no values
    • optional

      <T> Optional<T> optional()
      Returns the value of this key, wrapped in an Optional. Note that this method throws an exception if this key is a composite key.
      Type Parameters:
      T - the value type
      Returns:
      the first value contained in this key, wrapped in an Optional, useful for single attribute keys
      Throws:
      IllegalStateException - in case this is a composite key
      NoSuchElementException - in case this key contains no values
    • get

      <T> @Nullable T get(Column<T> column)
      Type Parameters:
      T - the value type
      Parameters:
      column - the column
      Returns:
      the value associated with the given column
      Throws:
      IllegalArgumentException - in case this column is not part of this key
    • optional

      <T> Optional<T> optional(Column<T> column)
      Type Parameters:
      T - the value type
      Parameters:
      column - the column
      Returns:
      the value associated with the given column, wrapped in an Optional
      Throws:
      IllegalArgumentException - in case this column is not part of this key
    • copy

      Creates a new Entity.Key.Builder instance, initialized with the values in this key.
      Returns:
      a new builder based on this key
    • groupByType

      Returns a LinkedHashMap containing the given entity keys mapped to their entityTypes, respecting the iteration order of the given collection
      Parameters:
      keys - the entity keys to map by entityType
      Returns:
      a Map of entity keys mapped to entityType