forked from Luke-Sikina/picsure-search-refinement
-
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.
Temporary datasource verification class
Remove after testing
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.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,39 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.datasource; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
@Service | ||
public class DataSourceVerifier { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataSourceVerifier.class); | ||
|
||
private final DataSource dataSource; | ||
|
||
@Autowired | ||
public DataSourceVerifier(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void verifyDataSourceConnection() { | ||
try (Connection connection = dataSource.getConnection()) { | ||
if (connection != null) { | ||
LOG.info("Datasource connection verified successfully."); | ||
} else { | ||
LOG.info("Failed to obtain a connection from the datasource."); | ||
} | ||
} catch (SQLException e) { | ||
LOG.info("Error verifying datasource connection: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
} |