E - the generic type of the identified entity.public class GenericId<E> extends AbstractId<E>
Id for a long based primary key.| Modifier and Type | Field and Description |
|---|---|
private long |
id |
private static long |
serialVersionUID |
private UUID |
uuid |
private long |
version |
ID_UUID, VERSION_LATEST, VERSION_SEPARATOR| Modifier | Constructor and Description |
|---|---|
protected |
GenericId()
The constructor.
|
|
GenericId(Class<E> type,
long id,
long version)
The constructor.
|
|
GenericId(Class<E> type,
UUID uuid,
long version)
The constructor.
|
private |
GenericId(Class<E> type,
UUID uuid,
long id,
long version)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getId() |
UUID |
getUuid()
Gets the primary key as
UUID. |
long |
getVersion() |
static <E> GenericId<E> |
of(Class<E> type,
long id) |
static <E> GenericId<E> |
of(Class<E> type,
Long id) |
static <E> GenericId<E> |
of(Class<E> type,
long id,
long version) |
static <E> GenericId<E> |
of(Class<E> type,
Long id,
long version) |
static <E> GenericId<E> |
of(Class<E> type,
String idAsString) |
static <E> GenericId<E> |
of(Class<E> type,
UUID uuid) |
static <E> GenericId<E> |
of(Class<E> type,
UUID uuid,
long version) |
Id<E> |
withLatestVersion() |
GenericId<E> |
withType(Class<?> type) |
private static final long serialVersionUID
private UUID uuid
private long id
private long version
protected GenericId()
public GenericId(Class<E> type, long id, long version)
type - - see AbstractId.getType().id - - see getId().version - - see getVersion().public GenericId(Class<E> type, UUID uuid, long version)
type - - see AbstractId.getType().uuid - - see getUuid().version - - see getVersion().private GenericId(Class<E> type, UUID uuid, long id, long version)
type - - see AbstractId.getType().uuid - - see getUuid().id - - see getId().version - - see getVersion().public UUID getUuid()
IdUUID. Most data stores will use a long provided by
Id.getId(). However a UUID can be used in the following scenarios:
UUIDs natively as primary key (e.g. apache cassandra supports this). In
such case Id.getId() will always return Id.ID_UUID and Id.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.Entity as UUID value or null if
Id.getId() is used.public long getId()
Entity as long value. It is only unique for a
particular type of an entity. May also be Id.ID_UUID.public 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
Id.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.public GenericId<E> withType(Class<?> type)
type - the value of Id.getType(). Exact type should actually be Class<E> but this
prevents simple usage. As the type can not actually be changed with this method, this
should be fine.Id ensured to carry the type.public Id<E> withLatestVersion()
Id with a version of Id.VERSION_LATEST e.g. to use the Id
as regular foreign key (pointing to the latest revision and not a historic revision).public static <E> GenericId<E> of(Class<E> type, Long id, long version)
E - the generic type of the identified entity.type - - see AbstractId.getType().id - - see getId().version - - see getVersion().GenericId.public static <E> GenericId<E> of(Class<E> type, Long id)
E - the generic type of the identified entity.type - - see AbstractId.getType().id - - see getId().GenericId.public static <E> GenericId<E> of(Class<E> type, long id)
E - the generic type of the identified entity.type - - see AbstractId.getType().id - - see getId().GenericId.public static <E> GenericId<E> of(Class<E> type, long id, long version)
E - the generic type of the identified entity.type - - see AbstractId.getType().id - - see getId().version - - see getVersion().GenericId.public static <E> GenericId<E> of(Class<E> type, UUID uuid)
E - the generic type of the identified entity.type - - see AbstractId.getType().uuid - - see getUuid().GenericId.public static <E> GenericId<E> of(Class<E> type, UUID uuid, long version)
E - the generic type of the identified entity.type - - see AbstractId.getType().uuid - - see getUuid().version - - see getVersion().GenericId.public static <E> GenericId<E> of(Class<E> type, String idAsString)
E - the generic type of the identified entity.type - - see AbstractId.getType().idAsString - the string representation of the ID.GenericId.Copyright © 2001–2016 mmm-Team. All rights reserved.