ID
- is the type of the primary key
.public abstract class EntityTo<ID> extends DataTo implements MutableRevisionedEntity<ID>
DTO
corresponding to a
PersistenceEntity
. Classes derived from this class should carry the suffix
Eto
. package JavaDoc
.Modifier and Type | Class and Description |
---|---|
static class |
EntityTo.PersistentEntityAccess
Inner class to grant access to internal
PersistenceEntity reference of an EntityTo . |
Modifier and Type | Field and Description |
---|---|
private ID |
id |
private int |
modificationCounter |
private GenericEntity<ID> |
persistentEntity |
private Number |
revision |
private static long |
serialVersionUID |
LATEST_REVISION
Constructor and Description |
---|
EntityTo()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
ID |
getId()
This method gets the unique identifier (primary key) of this entity.
|
int |
getModificationCounter()
This method gets the current modification-counter of this entity.
|
Number |
getRevision()
This method gets the revision of this entity.
|
int |
hashCode() |
void |
setId(ID id)
This method sets the
ID of this entity. |
void |
setModificationCounter(int version)
This method sets the
modification counter of this entity. |
void |
setRevision(Number revision)
This method sets the
revision of this entity. |
protected void |
toString(StringBuilder buffer)
Method to extend
AbstractTransferObject.toString() logic. |
private void |
writeobject(ObjectOutputStream o)
Force update of modification counter for serialization.
|
clone, toString
private static final long serialVersionUID
private ID id
private int modificationCounter
private Number revision
private transient GenericEntity<ID> persistentEntity
getModificationCounter()
public ID getId()
GenericEntity
Long
as datatype for IDs. String
-based business-oriented identifier it is best practice to use a
Long
as primary key and add the business identifier as additional field (with a unique constraint). This
way references to the entity will be a lot more compact and improve your performance in JOINs or the like. However,
there may be reasons to use other datatypes
for the ID. In any case the
unique ID should be an immutable java-object that can be rebuild from its string-representation
. Datatype
for it. If it can easily be mapped to a Long
value you can still
use Long
here and provide a transient getter method that returns the your custom
Datatype
from the Long
.getId
in interface GenericEntity<ID>
getId
in interface AttributeReadId<ID>
null
if the object is new
and
no ID has manually been assigned.public void setId(ID id)
MutableGenericEntity
ID
of this entity. GeneratedValue
and therefore managed by the persistence. However, for final freedom
we decided to add this method to the API (e.g. to copy from transfer-object to persistent-entity and vice-versa).setId
in interface MutableGenericEntity<ID>
id
- is the new value of GenericEntity.getId()
.public int getModificationCounter()
saved
, this counter will be increased. The initial value
after construction is 0
. 0
.
EntityTo
can carry a hidden reference to a PersistenceEntity
. This is
set by TransferObjectUtil.convertFromEntity(net.sf.mmm.util.entity.api.PersistenceEntity, Class)
and
related functions. In such case the modification counter is updated from that reference by this method as an
intended side effect. This is done because JPA implementations will typically update the modification counter only
after the transaction has been committed and the conversion of an entity to ETO
typically happens
before. This approach is better and more robust than flushing
.getModificationCounter
in interface GenericEntity<ID>
Version
public void setModificationCounter(int version)
MutableGenericEntity
modification counter
of this entity. setModificationCounter
in interface MutableGenericEntity<ID>
version
- is the new value of GenericEntity.getModificationCounter()
.public Number getRevision()
RevisionedEntity
latest revision
of an
entity will always return null
. Otherwise this object is a historic entity and it will be
read-only so modifications are NOT permitted.getRevision
in interface RevisionedEntity<ID>
RevisionedEntity.LATEST_REVISION
(null
) if this is the latest revision.public void setRevision(Number revision)
MutableRevisionedEntity
revision
of this entity. setRevision
in interface MutableRevisionedEntity<ID>
revision
- is the new value of RevisionedEntity.getRevision()
.public int hashCode()
hashCode
in class AbstractTransferObject
public boolean equals(Object obj)
equals
in class AbstractTransferObject
protected void toString(StringBuilder buffer)
AbstractTransferObject.toString()
logic.toString
in class AbstractTransferObject
buffer
- is the StringBuilder
where to append
the string
representation.private void writeobject(ObjectOutputStream o) throws IOException
o
- is the ObjectOutputStream
where to write the serialized object data to.IOException
- in case of an I/O error.Copyright © 2001–2016 mmm-Team. All rights reserved.