Interface Link<E>

  • Type Parameters:
    E - the generic type of the linked entity.
    All Known Implementing Classes:
    AbstractLink, EntityLink, IdLink

    public interface Link<E>
    This is the interface for a link to a persistent entity. It acts as a reference that can be evaluated lazily. It will hold the primary key of the linked entity.
    Since:
    1.0.0
    See Also:
    Entity
    • Method Detail

      • isResolved

        boolean isResolved()
        Returns:
        true if the link target is already resolved, false otherwise (if getTarget() may trigger lazy loading and could also fail if called without an open transaction).
      • getTarget

        E getTarget()
        This method resolves the linked entity.
        ATTENTION:
        A Link can be evaluated lazily. In such case the first call of this method will resolve the linked entity from the database. That can be a relatively expensive operation and requires an open transaction. Use isResolved() to distinguish and prevent undesired link resolving.
        Further, after serialization (e.g. mapping to JSON and back) maybe only the ID was transferred and this link can not be resolved. In that case this method may return null. Please note that id and target can not both be null. In case a link property is empty it will contain null instead of an empty Link so you can always properly distinguish the scenarios.
        Returns:
        the link target or null if the link can not be resolved.
      • of

        static <E extends EntityLink<E> of​(E entity)
        Type Parameters:
        E - type of Entity.
        Parameters:
        entity - the Entity.
        Returns:
        the Link for the given Entity. Will be null if the given Entity was null.
      • of

        static <E> Link<E> of​(Id<E> id)
        Type Parameters:
        E - type of the linked Entity.
        Parameters:
        id - the id.
        Returns:
        the Link for the given Id.
      • ofSet

        static <E extends EntitySet<Link<E>> ofSet​(Id<E>... ids)
        Type Parameters:
        E - type of Entity.
        Parameters:
        ids - the Ids to convert to Links.
        Returns:
        the Set of Links for the given Ids.
      • ofList

        static <E extends EntityList<Link<E>> ofList​(Id<E>... ids)
        Type Parameters:
        E - type of Entity.
        Parameters:
        ids - the Ids to convert to Links.
        Returns:
        the List of Links for the given Ids.
      • ofCollection

        static <E extends Entity> void ofCollection​(Collection<Link<E>> links,
                                                    Id<E>... ids)
        Type Parameters:
        E - type of Entity.
        Parameters:
        links - the Collection where to add the Links to create from the given Ids.
        ids - the Ids to convert to Links.