Class BaseEntity

java.lang.Object
org.pidome.server.entities.base.BaseEntity
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
HostBoundEntity, HostIdentification, ItemDefinition, Manufacturer, MobileDevice, ModuleLoaderConfiguration, Person, PidomeAuthToken, Premises, Property, PropertyLevel, RegionSection, Repository, RepositoryContainer, ServerPackage, UserLogin

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

    Constructors 
    Constructor Description
    BaseEntity()  
  • Method Summary

    Modifier and Type Method Description
    static <T extends BaseEntity>
    void
    delete​(java.lang.Class<T> entityClass, java.util.UUID entityId)
    Returns a single entity.
    static <T extends BaseEntity>
    void
    delete​(T entity)
    Returns a single entity.
    boolean equals​(java.lang.Object obj)
    Equality check.
    static java.util.Set<java.lang.reflect.Field> getAllEntityFields​(java.lang.Class klazz)
    Returns all fields in a class including it's superclass.
    java.time.LocalDateTime getCreated()
    Creation date.
    java.util.UUID getId()  
    static <T extends BaseEntity>
    java.util.Collection<T>
    getList​(java.lang.Class<T> klazz)
    For returning a list of type T without any transactions in it's own isolated manager instance.
    static <T extends BaseEntity>
    java.util.Collection<T>
    getList​(java.lang.Class<T> klazz, Database.AutoClosableEntityManager manager)
    Return a list of entities requested by klazz of type T.
    static <T extends BaseEntity>
    T
    getsingle​(java.lang.Class<T> klazz, java.util.UUID primaryId)
    Returns a single entity.
    java.time.LocalDateTime getUpdated()
    Last modified date.
    java.lang.Integer getVersion()
    Entity version.
    int hashCode()
    Generate hash code.
    boolean isNew()
    Returns if the entity is a new entity or not.
    void prePersist()
    Called before persisting.
    void preUpdate()
    Called before updating.
    void save()
    Saves the entity to the database.
    void setCreated​(java.time.LocalDateTime created)
    Creation date.
    void setId​(java.util.UUID id)  
    void setUpdated​(java.time.LocalDateTime updated)
    Last modified date.
    void setVersion​(java.lang.Integer version)
    Entity version.
    java.lang.String toString()
    This entity to a string representation.
    <T extends BaseEntity>
    T
    update​(T entity)
    Updates the current entity with the given entity.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • prePersist

      public void prePersist()
      Called before persisting.
    • preUpdate

      public void preUpdate()
      Called before updating.
    • getId

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

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

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

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

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

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

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

      public void setUpdated​(java.time.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 java.lang.Object
      Returns:
      The object hash.
    • equals

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

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

      public static <T extends BaseEntity> T getsingle​(java.lang.Class<T> klazz, java.util.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​(java.lang.Class<T> entityClass, java.util.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> java.util.Collection<T> getList​(java.lang.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> java.util.Collection<T> getList​(java.lang.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 java.util.Set<java.lang.reflect.Field> getAllEntityFields​(java.lang.Class klazz)
      Returns all fields in a class including it's superclass.
      Parameters:
      klazz - The class to fetch from.
      Returns:
      List of fields