Class IdLink<E>

  • Type Parameters:
    E - the generic type of the linked entity.
    All Implemented Interfaces:
    Link<E>

    public class IdLink<E>
    extends AbstractLink<E>
    Implementation of Link that carries the Id of an entity. It optionally allows lazy loading on the first call of getTarget() via an externally given resolver Function. This approach is easier, less invasive and more lightweight as using proxy objects for entities.
    Since:
    1.0.0
    • Method Detail

      • getId

        public Id<E> getId()
        Returns:
        the unique identifier of the linked bean. When creating new Entities a link may hold a transient Entity as target that has no ID assigned, yet. In such case this method will return null.
      • isResolved

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

        public E getTarget()
        Description copied from interface: Link
        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 Link.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.
      • withType

        public IdLink<E> withType​(Class<?> type)
        Parameters:
        type - the new value of Id.getType(). Exact type should actually be Class<E> but this prevents simple usage.
        Returns:
        a copy of this Link with the given type or this Link itself if already satisfying.
        See Also:
        Id.withType(Class)