-
- Type Parameters:
E
- the generic type of thelinked
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 theprimary key
of the linked entity.- Since:
- 1.0.0
- See Also:
Entity
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Id<E>
getId()
E
getTarget()
boolean
isResolved()
static <E extends Entity>
Link<E>of(E entity)
static <E> Link<E>
of(Id<E> id)
static <E extends Entity>
voidofCollection(Collection<Link<E>> links, E... entities)
static <E extends Entity>
voidofCollection(Collection<Link<E>> links, Id<E>... ids)
static <E extends Entity>
voidofCollection(Collection<Link<E>> links, Collection<E> entities)
static <E extends Entity>
List<Link<E>>ofList(E... entities)
static <E extends Entity>
List<Link<E>>ofList(Id<E>... ids)
static <E extends Entity>
List<Link<E>>ofList(Collection<E> entities)
static <E extends Entity>
Set<Link<E>>ofSet(E... entities)
static <E extends Entity>
Set<Link<E>>ofSet(Id<E>... ids)
static <E extends Entity>
Set<Link<E>>ofSet(Collection<E> entities)
-
-
-
Method Detail
-
getId
Id<E> getId()
- Returns:
- the
unique identifier
of the linkedbean
. When creating newEntities
a link may hold a transientEntity
astarget
that has no ID assigned, yet. In such case this method will returnnull
.
-
isResolved
boolean isResolved()
- Returns:
true
if thelink target
is already resolved,false
otherwise (ifgetTarget()
may trigger lazy loading and could also fail if called without an open transaction).
-
getTarget
E getTarget()
This method resolves the linked entity.
ATTENTION:
ALink
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. UseisResolved()
to distinguish and prevent undesired link resolving.
Further, after serialization (e.g. mapping to JSON and back) maybe only theID
was transferred and this link can not be resolved. In that case this method may returnnull
. Please note thatid
andtarget
can not both be null. In case a link property is empty it will containnull
instead of an emptyLink
so you can always properly distinguish the scenarios.- Returns:
- the link target or
null
if the link can not be resolved.
-
ofSet
static <E extends Entity> Set<Link<E>> ofSet(Collection<E> entities)
-
ofList
static <E extends Entity> List<Link<E>> ofList(Collection<E> entities)
-
ofCollection
static <E extends Entity> void ofCollection(Collection<Link<E>> links, E... entities)
-
ofCollection
static <E extends Entity> void ofCollection(Collection<Link<E>> links, Collection<E> entities)
-
-