Class DbObjectSchema

java.lang.Object
tech.ailef.dbadmin.external.dbmapping.DbObjectSchema

public class DbObjectSchema extends Object
A class that represents a table/`@Entity` as reconstructed from the JPA annotations found on its fields.
  • Constructor Details

    • DbObjectSchema

      public DbObjectSchema(Class<?> klass, DbAdmin dbAdmin)
      Initializes this schema for the specific `@Entity` class. Determines the table name from the `@Table` annotation and also which methods are `@ComputedColumn`s
      Parameters:
      klass - the `@Entity` class
      dbAdmin - the DbAdmin instance
  • Method Details

    • getBasePackage

      public String getBasePackage()
    • getDbAdmin

      public DbAdmin getDbAdmin()
      Returns the DbAdmin instance
      Returns:
      the DbAdmin instance
    • getJavaClass

      public Class<?> getJavaClass()
      Returns the Java class for the underlying `@Entity` this schema corresponds to
      Returns:
      the Java class for the `@Entity` this schema corresponds to
    • getClassName

      public String getClassName()
      Returns the name of the Java class for the underlying `@Entity` this schema corresponds to
      Returns:
      the name of the Java class for the `@Entity` this schema corresponds to
    • getFields

      public List<DbField> getFields()
      Returns an unmodifiable list of all the fields in the schema
      Returns:
      an unmodifiable list of all the fields in the schema
    • getErrors

      public List<MappingError> getErrors()
    • getFieldByJavaName

      public DbField getFieldByJavaName(String name)
      Get a field by its Java name, i.e. the name of the instance variable in the `@Entity` class
      Parameters:
      name - name of the instance variable
      Returns:
      the DbField if found, null otherwise
    • getFieldByName

      public DbField getFieldByName(String name)
      Get a field by its database name, i.e. the name of the column corresponding to the field
      Parameters:
      name - name of the column
      Returns:
      the DbField if found, null otherwise
    • addField

      public void addField(DbField f)
      Adds a field to this schema. This is used by the DbAdmin instance during initialization and it's not supposed to be called afterwards
      Parameters:
      f - the DbField to add
    • addError

      public void addError(MappingError error)
    • getJpaRepository

      public CustomJpaRepository getJpaRepository()
      Returns the underlying CustomJpaRepository
      Returns:
    • setJpaRepository

      public void setJpaRepository(CustomJpaRepository jpaRepository)
      Sets the underlying CustomJpaRepository
      Parameters:
      jpaRepository -
    • getTableName

      public String getTableName()
      Returns the inferred table name for this schema
      Returns:
    • getSortedFields

      public List<DbField> getSortedFields()
      Returns:
    • getSortedFields

      public List<DbField> getSortedFields(boolean readOnly)
      Returns a sorted list of physical fields (i.e., fields that correspond to a column in the table as opposed to fields that are just present as instance variables, like relationship fields). Sorted alphabetically with priority the primary key, and non nullable fields. If readOnly is true, `@HiddenColumn`s are not returned. If instead readOnly is false, i.e. how it gets called in the create/edit page, hidden columns are included if they are not nullable.
      Parameters:
      readOnly - whether we only need to read the fields are create/edit
      Returns:
    • getRelationshipFields

      public List<DbField> getRelationshipFields()
      Returns the list of relationship fields
      Returns:
    • getManyToManyOwnedFields

      public List<DbField> getManyToManyOwnedFields()
      Returns the list of ManyToMany fields owned by this class (i.e. they do not have "mappedBy")
      Returns:
    • getPrimaryKey

      public DbField getPrimaryKey()
      Returns the DbField which serves as the primary key for this schema
      Returns:
    • getComputedColumnNames

      public List<String> getComputedColumnNames()
      Returns the names of the `@ComputedColumn`s in this schema
      Returns:
    • getComputedColumn

      public Method getComputedColumn(String name)
      Returns the method for the given `@ComputedColumn` name
      Parameters:
      name - the name of the `@ComputedColumn`
      Returns:
      the corresponding instance method if found, null otherwise
    • getFilterableFields

      public List<DbField> getFilterableFields()
      Returns the list of fields that are `@Filterable`
      Returns:
    • isDeleteEnabled

      public boolean isDeleteEnabled()
    • isEditEnabled

      public boolean isEditEnabled()
    • isCreateEnabled

      public boolean isCreateEnabled()
    • findAll

      public List<DbObject> findAll()
      Returns all the data in this schema, as `DbObject`s
      Returns:
    • buildObject

      public DbObject buildObject(Map<String,String> params, Map<String,org.springframework.web.multipart.MultipartFile> files)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object