Package org.hawaiiframework.repository
Class BaseJdbcRepository
java.lang.Object
org.hawaiiframework.repository.BaseJdbcRepository
Base class for JDBC repositories.
Contains the SQL query resolver and methods to obtain Spring JDBC templates.
-
Constructor Summary
ConstructorDescriptionBaseJdbcRepository
(SqlQueryResolver queryResolver, DataSource dataSource) Constructor with a query resolver and a data source. -
Method Summary
Modifier and TypeMethodDescriptionprotected <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
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
Return the JDBC template.protected org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
Return the named parameter template.protected String
resolveQuery
(String sqlQueryName) Use theSqlQueryResolver
to resolve the given query.protected int
Perform the 'update' query (insert, update, delete).
-
Constructor Details
-
BaseJdbcRepository
Constructor with a query resolver and a data source.- Parameters:
queryResolver
- The SQL query resolver.dataSource
- The datasource to use.
-
-
Method Details
-
resolveQuery
Use theSqlQueryResolver
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()Return the JDBC template. -
namedParameterJdbcTemplate
protected org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate namedParameterJdbcTemplate()Return 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
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.
-