Interface Key


  • public interface Key
    Represents a unique attribute value combination for a given entity.
    • Method Detail

      • type

        EntityType type()
        Returns:
        the entity type
      • attributes

        List<Attribute<?>> attributes()
        Returns:
        the attributes comprising this key
      • isPrimaryKey

        boolean isPrimaryKey()
        Returns:
        true if this key represents a primary key for an entity, note that this is true for empty keys representing entities without a defined primary key
      • isNull

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

        boolean isNotNull()
        Returns:
        true if no non-nullable values are null
      • isNull

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

        boolean isNotNull​(Attribute<?> attribute)
        Returns true if a non-null value is mapped to the given attribute.
        Parameters:
        attribute - the attribute
        Returns:
        true if a non-null value is mapped to the given attribute
      • attribute

        <T> Attribute<T> attribute()
        Returns this keys attribute. Note that this method throws an exception if this key is a composite key.
        Type Parameters:
        T - the attribute type
        Returns:
        the key attribute, useful for single attribute keys
        Throws:
        IllegalStateException - in case this is a composite key or if it contains no attributes
      • get

        <T> T get()
        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 or if it contains no values
      • getOptional

        <T> Optional<T> getOptional()
        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
      • get

        <T> T get​(Attribute<T> attribute)
        Type Parameters:
        T - the value type
        Parameters:
        attribute - the attribute
        Returns:
        the value associated with the given attribute
      • getOptional

        <T> Optional<T> getOptional​(Attribute<T> attribute)
        Type Parameters:
        T - the value type
        Parameters:
        attribute - the attribute
        Returns:
        the value associated with the given attribute, wrapped in an Optional
      • copyBuilder

        Key.Builder copyBuilder()
        Creates a new Key.Builder instance, initialized with the values in this key.
        Returns:
        a new builder based on this key