Package de.chojo.sqlutil.base
Class DataHolder
java.lang.Object
de.chojo.sqlutil.base.DataHolder
- All Implemented Interfaces:
DataSourceProvider
- Direct Known Subclasses:
QueryBuilder,QueryFactoryHolder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAttempts to establish a connection with the data source that this DataSource object represents.voidlogDbError(String message, SQLException e) Logs the exception with a messagevoidLogs the exception with a default message.protected <T> ConfigurationStage<T>queryBuilder(Class<T> clazz) Get a query builder for easy sql execution.static voidsetupLogger(LoggerAdapter adapter) Setup the logger used for logging.source()
-
Constructor Details
-
DataHolder
Create a new DataHolder- Parameters:
dataSource- data source
-
-
Method Details
-
setupLogger
Setup the logger used for logging.- Parameters:
adapter- logger adapter
-
queryBuilder
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
Logs the exception with a message- Parameters:
message- messagee- exception
-
logDbError
Logs the exception with a default message.- Parameters:
e- exception
-
getConnection
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 occursSQLTimeoutException- 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
- Specified by:
sourcein interfaceDataSourceProvider
-