Class DataHolder

java.lang.Object
de.chojo.sqlutil.base.DataHolder
All Implemented Interfaces:
DataSourceProvider
Direct Known Subclasses:
QueryBuilder, QueryFactoryHolder

public abstract class DataHolder extends Object implements DataSourceProvider
Base class which can be used for classes which call the database.

Provides convinience methods for connection retrieval, logging and a querybuilder.

You may use a QueryBuilderFactory for builder creation or extend QueryFactoryHolder

  • Constructor Details

    • DataHolder

      public DataHolder(DataSource dataSource)
      Create a new DataHolder
      Parameters:
      dataSource - data source
  • Method Details

    • setupLogger

      public static void setupLogger(LoggerAdapter adapter)
      Setup the logger used for logging.
      Parameters:
      adapter - logger adapter
    • queryBuilder

      protected <T> ConfigurationStage<T> queryBuilder(Class<T> clazz)
      Get a query builder for easy sql execution.
      Type Parameters:
      T - type of result
      Parameters:
      clazz - clazz which should be retrieved. Doesnt matter if you want a list and multiple results or not.
      Returns:
      query builder in a query stage
    • logDbError

      public void logDbError(String message, SQLException e)
      Logs the exception with a message
      Parameters:
      message - message
      e - exception
    • logDbError

      public void logDbError(SQLException e)
      Logs the exception with a default message.
      Parameters:
      e - exception
    • getConnection

      public Connection getConnection() throws SQLException
      Attempts to establish a connection with the data source that this DataSource object represents.
      Returns:
      a connection to the data source
      Throws:
      SQLException - if a database access error occurs
      SQLTimeoutException - when the driver has determined that the timeout value specified by the setLoginTimeout method has been exceeded and has at least tried to cancel the current database connection attempt
    • source

      public DataSource source()
      Specified by:
      source in interface DataSourceProvider