Class BaseJdbcRepository

java.lang.Object
org.hawaiiframework.repository.BaseJdbcRepository

public class BaseJdbcRepository extends Object
Base class for JDBC repositories.

Contains the SQL query resolver and methods to obtain Spring JDBC templates.

  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseJdbcRepository(SqlQueryResolver queryResolver, DataSource dataSource)
    Constructor with a query resolver and a data source.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <T> T
    get(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
    Throws an EmptyResultDataAccessException in case the result set is empty.
    protected <T> T
    get(String query, org.springframework.jdbc.core.RowMapper<T> rowMapper)
    Throws an EmptyResultDataAccessException in case the result set is empty.
    protected <T> List<T>
    getList(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
    Throws an EmptyResultDataAccessException in case the result set is empty.
    protected <T> T
    getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, Class<T> requiredType)
    Method to handle an EmptyResultDataAccessException using a type.
    protected <T> T
    getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.ResultSetExtractor<T> extractor)
    Method to handle an EmptyResultDataAccessException using a row mapper.
    protected <T> T
    getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
    Method to handle an EmptyResultDataAccessException using a row mapper.
    protected org.springframework.jdbc.core.JdbcTemplate
     
    protected org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
     
    protected String
    resolveQuery(String sqlQueryName)
    Use the SqlQueryResolver to resolve the given query.
    protected int
    update(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters)
    Perform the 'update' query (insert, update, delete).

    Methods inherited from class java.lang.Object

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

    • BaseJdbcRepository

      public BaseJdbcRepository(SqlQueryResolver queryResolver, DataSource dataSource)
      Constructor with a query resolver and a data source.
      Parameters:
      queryResolver - The SQL query resolver.
      dataSource - The datasource to use.
  • Method Details

    • resolveQuery

      protected String resolveQuery(String sqlQueryName)
      Use the SqlQueryResolver to resolve the given query.
      Parameters:
      sqlQueryName - the name of the query to resolve from the path.
      Returns:
      the query string.
    • jdbcTemplate

      protected org.springframework.jdbc.core.JdbcTemplate jdbcTemplate()
      Returns:
      the JDBC template.
    • namedParameterJdbcTemplate

      protected org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate namedParameterJdbcTemplate()
      Returns:
      the named parameter template.
    • getOpt

      protected <T> T getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
      Method to handle an EmptyResultDataAccessException using a row mapper.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      rowMapper - the row mapper to use.
      Returns:
      the requested type or null in case of an EmptyResultDataAccessException.
    • getOpt

      protected <T> T getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, Class<T> requiredType)
      Method to handle an EmptyResultDataAccessException using a type.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      requiredType - the required type for the query.
      Returns:
      the requested type or null in case of an EmptyResultDataAccessException.
    • getOpt

      protected <T> T getOpt(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.ResultSetExtractor<T> extractor)
      Method to handle an EmptyResultDataAccessException using a row mapper.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      extractor - result set extractor to use.
      Returns:
      the requested type or null in case of an EmptyResultDataAccessException.
    • get

      protected <T> T get(String query, org.springframework.jdbc.core.RowMapper<T> rowMapper)
      Throws an EmptyResultDataAccessException in case the result set is empty.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      rowMapper - the row mapper to use.
      Returns:
      the requested type or an EmptyResultDataAccessException.
    • get

      protected <T> T get(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
      Throws an EmptyResultDataAccessException in case the result set is empty.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      rowMapper - the row mapper to use.
      Returns:
      the requested type or an EmptyResultDataAccessException.
    • update

      protected int update(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters)
      Perform the 'update' query (insert, update, delete).
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      Returns:
      the number of rows affected
      Throws:
      org.springframework.dao.DataAccessException - if there is any problem issuing the update
    • getList

      protected <T> List<T> getList(String query, org.springframework.jdbc.core.namedparam.SqlParameterSource parameters, org.springframework.jdbc.core.RowMapper<T> rowMapper)
      Throws an EmptyResultDataAccessException in case the result set is empty.
      Type Parameters:
      T - the type to return.
      Parameters:
      query - query to use.
      parameters - parameters to add to the query.
      rowMapper - the row mapper to use.
      Returns:
      the requested type or an EmptyResultDataAccessException.