Class SqlDataSource<T>

java.lang.Object
edu.ie3.datamodel.io.source.sql.SqlDataSource<T>
Direct Known Subclasses:
SqlTimeSeriesMappingSource, SqlTimeSeriesMetaInformationSource, SqlTimeSeriesSource, SqlWeatherSource

public abstract class SqlDataSource<T> extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static String
    createBaseQueryString(String schemaName, String tableName)
    Creates a base query string without closing semicolon of the following pattern:
    SELECT * FROM <schema>.<table>
    protected abstract Optional<T>
    createEntity(Map<String,String> fieldToValues)
    Instantiates an entity produced by this source given the required field value map.
    protected List<T>
    executeQuery(String query, edu.ie3.datamodel.io.source.sql.SqlDataSource.AddParams addParams)
    Executes the prepared statement after possibly adding parameters to the query using the given function.
    protected String
    getDbColumnName(String factoryColumnName, String tableName)
    Determine the corresponding database column name based on the provided factory field parameter name.
    protected List<String>
    getDbTables(String schemaPattern, String tableNamePattern)
    Determine the corresponding table names based on the provided table name pattern.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      protected static final org.slf4j.Logger log
  • Constructor Details

    • SqlDataSource

      protected SqlDataSource(SqlConnector connector)
  • Method Details

    • createBaseQueryString

      protected static String createBaseQueryString(String schemaName, String tableName)
      Creates a base query string without closing semicolon of the following pattern:
      SELECT * FROM <schema>.<table>
      Parameters:
      schemaName - the name of the database schema
      tableName - the name of the database table
      Returns:
      basic query string without semicolon
    • getDbColumnName

      protected String getDbColumnName(String factoryColumnName, String tableName)
      Determine the corresponding database column name based on the provided factory field parameter name. Needed to support camel as well as snake case database column names.
      Parameters:
      factoryColumnName - the name of the field parameter set in the entity factory
      tableName - the table name where the data is stored
      Returns:
      the column name that corresponds to the provided field parameter or an empty optional if no matching column can be found
    • getDbTables

      protected List<String> getDbTables(String schemaPattern, String tableNamePattern)
      Determine the corresponding table names based on the provided table name pattern.
      Parameters:
      schemaPattern - pattern of the schema to search in
      tableNamePattern - pattern of the table name
      Returns:
      matching table names
    • executeQuery

      protected List<T> executeQuery(String query, edu.ie3.datamodel.io.source.sql.SqlDataSource.AddParams addParams)
      Executes the prepared statement after possibly adding parameters to the query using the given function. Finally, processes the results and creates a list of time based values via field map extraction.
      Parameters:
      query - the query to use
      addParams - function that possibly adds parameters to query
      Returns:
      a list of resulting entities
    • createEntity

      protected abstract Optional<T> createEntity(Map<String,String> fieldToValues)
      Instantiates an entity produced by this source given the required field value map.
      Parameters:
      fieldToValues - map of fields to their respective values
      Returns:
      the entity if instantiation succeeds