|
|
|
|
@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService;
@@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService;
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
import javax.sql.DataSource; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean; |
|
|
|
|
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration; |
|
|
|
|
@ -32,9 +31,7 @@ import org.springframework.context.annotation.Condition;
@@ -32,9 +31,7 @@ import org.springframework.context.annotation.Condition;
|
|
|
|
|
import org.springframework.context.annotation.ConditionContext; |
|
|
|
|
import org.springframework.context.annotation.Conditional; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.core.io.DefaultResourceLoader; |
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
import org.springframework.core.io.ResourceLoader; |
|
|
|
|
import org.springframework.core.task.AsyncUtils; |
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata; |
|
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
|
|
|
|
@ -62,19 +59,22 @@ public class EmbeddedDatabaseAutoConfiguration {
@@ -62,19 +59,22 @@ public class EmbeddedDatabaseAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
private ExecutorService executorService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ResourceLoader resourceLoader = new DefaultResourceLoader(); |
|
|
|
|
|
|
|
|
|
@Value("${spring.jdbc.schema:classpath:schema.sql}") |
|
|
|
|
private String schemaLocation = "classpath:schema.sql"; // FIXME: DB platform
|
|
|
|
|
// FIXME: DB platform
|
|
|
|
|
@Value("${spring.jdbc.schema:classpath*:schema.sql}") |
|
|
|
|
private Resource[] schemaLocations = new Resource[0]; |
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
|
protected void initialize() throws Exception { |
|
|
|
|
Resource resource = this.resourceLoader.getResource(this.schemaLocation); |
|
|
|
|
if (resource.exists()) { |
|
|
|
|
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); |
|
|
|
|
populator.addScript(resource); |
|
|
|
|
populator.setContinueOnError(true); |
|
|
|
|
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); |
|
|
|
|
boolean exists = false; |
|
|
|
|
for (Resource resource : this.schemaLocations) { |
|
|
|
|
if (resource.exists()) { |
|
|
|
|
exists = true; |
|
|
|
|
populator.addScript(resource); |
|
|
|
|
populator.setContinueOnError(true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (exists) { |
|
|
|
|
DatabasePopulatorUtils.execute(populator, dataSource()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|