Package org.minijax.dao
Class DefaultBaseEntity
- java.lang.Object
-
- org.minijax.dao.DefaultBaseEntity
-
- All Implemented Interfaces:
Serializable,BaseEntity
- Direct Known Subclasses:
DefaultNamedEntity
@MappedSuperclass public abstract class DefaultBaseEntity extends Object implements BaseEntity
The BaseEntity class is the abstract base class for all web primitives. ID's are set by the class. ID's are *not* populated by JPA. For background:- https://stackoverflow.com/questions/5031614/the-jpa-hashcode-equals-dilemma
- http://www.onjava.com/pub/a/onjava/2006/09/13/dont-let-hibernate-steal-your-identity.html
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDefaultBaseEntity()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends DefaultBaseEntity>
voidcopyNonNullProperties(T other)Copies all non-null properties from the other object to this object.booleanequals(Object obj)Determines if this object equals another.static <T extends DefaultBaseEntity>
TfromJson(Class<T> c, String str)InstantgetCreatedDateTime()Returns the date/time when the object was created in the database.InstantgetDeletedDateTime()Returns the date/time when the object was last deleted in the database.UUIDgetId()Returns the ID of the object.InstantgetUpdatedDateTime()Returns the date/time when the object was last updated in the database.inthashCode()Returns a hash code for this details object.booleanisDeleted()Returns whether the object is deleted.voidonPrePersist()voidonPreUpdate()voidsetCreatedDateTime(Instant createdDateTime)Sets the date/time when the object was created in the database.voidsetDeleted(boolean deleted)Marks the entity as deleted.voidsetId(UUID id)Sets the ID of the object.voidsetUpdatedDateTime(Instant updatedDateTime)Sets the date/time when the object was last updated in the database.StringtoJson()
-
-
-
Method Detail
-
getId
public UUID getId()
Returns the ID of the object.- Specified by:
getIdin interfaceBaseEntity- Returns:
-
setId
public void setId(UUID id)
Sets the ID of the object.- Specified by:
setIdin interfaceBaseEntity- Parameters:
id-
-
getCreatedDateTime
public Instant getCreatedDateTime()
Returns the date/time when the object was created in the database.- Specified by:
getCreatedDateTimein interfaceBaseEntity- Returns:
- The created date/time.
-
setCreatedDateTime
public void setCreatedDateTime(Instant createdDateTime)
Sets the date/time when the object was created in the database.- Parameters:
createdDateTime- The created date/time.
-
getUpdatedDateTime
public Instant getUpdatedDateTime()
Returns the date/time when the object was last updated in the database.- Specified by:
getUpdatedDateTimein interfaceBaseEntity- Returns:
- The updated date/time.
-
setUpdatedDateTime
public void setUpdatedDateTime(Instant updatedDateTime)
Sets the date/time when the object was last updated in the database.- Parameters:
updatedDateTime- The updated date/time.
-
isDeleted
public boolean isDeleted()
Returns whether the object is deleted. Data is never truly deleted from the database. It is the responsibility of all application logic to enforce the deleted flag as appropriate.- Specified by:
isDeletedin interfaceBaseEntity- Returns:
- True if the object is deleted.
-
setDeleted
public void setDeleted(boolean deleted)
Marks the entity as deleted. Shortcut forsetDeletedDateTime(Instant.now()).- Specified by:
setDeletedin interfaceBaseEntity- Parameters:
deleted- True if the object is deleted.
-
getDeletedDateTime
public Instant getDeletedDateTime()
Returns the date/time when the object was last deleted in the database. Data is never truly deleted from the database. It is the responsibility of all application logic to enforce the deleted flag as appropriate.- Specified by:
getDeletedDateTimein interfaceBaseEntity- Returns:
- The deleted date/time.
-
onPrePersist
public void onPrePersist()
-
onPreUpdate
public void onPreUpdate()
-
hashCode
public int hashCode()
Returns a hash code for this details object. The hash code is completely based on the ID. If a deriving class expects to mix/match several classes within a hash table, then you should override and replace this.
-
equals
public boolean equals(Object obj)
Determines if this object equals another. Equality is defined as same class type and same ID.
-
toJson
public String toJson()
-
fromJson
public static <T extends DefaultBaseEntity> T fromJson(Class<T> c, String str)
-
copyNonNullProperties
public <T extends DefaultBaseEntity> void copyNonNullProperties(T other)
Copies all non-null properties from the other object to this object.- Parameters:
other- The other entity.
-
-