-
- Type Parameters:
E- type of the identified entity.
- All Known Implementing Classes:
AbstractId,AbstractInstantId,AbstractVersionId,LongInstantId,LongVersionId,StringInstantId,StringVersionId,UuidInstantId,UuidVersionId
public interface Id<E>This is the interface for an ID that uniquely identifies a persistent entity of a particulartype(<E>).
AnIdis build out of the following parts:object-id- the primary key that identifies the entity and is unique for a specifictype.type- is the (optional) type of the identified entity.version- the optional version (revision) of the entity.
primary keytheversionandtypeof an object do not change. This allows to use theIdas globally unique identifier for its corresponding entity.
AnIdhas a compactstring representationthat can be converted back to anId. Therefore, the implementation shall provide aString-arg constructor and a staticvalueOf(String)method.- Since:
- 1.0.0
- See Also:
AbstractId
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROPERTY_IDThe name of theIDproperty (e.g.static StringPROPERTY_VERSIONThe name of theversionproperty (e.g.static Comparable<?>VERSION_LATESTThe value used asversionif it unspecified.static charVERSION_SEPARATORThe separator for theversion.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ObjectgetId()default StringgetIdAsString()Class<E>getType()Comparable<?>getVersion()default StringgetVersionAsString()static <E extends Entity>
Id<E>of(E entity)Type-safe andnull-safe variant ofEntity.getId().StringtoString()Id<E>withLatestVersion()Id<E>withType(Class<?> type)
-
-
-
Field Detail
-
PROPERTY_ID
static final String PROPERTY_ID
The name of theIDproperty (e.g. for JSON or XML).- See Also:
- Constant Field Values
-
PROPERTY_VERSION
static final String PROPERTY_VERSION
The name of theversionproperty (e.g. for JSON or XML).- See Also:
- Constant Field Values
-
VERSION_LATEST
static final Comparable<?> VERSION_LATEST
-
VERSION_SEPARATOR
static final char VERSION_SEPARATOR
The separator for theversion.- See Also:
- Constant Field Values
-
-
Method Detail
-
getId
Object getId()
- Returns:
- the primary key of the identified
EntityasObjectvalue. It is only unique for a particulartypeof an entity. - See Also:
LongVersionId,UuidVersionId,StringVersionId
-
getIdAsString
default String getIdAsString()
- Returns:
- the
primary keyasStringfor marshalling.
-
getType
Class<E> getType()
- Returns:
- the
Classreflecting the type of the referenced entity. May benullif not available.
-
withLatestVersion
Id<E> withLatestVersion()
- Returns:
- a copy of this
Idwith aversionofVERSION_LATESTe.g. to use theIdas regular foreign key (pointing to the latest revision and not a historic revision) or thisIditself if already satisfying.
-
getVersion
Comparable<?> getVersion()
- Returns:
- the
versionof this entity. Whenever theEntitygets updated (a modification is saved and the transaction is committed), this version is increased. Typically the version is aNumberstarting with0for a newEntitythat is increased whenever a modification is committed. However, it may also be anInstant. The version acts as a modification sequence for optimistic locking. On each update it will be verified that the version has not been increased already by another transaction. When linking anEntity(Idused as foreign key) the version can act as revision for auditing. If it isVERSION_LATEST(null) it points to the latest revision of theEntity. Otherwise it points to a specific historic revision of theEntity. Depending on the database technology (e.g. when using hibernate envers) the version and the revision can be semantically different. In such case aprimary keycan not be converted 1:1 as revisioned foreign keyId.
-
getVersionAsString
default String getVersionAsString()
-
toString
String toString()
-
-