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

@MappedSuperclass public class BaseEntity extends Object implements Serializable
The base entity for all entities.
See Also:
Serialized Form
  • Constructor Details

    • BaseEntity

      public BaseEntity()
  • Method Details

    • prePersist

      public void prePersist()
      Called before persisting.
    • preUpdate

      public void preUpdate()
      Called before updating.
    • getId

      public UUID getId()
      Returns:
      the id.
    • setId

      public void setId(UUID id)
      Parameters:
      id - the id to set.
    • getVersion

      public Integer getVersion()
      Entity version.
      Returns:
      the version.
    • setVersion

      public void setVersion(Integer version)
      Entity version.
      Parameters:
      version - the version to set.
    • getCreated

      public LocalDateTime getCreated()
      Creation date.
      Returns:
      the created.
    • setCreated

      public void setCreated(LocalDateTime created)
      Creation date.
      Parameters:
      created - the created to set.
    • getUpdated

      public LocalDateTime getUpdated()
      Last modified date.
      Returns:
      the updated.
    • setUpdated

      public void setUpdated(LocalDateTime updated)
      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

      public final <T extends BaseEntity> T update(T entity)
      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.
      Overrides:
      hashCode in class Object
      Returns:
      The object hash.
    • equals

      public final boolean equals(Object obj)
      Equality check.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to check.
      Returns:
      If equals.
    • toString

      public String toString()
      This entity to a string representation.
      Overrides:
      toString in class Object
      Returns:
      The entity as string.
    • getsingle

      public static <T extends BaseEntity> T getsingle(Class<T> klazz, UUID primaryId)
      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

      public static <T extends BaseEntity> void delete(T entity)
      Returns a single entity.
      Type Parameters:
      T - The class type.
      Parameters:
      entity - The entity to delete.
    • delete

      public static <T extends BaseEntity> void delete(Class<T> entityClass, UUID entityId)
      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

      public static <T extends BaseEntity> Collection<T> getList(Class<T> klazz)
      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 by Database.getInstance().getNewAutoClosableManager()
      Returns:
      The list of entities requested.
    • getAllEntityFields

      public static Set<Field> getAllEntityFields(Class klazz)
      Returns all fields in a class including it's superclass.
      Parameters:
      klazz - The class to fetch from.
      Returns:
      List of fields