Class AbstractId<E,​I,​V extends Comparable<?>>

  • Type Parameters:
    E - type of the identified entity.
    I - type of the ID.
    V - type of the Version.
    All Implemented Interfaces:
    Id<E>
    Direct Known Subclasses:
    AbstractInstantId, AbstractVersionId

    public abstract class AbstractId<E,​I,​V extends Comparable<?>>
    extends Object
    implements Id<E>
    This is the abstract base implementation of Id.
    Since:
    1.0.0
    • Constructor Detail

      • AbstractId

        public AbstractId​(Class<E> type)
        The constructor.
        Parameters:
        type - - see getType().
    • Method Detail

      • getType

        public Class<E> getType()
        Specified by:
        getType in interface Id<E>
        Returns:
        the Class reflecting the type of the referenced entity. May be null if not available.
      • getVersion

        public abstract V getVersion()
        Specified by:
        getVersion in interface Id<E>
        Returns:
        the version of this entity. Whenever the Entity gets updated (a modification is saved and the transaction is committed), this version is increased. Typically the version is a Number starting with 0 for a new Entity that is increased whenever a modification is committed. However, it may also be an Instant. The version acts as a modification sequence for optimistic locking. On each update it will be verified that the version has not been increased already by another transaction. When linking an Entity (Id used as foreign key) the version can act as revision for auditing. If it is Id.VERSION_LATEST (null) it points to the latest revision of the Entity. Otherwise it points to a specific historic revision of the Entity. Depending on the database technology (e.g. when using hibernate envers) the version and the revision can be semantically different. In such case a primary key can not be converted 1:1 as revisioned foreign key Id.
      • withLatestVersion

        public Id<E> withLatestVersion()
        Specified by:
        withLatestVersion in interface Id<E>
        Returns:
        a copy of this Id with a version of Id.VERSION_LATEST e.g. to use the Id as regular foreign key (pointing to the latest revision and not a historic revision) or this Id itself if already satisfying.
      • withVersion

        public Id<E> withVersion​(V newVersion)
        Parameters:
        newVersion - the new value of getVersion().
        Returns:
        a copy of this Id with the given version or this Id itself if already satisfying.
      • withType

        public final Id<E> withType​(Class<?> newType)
        Specified by:
        withType in interface Id<E>
        Parameters:
        newType - the new value of Id.getType(). Exact type should actually be Class<E> but this prevents simple usage. As the type can not actually be changed with this method, this should be fine.
        Returns:
        a copy of this Id with the given type or this Id itself if already satisfying.
      • getFactory

        public abstract IdFactory<I,​V,​?> getFactory()
        Returns:
        the IdFactory responsible for this Id implementation.
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public final boolean equals​(Object obj)
        Overrides:
        equals in class Object
      • getWithType

        public static <E> Id<E> getWithType​(Id<?> id,
                                            Class<E> type)
        Type Parameters:
        E - the type of the identified entity.
        Parameters:
        id - the existing Id or null.
        type - the type to ensure.
        Returns:
        the result of id.withType(type) or null if the given Id is null.
      • parseUuid

        protected static UUID parseUuid​(String idString)
        Parameters:
        idString - the id (without version) as String.
        Returns:
        the idString as UUID or null if not a UUID.