Package org.pidome.server.entities.base
Class BaseEntity
java.lang.Object
org.pidome.server.entities.base.BaseEntity
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
HostBoundEntity
,HostIdentification
,ItemDefinition
,Manufacturer
,MobileDevice
,ModuleLoaderConfiguration
,Person
,PidomeTokenContainer
,Premises
,Property
,PropertyLevel
,RegionSection
,Repository
,RepositoryContainer
,ServerPackage
,UserConstraint
,UserLogin
,UserRole
The base entity for all entities.
- See Also:
- Serialized Form
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends BaseEntity>
voidReturns a single entity.static <T extends BaseEntity>
voiddelete(T entity)
Returns a single entity.boolean
Equality check.getAllEntityFields(Class klazz)
Returns all fields in a class including it's superclass.Creation date.getId()
static <T extends BaseEntity>
Collection<T>For returning a list of type T without any transactions in it's own isolated manager instance.static <T extends BaseEntity>
Collection<T>getList(Class<T> klazz, Database.AutoClosableEntityManager manager)
Return a list of entities requested by klazz of type T.static <T extends BaseEntity>
TReturns a single entity.Last modified date.Entity version.int
hashCode()
Generate hash code.boolean
isNew()
Returns if the entity is a new entity or not.void
Called before persisting.void
Called before updating.void
save()
Saves the entity to the database.void
setCreated(LocalDateTime created)
Creation date.void
void
setUpdated(LocalDateTime updated)
Last modified date.void
setVersion(Integer version)
Entity version.toString()
This entity to a string representation.<T extends BaseEntity>
Tupdate(T entity)
Updates the current entity with the given entity.
-
Constructor Details
-
BaseEntity
public BaseEntity()
-
-
Method Details
-
prePersist
public void prePersist()Called before persisting. -
preUpdate
public void preUpdate()Called before updating. -
getId
- Returns:
- the id.
-
setId
- Parameters:
id
- the id to set.
-
getVersion
Entity version.- Returns:
- the version.
-
setVersion
Entity version.- Parameters:
version
- the version to set.
-
getCreated
Creation date.- Returns:
- the created.
-
setCreated
Creation date.- Parameters:
created
- the created to set.
-
getUpdated
Last modified date.- Returns:
- the updated.
-
setUpdated
Last modified date.- Parameters:
updated
- the updated to set.
-
isNew
public boolean isNew()Returns if the entity is a new entity or not.- Returns:
- boolean true if new.
-
save
public void save()Saves the entity to the database.This method does both persist a new object to the database as updating the object.
-
update
Updates the current entity with the given entity.This method merges the given object with this object. This means only changed fields are required to be supplied next to the same id. If the object itself is updated, please use save.
- Type Parameters:
T
- The Object type.- Parameters:
entity
- The entity to update this entity with, must match the object type on which update is called.- Returns:
- The entity updated.
-
hashCode
public final int hashCode()Generate hash code. -
equals
Equality check. -
toString
This entity to a string representation. -
getsingle
Returns a single entity.- Type Parameters:
T
- The class type.- Parameters:
klazz
- The class to create object for.primaryId
- The primary of the entity to retrieve.- Returns:
- The object when available.
-
delete
Returns a single entity.- Type Parameters:
T
- The class type.- Parameters:
entity
- The entity to delete.
-
delete
Returns a single entity.- Type Parameters:
T
- The class type.- Parameters:
entityClass
- The entity class for which to delete.entityId
- The entity UUID of the entity to remove.
-
getList
For returning a list of type T without any transactions in it's own isolated manager instance.Be aware that when entities are returned by this method they are detached.
- Type Parameters:
T
- The type to return in the list.- Parameters:
klazz
- The class of the entities to be returned.- Returns:
- The list of entities requested.
-
getList
public static <T extends BaseEntity> Collection<T> getList(Class<T> klazz, Database.AutoClosableEntityManager manager)Return a list of entities requested by klazz of type T.Using this method allows to perform more actions on the entities.
- Type Parameters:
T
- The type to return in the list.- Parameters:
klazz
- The class of the entities to be returned.manager
- the auto closable manager as given byDatabase.getInstance().getNewAutoClosableManager()
- Returns:
- The list of entities requested.
-
getAllEntityFields
Returns all fields in a class including it's superclass.- Parameters:
klazz
- The class to fetch from.- Returns:
- List of fields
-