Class AbstractEto
- java.lang.Object
-
- com.devonfw.module.basic.common.api.to.AbstractTo
-
- com.devonfw.module.basic.common.api.to.AbstractEto
-
- All Implemented Interfaces:
GenericEntity<Long>,Serializable
- Direct Known Subclasses:
RevisionedEto
public abstract class AbstractEto extends AbstractTo implements GenericEntity<Long>
This is the abstract base class for antransfer-objectthat contains all the data properties of anentitywithout its relations. This is called ETO (entity transfer object). Sometimes in other contexts people also call this DTO (data transfer object).
Here, data properties are the properties using a datatype (immutable value type such asString,Number,Instant, custom-datatype, etc.). Relations of an @link GenericEntity entity} are not contained except forIDsofOneToOnerelations. Instead of usingLongwe recommend to useIdRefto be type-safe and more expressive. For actual relations you will useCTOs to express what set of entities to transfer, load, save, update, etc. without redundancies.
Classes extending this class should carry the suffixEto.- Since:
- 3.0.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractEto.PersistentEntityAccessInner class to grant access to internal persistententityreference of anAbstractEto.
-
Field Summary
Fields Modifier and Type Field Description private Longidprivate intmodificationCounterprivate GenericEntity<Long>persistentEntityprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description AbstractEto()The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LonggetId()intgetModificationCounter()This method gets the current modification-counter of this entity.voidsetId(Long id)voidsetModificationCounter(int version)protected voidtoString(StringBuilder buffer)Method to extendAbstractTo.toString()logic.-
Methods inherited from class com.devonfw.module.basic.common.api.to.AbstractTo
toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
id
private Long id
-
modificationCounter
private int modificationCounter
-
persistentEntity
private transient GenericEntity<Long> persistentEntity
-
-
Method Detail
-
getId
public Long getId()
- Specified by:
getIdin interfaceGenericEntity<Long>- Returns:
- the primary key (unique identifier) of this entity. May be
nullif this entity is transient (not yetsavedin the database). While this method is initially defined in a generic way, it is strongly recommended to useLongas datatype for IDs.
Even if you want to have aString-based business-oriented identifier it is best practice to use aLongas 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 itsstring-representation.
Please note that if your ID has a specific syntax, semantic, formatting rules, etc. you should create a custom datatype for it. If it can easily be mapped to aLongvalue you can still useLonghere and provide a transient getter method that returns the your custom datatype from theLong. - See Also:
Id
-
setId
public void setId(Long id)
- Specified by:
setIdin interfaceGenericEntity<Long>- Parameters:
id- the newprimary key. This method shall typically only be used by technical frameworks such as hibernate.
-
getModificationCounter
public int getModificationCounter()
Description copied from interface:GenericEntityThis method gets the current modification-counter of this entity. Whenever the object gets modified andpersisted, this counter will be increased (typically after the transaction is closed). The initial value after construction is0.
This property is often simply calledversion. However, as this sometimes causes confusion or may conflict with a business property "version", we use the more technical and self-explanatory namemodificationCounter.
If this feature is NOT supported for some reason, this method should always return0.- Specified by:
getModificationCounterin interfaceGenericEntity<Long>- Returns:
- the current modification-counter.
- See Also:
Version,Version
-
setModificationCounter
public void setModificationCounter(int version)
- Specified by:
setModificationCounterin interfaceGenericEntity<Long>- Parameters:
version- the newmodification counter. This method shall typically only be used by technical frameworks such as hibernate.
-
toString
protected void toString(StringBuilder buffer)
Method to extendAbstractTo.toString()logic.- Overrides:
toStringin classAbstractTo- Parameters:
buffer- is theStringBuilderwhere toappendthe string representation.
-
-