E
- the generic type of the linked
EntityBean
.public class IdLink<E extends EntityBean> extends AbstractLink<E>
Link
that initially only carries the Id
of an entity and
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.Modifier and Type | Field and Description |
---|---|
private E |
entity |
private Id<E> |
id |
private Function<Id<E>,E> |
resolver |
Modifier | Constructor and Description |
---|---|
protected |
IdLink()
The constructor (for serialization and strange frameworks).
|
protected |
IdLink(Id<E> id,
Function<Id<E>,E> resolver)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
Id<E> |
getId() |
E |
getTarget()
|
boolean |
isResolved() |
private E |
resolve() |
static <E extends EntityBean> |
valueOf(Id<E> id,
Function<Id<E>,E> resolver) |
equals, hashCode, toString
private final Id<E extends EntityBean> id
private transient Function<Id<E extends EntityBean>,E extends EntityBean> resolver
private E extends EntityBean entity
protected IdLink()
public Id<E> getId()
unique identifier
of the linked bean
. When
creating new Bean
s a link may hold a transient EntityBean
as target
that has no ID assigned, yet. In such case this method will return null
.public boolean isResolved()
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).public E getTarget()
Link
EntityBean
.Link
can be evaluated lazily. In such case the first call of this method will resolve the
linked EntityBean
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.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.null
if the link can not be resolved.private E resolve()
Copyright © 2001–2016 mmm-Team. All rights reserved.