Class JKEntity

java.lang.Object
com.jk.data.dataaccess.orm.JKEntity
All Implemented Interfaces:
Serializable

public class JKEntity extends Object implements Serializable
This class provides common functionality and annotations for entity classes.

Entities that extend this class are expected to include annotations such as `@Id`, `@GeneratedValue`, and `@Column` for mapping to database tables.

This class offers utility methods for working with entities, such as retrieving table name, column information, and sorting information.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    This method constructs a new JKEntity.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Indicates whether some other object is "equal to" this one.
    This method retrieves the alias name for this entity class.
    getColumns(Class<? extends JKEntity> clas)
    This method retrieves a list of column wrappers for the columns in the specified entity class.
    jakarta.persistence.Column
    This method retrieves the first column in this entity class that is not marked as the primary key.
    This method gets the column wrapper representing the primary key (ID column) for this JKEntity class.
    getIdColumn(Class<? extends JKEntity> clas)
    This method gets the column wrapper representing the primary key (ID column) for the specified JKEntity class.
    <T> T
    This method gets the value of the primary key (ID) field for this entity.
    static JKSortInfo
    getSortInfo(Class<? extends JKEntity> clas)
    This method retrieves the sort information associated with a class.
    This method gets the primary table name of this entity.
    int
    Returns a hash code value for the object.
    static void
    This method prints the annotations applied to a given field.
    void
    This method prints the annotations of fields within the current JKEntity class.
    Returns a string representation of the object.

    Methods inherited from class java.lang.Object

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

    • JKEntity

      public JKEntity()
      This method constructs a new JKEntity.
  • Method Details

    • getTableName

      public String getTableName()
      This method gets the primary table name of this entity.
      Returns:
      the primary table name of this entity.
    • getIdValue

      public <T> T getIdValue()
      This method gets the value of the primary key (ID) field for this entity.
      Type Parameters:
      T - Specifies the type of the primary key value.
      Returns:
      the value of the primary key field.
    • getFirstNonIdColumn

      public jakarta.persistence.Column getFirstNonIdColumn()
      This method retrieves the first column in this entity class that is not marked as the primary key.
      Returns:
      the first non-primary key column in the entity class, or null if none was found.
    • getColumns

      public static List<JKColumnWrapper> getColumns(Class<? extends JKEntity> clas)
      This method retrieves a list of column wrappers for the columns in the specified entity class.
      Parameters:
      clas - Specifies the entity class for which to retrieve the columns.
      Returns:
      a list of column wrappers representing the columns in the entity class.
    • getIdColumn

      public JKColumnWrapper getIdColumn()
      This method gets the column wrapper representing the primary key (ID column) for this JKEntity class.
      Returns:
      a JKColumnWrapper representing the primary key column.
    • getIdColumn

      public static JKColumnWrapper getIdColumn(Class<? extends JKEntity> clas)
      This method gets the column wrapper representing the primary key (ID column) for the specified JKEntity class.
      Parameters:
      clas - Specifies the JKEntity class for which to retrieve the ID column.
      Returns:
      a JKColumnWrapper representing the primary key column.
    • printFieldsAnnotations

      public void printFieldsAnnotations()
      This method prints the annotations of fields within the current JKEntity class.
    • printFieldAnnotations

      public static void printFieldAnnotations(Field field)
      This method prints the annotations applied to a given field.
      Parameters:
      field - Specifies the field for which annotations should be printed.
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object.
    • getSortInfo

      public static JKSortInfo getSortInfo(Class<? extends JKEntity> clas)
      This method retrieves the sort information associated with a class.
      Parameters:
      clas - Specifies the class for which sort information is retrieved.
      Returns:
      the sort information associated with the class, or null if none is found.
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one.

      The equals method implements an equivalence relation on non-null object references:

      • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
      • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
      • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
      • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
      • For any non-null reference value x, x.equals(null) should return false.

      An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

      The general contract of hashCode is:

      • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
      • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
      • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this object.
    • getAliasName

      public String getAliasName()
      This method retrieves the alias name for this entity class.
      Returns:
      the alias name, which is the simple name of the class.