|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012-2016 the original author or authors. |
|
|
|
* Copyright 2012-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -42,7 +42,6 @@ import org.springframework.context.annotation.Conditional; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.context.annotation.ConfigurationCondition; |
|
|
|
import org.springframework.context.annotation.ConfigurationCondition; |
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata; |
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata; |
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
|
|
|
|
|
|
|
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; |
|
|
|
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; |
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
|
|
|
|
|
|
|
|
|
|
|
@ -85,12 +84,6 @@ public class DevToolsDataSourceAutoConfiguration { |
|
|
|
static final class NonEmbeddedInMemoryDatabaseShutdownExecutor |
|
|
|
static final class NonEmbeddedInMemoryDatabaseShutdownExecutor |
|
|
|
implements DisposableBean { |
|
|
|
implements DisposableBean { |
|
|
|
|
|
|
|
|
|
|
|
private static final Set<String> IN_MEMORY_DRIVER_CLASS_NAMES = new HashSet<String>( |
|
|
|
|
|
|
|
Arrays.asList("org.apache.derby.jdbc.EmbeddedDriver", "org.h2.Driver", |
|
|
|
|
|
|
|
"org.h2.jdbcx.JdbcDataSource", "org.hsqldb.jdbcDriver", |
|
|
|
|
|
|
|
"org.hsqldb.jdbc.JDBCDriver", |
|
|
|
|
|
|
|
"org.hsqldb.jdbc.pool.JDBCXADataSource")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final DataSource dataSource; |
|
|
|
private final DataSource dataSource; |
|
|
|
|
|
|
|
|
|
|
|
private final DataSourceProperties dataSourceProperties; |
|
|
|
private final DataSourceProperties dataSourceProperties; |
|
|
|
@ -109,9 +102,42 @@ public class DevToolsDataSourceAutoConfiguration { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean dataSourceRequiresShutdown() { |
|
|
|
private boolean dataSourceRequiresShutdown() { |
|
|
|
return IN_MEMORY_DRIVER_CLASS_NAMES |
|
|
|
for (InMemoryDatabase inMemoryDatabase : InMemoryDatabase.values()) { |
|
|
|
.contains(this.dataSourceProperties.determineDriverClassName()) |
|
|
|
if (inMemoryDatabase.matches(this.dataSourceProperties)) { |
|
|
|
&& (!(this.dataSource instanceof EmbeddedDatabase)); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static enum InMemoryDatabase { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DERBY(null, "org.apache.derby.jdbc.EmbeddedDriver"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
H2("jdbc:h2:mem:", "org.h2.Driver", "org.h2.jdbcx.JdbcDataSource"), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HQSQLDB("jdbc:hsqldb:mem:", "org.hsqldb.jdbcDriver", |
|
|
|
|
|
|
|
"org.hsqldb.jdbc.JDBCDriver", |
|
|
|
|
|
|
|
"org.hsqldb.jdbc.pool.JDBCXADataSource"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String urlPrefix; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Set<String> driverClassNames; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InMemoryDatabase(String urlPrefix, String... driverClassNames) { |
|
|
|
|
|
|
|
this.urlPrefix = urlPrefix; |
|
|
|
|
|
|
|
this.driverClassNames = new HashSet<String>( |
|
|
|
|
|
|
|
Arrays.asList(driverClassNames)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean matches(DataSourceProperties properties) { |
|
|
|
|
|
|
|
String url = properties.getUrl(); |
|
|
|
|
|
|
|
return (url == null || this.urlPrefix == null |
|
|
|
|
|
|
|
|| url.startsWith(this.urlPrefix)) |
|
|
|
|
|
|
|
&& this.driverClassNames |
|
|
|
|
|
|
|
.contains(properties.determineDriverClassName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|