E
- the generic type of the identified entity.public interface Id<E> extends Datatype, AttributeReadUuid
Entity
of a particular type
.
Id
is build out of the following parts:
object-id
- the ID that identifies the entity and is unique for a specific type
.type
- is the ID of the type of the identified entity.revision
- the optional revision
of the entity.primary key
the revision
and type
of an
object do not change. This allows to create an instance of the identified object without additional costs (e.g.
database lookup) by a dynamic proxy using lazy loading.Id
has a compact string representation
that can be converted back to an Id
.
Therefore, the implementation shall provide a String
-arg constructor and a static valueOf(String)
method.GenericId
Modifier and Type | Field and Description |
---|---|
static long |
ID_UUID
|
static long |
VERSION_LATEST
The value used as
version if it unspecified. |
static char |
VERSION_SEPARATOR
The separator for the
version . |
Modifier and Type | Method and Description |
---|---|
long |
getId() |
Class<E> |
getType() |
UUID |
getUuid()
Gets the primary key as
UUID . |
long |
getVersion() |
String |
toString()
|
Id<E> |
withLatestVersion() |
Id<E> |
withType(Class<?> type) |
static final long VERSION_LATEST
version
if it unspecified. If you are using an Id
as link to an
Entity
you will use this value to point to the recent version of the Entity
.static final long ID_UUID
static final char VERSION_SEPARATOR
version
.long getId()
UUID getUuid()
UUID
. Most data stores will use a long
provided by
getId()
. However a UUID
can be used in the following scenarios:
UUID
s natively as primary key (e.g. apache cassandra supports this). In
such case getId()
will always return ID_UUID
and getUuid()
holds the actual
primary key.UUID
to the
entity on the client and link it via such ID. On the server-side the actual UUID
based Id
can then
be replaced with the actual ID
while persisting the data.null
.getUuid
in interface AttributeReadUuid
Entity
as UUID
value or null
if
getId()
is used.Id<E> withLatestVersion()
Id
with a version
of VERSION_LATEST
e.g. to use the Id
as regular foreign key (pointing to the latest revision and not a historic revision).long getVersion()
version
of this entity. Whenever the Entity
gets updated (a modification is saved and
the transaction is committed), this counter is increased. The initial value of a new EntityBean
is
0
. The version acts as a modification counter for optimistic locking. On each update it will be
verified that the version has not been increased already by another transaction. When linking an
Entity
(Id
used as foreign key) the version can act as revision for auditing. If it is
VERSION_LATEST
it points to the latest revision of the Entity
. Otherwise it points to a
specific historic revision of the Entity
. Depending on the database technology (e.g. when using
hibernate envers) the version and the revision can be semantically different. In such case a
primary key
can not directly be used as revisioned foreign key Id
.String toString()
Datatype
String
representation of this Datatype
. While the general contract of
Object.toString()
is very weak and mainly used for debugging, the contract here is very strong. The
returned String
has to be suitable for end-users and official output to any kind of sink. NlsMessage
for
this purpose and implement NlsObject
if you want to support I18N/L10N.Copyright © 2001–2016 mmm-Team. All rights reserved.