-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pandas.core; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.support.DatabaseStartupValidator; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Configuration | ||
public class DatabaseStartupConfig { | ||
@Bean | ||
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) { | ||
var validator = new DatabaseStartupValidator(); | ||
validator.setDataSource(dataSource); | ||
validator.setTimeout((int) TimeUnit.HOURS.toSeconds(4)); | ||
return validator; | ||
} | ||
|
||
/** | ||
* This makes EntityManagerFactory depend on DatabaseStartupValidator to block startup | ||
* until the database is ready. | ||
*/ | ||
@Bean | ||
public static EntityManagerFactoryDependsOnPostProcessor databaseStartupDependency() { | ||
return new EntityManagerFactoryDependsOnPostProcessor("databaseStartupValidator"); | ||
} | ||
} |