- java.lang.Object
-
- io.github.mmm.entity.link.AbstractLink<E>
-
- io.github.mmm.entity.link.EntityLink<E>
-
- All Implemented Interfaces:
Link<E>
public class EntityLink<E extends Entity> extends AbstractLink<E>
Implementation ofAbstractLinkbased on an already resolvedEntity.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedEntityLink(E entity)The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Id<E>getId()EgetTarget()booleanisResolved()-
Methods inherited from class io.github.mmm.entity.link.AbstractLink
equals, hashCode, toString
-
-
-
-
Constructor Detail
-
EntityLink
protected EntityLink(E entity)
The constructor.- Parameters:
entity- thetarget entity.
-
-
Method Detail
-
isResolved
public boolean isResolved()
- Returns:
trueif thelink targetis already resolved,falseotherwise (ifLink.getTarget()may trigger lazy loading and could also fail if called without an open transaction).
-
getId
public Id<E> getId()
- Returns:
- the
unique identifierof the linkedbean. When creating newEntitiesa link may hold a transientEntityastargetthat has no ID assigned, yet. In such case this method will returnnull.
-
getTarget
public E getTarget()
Description copied from interface:LinkThis method resolves the linked entity.
ATTENTION:
ALinkcan 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. UseLink.isResolved()to distinguish and prevent undesired link resolving.
Further, after serialization (e.g. mapping to JSON and back) maybe only theIDwas transferred and this link can not be resolved. In that case this method may returnnull. Please note thatidandtargetcan not both be null. In case a link property is empty it will containnullinstead of an emptyLinkso you can always properly distinguish the scenarios.- Returns:
- the link target or
nullif the link can not be resolved.
-
-