sql-dao provides HikariCP pooled connections to the Postgres DB. It creates, manages and authenticates connection to Postgres DB.
Retry on failure in obtaining a connection is implemented with the configurable retry count.
Graceful shutdown of the connection is ensured whenever a connection is closed.
Apart from providing connections, it also provides the below functionalities to a service.
- Health Monitoring of Postgres DB.
- A JDBC template provider to execute queries using JDBC.
- Extensible Credentials provider to fetch credentials from Vault or from environment properties or a customized implementation.
- Metrics exporter to export DB connection pool metrics to Prometheus for reliability.
- Getting Started
- Usage
- How to contribute
- Built with Dependencies
- Code of Conduct
- Authors
- Security Contact Information
- Support
- Troubleshooting
- License
- Announcements
To build the project in the local working directory after the project has been cloned/forked, run:
mvn clean install
from the command line interface.
- Maven
- Java 11
mvn test
Or run a specific test
mvn test -Dtest="TheFirstUnitTest"
To run a method from within a test
mvn test -Dtest="TheSecondUnitTest#whenTestCase2_thenPrintTest2_1"
sql-dao-library project serves as a library for the services. It is not meant to be deployed as a service in any cloud environment.
Add the following dependency in the target project
<dependency>
<groupId>org.eclipse.ecsp</groupId>
<artifactId>sql-dao</artifactId>
<version>1.X.X</version>
</dependency>
The Postgres DB connection properties can be specified in the environment properties as shown below:
postgres.jdbc.url=jdbc:postgresql://localhost:5432/postgres
postgres.username=********
postgres.password=********The JdbcTemplate can be autowired in the implementing service to execute queries as shown below:
import org.springframework.beans.factory.annotation.Qualifier;
@Autowired
@Qualifier("jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void executeQuery() {
jdbcTemplate.query("SELECT * FROM table_name", (rs, rowNum) -> {
// Process the result set
return null;
});
}The health of the Postgres DB is monitored by the PostgresDBHealthMonitor class. To enabled health monitoring, the below configuration needs to be added in the environment properties:
health.postgresdb.monitor.enabled=true
## If graceful restart is required
health.postgresdb.monitor.restart.on.failure=trueTo publish Postgres DB pool metrics to Prometheus server, the below configuration needs to be added in the environment properties:
## To enable postgres DB metrics fetching from PostgresDB connection pool
postgresdb.metrics.enabled=true
## To enable Prometheus metrics publishing
metrics.prometheus.enabled=true
## Prometheus agent port configuration
prometheus.agent.port=9100
prometheus.agent.port.exposed=9100| Dependency | Purpose |
|---|---|
| Ignite Utils | For logging & health monitoring |
| Prometheus HTTP server | For metrics publishing |
| postgresql | For Postgres DB connection |
| HikariCP | For connection pooling |
| Spring Framework | The core spring support |
| Spring Boot | The web framework used |
| Maven | Dependency Management |
| Junit | Testing framework |
| Mockito | Test Mocking framework |
Please read CONTRIBUTING.md for details on our contribution guidelines, and the process for submitting pull requests to us.
Please read CODE_OF_CONDUCT.md for details on our code of conduct.
![]() Kaushal Arora ๐ ๐ |
See also the list of contributors who participated in this project.
Please read SECURITY.md to raise any security related issues.
Please write to us at csp@harman.com
Please read CONTRIBUTING.md for details on how to raise an issue and submit a pull request to us.
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
All updates to this library are documented in our Release Notes and releases. For the versions available, see the tags on this repository.

