Interface DatabasePojo

All Superinterfaces:
com.github.tadukoo.util.pojo.MappedPojo
All Known Implementing Classes:
AbstractDatabasePojo

public interface DatabasePojo extends com.github.tadukoo.util.pojo.MappedPojo
Database Pojo represents a MappedPojo that can be used with a Database, to store and retrieve values from the Database as needed.
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Method Details

    • getTableName

      String getTableName()
      Returns:
      The name of the table for this pojo
    • getIDColumnName

      String getIDColumnName()
      Returns:
      The name of the ID column for this pojo
    • getColumnDefs

      Map<String,ColumnDefinition> getColumnDefs()
      Returns:
      A Map of all the column definitions in this pojo
    • getSubPojoDefs

      Map<String,SubPojoDefinition> getSubPojoDefs()
      Returns:
      A Map of all subPojo definitions in this pojo
    • getSubPojoKeys

      default Set<String> getSubPojoKeys()
      Returns:
      The keys for any pojos stored inside this pojo
    • getSubPojoDefBySubPojoKey

      default SubPojoDefinition getSubPojoDefBySubPojoKey(String subPojoKey)
      Parameters:
      subPojoKey - The subPojoKey to use to find a subPojoDefinition
      Returns:
      The SubPojoDefinition for the given subPojoKey
    • getForeignKeys

      List<ForeignKeyConstraint> getForeignKeys()
      Returns:
      The List of foreign keys for this pojo
    • addForeignKey

      default void addForeignKey(ForeignKeyConstraint foreignKey)
      Adds the given foreign key to this pojo
      Parameters:
      foreignKey - The foreign key to be added to the pojo
    • addSubPojo

      default void addSubPojo(SubPojoDefinition subPojoDef, DatabasePojo subPojo, ForeignKeyConstraint foreignKey)
      Adds the info for a subPojo using the given parameters
      Parameters:
      subPojoDef - The SubPojoDefinition to be added to this pojo
      subPojo - The subPojo itself to be stored (may be null)
      foreignKey - The foreign key for the subPojo (to use when setting up the table)
    • addColumnDef

      default void addColumnDef(ColumnDefinition columnDef)
      Adds the given ColumnDefinition to the Map of column definitions
      Parameters:
      columnDef - The ColumnDefinition to add to the Map
    • addColumnDef

      default void addColumnDef(ColumnDefinition columnDef, Object value)
      Adds the given ColumnDefinition to the Map of column definitions and sets the column value to the given value
      Parameters:
      columnDef - The ColumnDefinition to add to the Map
      value - The value to set for the column
    • setDefaultColumnDefs

      void setDefaultColumnDefs()
      Should be called in the constructor of a DatabasePojo and be used to create the column definitions
    • getColumnDefKeys

      default Set<String> getColumnDefKeys()
      Returns:
      The Set of column definition keys
    • getColumnDefByKey

      default ColumnDefinition getColumnDefByKey(String key)
      Retrieve a ColumnDefinition from the Map using the given key
      Parameters:
      key - The key for the ColumnDefinition
      Returns:
      The ColumnDefinition from the Map
    • createTable

      default void createTable(Database database) throws SQLException
      Create a table for this pojo on the given Database
      Parameters:
      database - The Database to create the table on
      Throws:
      SQLException - If something goes wrong in creating the table
    • retrieveValues

      default void retrieveValues(Database database, boolean retrieveSubPojos) throws SQLException
      Retrieves all the values for the pojo from the database, using the stored id column value
      Parameters:
      database - The Database to retrieve values from
      retrieveSubPojos - Whether to also retrieve values for subPojos or not
      Throws:
      SQLException - If anything goes wrong in retrieving values
    • retrieveValues

      default void retrieveValues(Database database, Object idColumnValue, boolean retrieveSubPojos) throws SQLException
      Retrieves all the values for the pojo from the database, using the given id column value
      Parameters:
      database - The Database to retrieve values from
      idColumnValue - The ID column value to be used
      retrieveSubPojos - Whether to also retrieve values for subPojos or not
      Throws:
      SQLException - If anything goes wrong in retrieving values
    • getResultSetFunc

      default com.github.tadukoo.util.functional.function.ThrowingFunction<ResultSet,Boolean,SQLException> getResultSetFunc()
      Returns:
      A ThrowingFunction to use to extract a single DatabasePojo from a ResultSet
    • getResultSetListFunc

      default <P extends DatabasePojo> com.github.tadukoo.util.functional.function.ThrowingFunction<ResultSet,List<P>,SQLException> getResultSetListFunc(Class<P> clazz)
      This ThrowingFunction is used to extract a List of DatabasePojos from a ResultSet (e.g. from a search).
      Type Parameters:
      P - The DatabasePojo class to be used for the List
      Parameters:
      clazz - The DatabasePojo class to be used for the List
      Returns:
      A ThrowingFunction that extracts a List of DatabasePojos from a ResultSet
    • storeValues

      default Integer storeValues(Database database, boolean storeSubPojos) throws SQLException
      Stores the values from this DatabasePojo into the given Database. Specifying storeSubPojos will also store values on any subPojos stored in this pojo
      Parameters:
      database - The Database to store values in
      storeSubPojos - Whether to store values on subPojos or not
      Returns:
      The new ID for the DatabasePojo if it was freshly inserted to the Database
      Throws:
      SQLException - If anything goes wrong in storing values
    • doSearch

      default <P extends DatabasePojo> List<P> doSearch(Database database, Class<P> clazz, boolean useSubPojos) throws SQLException
      Performs a search for data on pojos of this type in the given Database. The given class is for which class of pojos to return and the boolean determines whether to use all the subPojos stored in this pojo true in this search or use none of them false
      Type Parameters:
      P - The DatabasePojo class to use for the returned pojos
      Parameters:
      database - The Database to do the search on
      clazz - The DatabasePojo class to use for the returned pojos
      useSubPojos - Whether to use all subPojos true or none false in the search
      Returns:
      A List of pojos found from the search
      Throws:
      SQLException - If anything goes wrong in doing the search
    • doSearch

      default <P extends DatabasePojo> List<P> doSearch(Database database, Class<P> clazz, Collection<String> subPojosToUse) throws SQLException
      Performs a search for data on pojos of this type in the given Database. The given class is for which class of pojos to return and the collection of subPojo strings is for subPojoKeys of subPojos to be used in the search (so long as they're non-null)
      Type Parameters:
      P - The DatabasePojo class to use for the returned pojos
      Parameters:
      database - The Database to do the search on
      clazz - The DatabasePojo class to use for the returned pojos
      subPojosToUse - The subPojoKeys of subPojos to use in the search
      Returns:
      A List of pojos found from the search
      Throws:
      SQLException - If anything goes wrong in doing the search