Class Id<T>

java.lang.Object
io.fluxzero.sdk.modeling.Id<T>
Type Parameters:
T - the entity type. I.e.: a typical class will look something like public class ProjectId extends Id<Project>.
All Implemented Interfaces:
HasId, Leaf, Comparable<Id<?>>

public abstract class Id<T> extends Object implements HasId, Comparable<Id<?>>, Leaf
Object that represents the identifier of a specific entity. This object makes it easy to prefix the functional id of an entity to with a value before storing or lookup in a repository to prevent clashes with other entities that may share the same functional id.

Additionally, this object makes it possible to store and lookup entities using a case-insensitive identifier.

It also allows specifying the entity type which prevents the need for dynamic casting after loading the entity.

Because an Id represents a scalar domain value rather than a nested object graph, it implements Leaf. This ensures Fluxzero treats identifier types as terminal values during reflection-based traversal for features such as search indexing and data protection.

Concrete ID properties and standalone IDs serialize as a string of the functionalId. Properties declared as Id<?>, Id<T> or abstract ID types instead retain a discriminator: {"name":"model","id":"value"} for Model IDs, or {"@class":"package.ConcreteId","id":"value"} for other IDs. Model names resolve through Parent.types(), a declared Model type argument, or the compile-time ModelTypes index; the Model must declare that concrete ID class as its EntityId. Explicit Jackson type information retains its own format. Unknown, conflicting and ambiguous discriminators are rejected. Previously stored polymorphic scalar values need an upcaster when their type cannot be inferred; concrete scalar values remain supported. Deserialization is done by invoking a constructor on your subtype that accepts a single String argument. If such constructor does not exist, please specify your own deserializer, using e.g. @JsonDeserialize on your type. Discriminated properties also use that concrete subtype deserializer, with the original property context.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Reads scalar concrete IDs and discriminated polymorphic IDs.
    static class 
    Writes concrete ID properties as scalars and polymorphic properties with a recoverable type discriminator.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Id(@NonNull String functionalId, @NonNull Class<T> type, @NonNull String prefix, boolean caseSensitive)
    Construct an id for an entity.
    Id(@NonNull String functionalId, @NonNull String prefix, boolean caseSensitive)
    Construct an id for an entity.
    Id(String functionalId)
    Construct a case-sensitive id for an entity without prefix.
    Id(String functionalId, boolean caseSensitive)
    Construct an id for an entity without prefix.
    Id(String functionalId, Class<T> type)
    Construct a case-sensitive id for an entity without prefix.
    Id(String functionalId, Class<T> type, boolean caseSensitive)
    Construct an id for an entity without prefix.
    Id(String functionalId, Class<T> type, String prefix)
    Construct a case-sensitive id for an entity.
    Id(String functionalId, String prefix)
    Construct a case-sensitive id for an entity.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(Id<?> o)
     
    boolean
     
    Returns the stringified identifier of this object.
    int
     
    final String
    Returns the id under which the entity will be stored in a repository.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Id

      public Id(String functionalId)
      Construct a case-sensitive id for an entity without prefix. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id.

      The identifier's type will be determined using reflection.

      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
    • Id

      public Id(String functionalId, Class<T> type)
      Construct a case-sensitive id for an entity without prefix. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id.
      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      type - The entity's type. This may be a superclass of the actual entity.
    • Id

      public Id(String functionalId, String prefix)
      Construct a case-sensitive id for an entity. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id.

      The identifier's type will be determined using reflection.

      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      prefix - The prefix that is prepended to the functionalId to create the full id under which this entity will be stored. Eg, if the prefix of an Id is "user-", and the id is "pete123", the entity will be stored under "user-pete123".
    • Id

      public Id(String functionalId, Class<T> type, String prefix)
      Construct a case-sensitive id for an entity. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id.
      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      type - The entity's type. This may be a superclass of the actual entity.
      prefix - The prefix that is prepended to the functionalId to create the full id under which this entity will be stored. Eg, if the prefix of an Id is "user-", and the id is "pete123", the entity will be stored under "user-pete123".
    • Id

      public Id(String functionalId, boolean caseSensitive)
      Construct an id for an entity without prefix. This constructor allows ids to be case-insensitive.

      The identifier's type will be determined using reflection.

      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      caseSensitive - whether this id is case-sensitive.
    • Id

      public Id(String functionalId, Class<T> type, boolean caseSensitive)
      Construct an id for an entity without prefix. This constructor allows ids to be case-insensitive.
      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      type - The entity's type. This may be a superclass of the actual entity.
      caseSensitive - whether this id is case-sensitive.
    • Id

      public Id(@NonNull @NonNull String functionalId, @NonNull @NonNull String prefix, boolean caseSensitive)
      Construct an id for an entity. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id. It also enables ids to be case-insensitive.

      The identifier's type will be determined using reflection.

      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      prefix - The prefix that is prepended to the functionalId to create the full id under which this entity will be stored. Eg, if the prefix of an Id is "user-", and the id is "pete123", the entity will be stored under "user-pete123".
      caseSensitive - whether this id is case-sensitive.
    • Id

      public Id(@NonNull @NonNull String functionalId, @NonNull @NonNull Class<T> type, @NonNull @NonNull String prefix, boolean caseSensitive)
      Construct an id for an entity. This constructor allows ids to be prefixed with a value to prevent clashes with other entities that may share the same functional id. It also enables ids to be case-insensitive.
      Parameters:
      functionalId - The functional id of the entity. The object's toString() method is used to get a string representation of the functional id.
      type - The entity's type. This may be a superclass of the actual entity.
      prefix - The prefix that is prepended to the functionalId to create the full id under which this entity will be stored. Eg, if the prefix of an Id is "user-", and the id is "pete123", the entity will be stored under "user-pete123".
      caseSensitive - whether this id is case-sensitive.
  • Method Details

    • getId

      public String getId()
      Description copied from interface: HasId
      Returns the stringified identifier of this object.

      This is typically used for serialization or ID-based lookups.

      Specified by:
      getId in interface HasId
      Returns:
      a non-null, plain string representation of the identifier
    • toString

      public final String toString()
      Returns the id under which the entity will be stored in a repository. This may differ from the functional
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Id<?> o)
      Specified by:
      compareTo in interface Comparable<T>