-
Notifications
You must be signed in to change notification settings - Fork 6
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
Felix Zwirn
committed
Jul 24, 2024
1 parent
05aca20
commit 07aee89
Showing
2 changed files
with
31 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
30 changes: 30 additions & 0 deletions
30
jpa/src/main/java/de/taimos/dvalin/jpa/config/H2Config.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,30 @@ | ||
package de.taimos.dvalin.jpa.config; | ||
|
||
import de.taimos.daemon.spring.conditional.OnSystemProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean; | ||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Copyright 2024 Cinovo AG<br> | ||
* <br> | ||
* | ||
* @author fzwirn | ||
*/ | ||
@Configuration | ||
@OnSystemProperty(propertyName = "ds.type", propertyValue = "H2") | ||
public class H2Config { | ||
@Bean | ||
public DataSource dataSource() { | ||
EmbeddedDatabaseFactoryBean factoryBean = new EmbeddedDatabaseFactoryBean(); | ||
// randomize database name to get a new one each time | ||
factoryBean.setDatabaseName(UUID.randomUUID().toString()); | ||
factoryBean.setDatabaseType(EmbeddedDatabaseType.H2); | ||
factoryBean.afterPropertiesSet(); | ||
return factoryBean.getObject(); | ||
} | ||
} |