generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add graceful shutdown and hikari connection pool (#274)
- Loading branch information
Ricardo Campos
authored
Apr 5, 2024
1 parent
0c3b777
commit 36601b5
Showing
10 changed files
with
162 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...d/src/main/java/ca/bc/gov/restapi/results/oracle/config/OracleGracefulShutdownConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ca.bc.gov.restapi.results.oracle.config; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** This class adds a listener for closing connection gracefully. */ | ||
@Component | ||
public class OracleGracefulShutdownConfig implements ApplicationListener<ContextClosedEvent> { | ||
|
||
@Autowired private EntityManager oracleEntityManager; | ||
|
||
@Override | ||
public void onApplicationEvent(@NonNull ContextClosedEvent event) { | ||
oracleEntityManager.close(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/ca/bc/gov/restapi/results/oracle/config/OracleHikariConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ca.bc.gov.restapi.results.oracle.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** This class holds configurations for the Oracle Hikari connection pool. */ | ||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("spring.datasource.oracle") | ||
public class OracleHikariConfig { | ||
|
||
private String driverClassName; | ||
private String url; | ||
private String username; | ||
private String password; | ||
private long connectionTimeout; | ||
private long idleTimeout; | ||
private long maxLifetime; | ||
private long keepaliveTime; | ||
private String poolName; | ||
private int minimumIdle; | ||
private int maximumPoolSize; | ||
private long leakDetectionThreshold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...c/main/java/ca/bc/gov/restapi/results/postgres/config/PostgresGracefulShutdownConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ca.bc.gov.restapi.results.postgres.config; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** This class adds a listener for closing connection gracefully. */ | ||
@Component | ||
public class PostgresGracefulShutdownConfig implements ApplicationListener<ContextClosedEvent> { | ||
|
||
@Autowired private EntityManager postgresEntityManager; | ||
|
||
@Override | ||
public void onApplicationEvent(@NonNull ContextClosedEvent event) { | ||
postgresEntityManager.close(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/ca/bc/gov/restapi/results/postgres/config/PostgresHikariConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ca.bc.gov.restapi.results.postgres.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** This class holds configurations for the Postgres Hikari connection pool. */ | ||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("spring.datasource.postgres") | ||
public class PostgresHikariConfig { | ||
|
||
private String driverClassName; | ||
private String url; | ||
private String username; | ||
private String password; | ||
private long connectionTimeout; | ||
private long idleTimeout; | ||
private long maxLifetime; | ||
private long keepaliveTime; | ||
private String poolName; | ||
private int minimumIdle; | ||
private int maximumPoolSize; | ||
private long leakDetectionThreshold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters