parent
b4d6e27fb3
commit
d032c20a54
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,10 +30,11 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
|
||||
|
||||
private static H2EmbeddedDatabaseConfigurer INSTANCE;
|
||||
private static H2EmbeddedDatabaseConfigurer instance;
|
||||
|
||||
private final Class<? extends Driver> driverClass;
|
||||
|
||||
|
||||
/**
|
||||
* Get the singleton {@link H2EmbeddedDatabaseConfigurer} instance.
|
||||
* @return the configurer
|
||||
|
@ -41,13 +42,14 @@ final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigu
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static synchronized H2EmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new H2EmbeddedDatabaseConfigurer(
|
||||
(Class<? extends Driver>) ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader()));
|
||||
if (instance == null) {
|
||||
instance = new H2EmbeddedDatabaseConfigurer( (Class<? extends Driver>)
|
||||
ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader()));
|
||||
}
|
||||
return INSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private H2EmbeddedDatabaseConfigurer(Class<? extends Driver> driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,10 +30,11 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
|
||||
|
||||
private static HsqlEmbeddedDatabaseConfigurer INSTANCE;
|
||||
private static HsqlEmbeddedDatabaseConfigurer instance;
|
||||
|
||||
private final Class<? extends Driver> driverClass;
|
||||
|
||||
|
||||
/**
|
||||
* Get the singleton {@link HsqlEmbeddedDatabaseConfigurer} instance.
|
||||
* @return the configurer
|
||||
|
@ -41,13 +42,14 @@ final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfi
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static synchronized HsqlEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new HsqlEmbeddedDatabaseConfigurer(
|
||||
(Class<? extends Driver>) ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader()));
|
||||
if (instance == null) {
|
||||
instance = new HsqlEmbeddedDatabaseConfigurer( (Class<? extends Driver>)
|
||||
ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader()));
|
||||
}
|
||||
return INSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private HsqlEmbeddedDatabaseConfigurer(Class<? extends Driver> driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jdbc.datasource.embedded;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -10,16 +26,16 @@ import org.springframework.core.io.Resource;
|
|||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class EmbeddedDatabaseFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanLifecycle() throws Exception {
|
||||
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
|
||||
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
|
||||
populator.setScripts(new Resource[] {
|
||||
new ClassPathResource("db-schema.sql", getClass()),
|
||||
new ClassPathResource("db-test-data.sql", getClass())
|
||||
});
|
||||
populator.setScripts(new ClassPathResource("db-schema.sql", getClass()), new ClassPathResource("db-test-data.sql", getClass()));
|
||||
bean.setDatabasePopulator(populator);
|
||||
bean.afterPropertiesSet();
|
||||
DataSource ds = bean.getObject();
|
||||
|
@ -27,4 +43,5 @@ public class EmbeddedDatabaseFactoryBeanTests {
|
|||
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
|
||||
bean.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,37 @@
|
|||
package org.springframework.jdbc.datasource.embedded;
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
package org.springframework.jdbc.datasource.embedded;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.jdbc.datasource.init.DatabasePopulator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class EmbeddedDatabaseFactoryTests {
|
||||
|
||||
private EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory();
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
StubDatabasePopulator populator = new StubDatabasePopulator();
|
||||
|
@ -20,6 +41,7 @@ public class EmbeddedDatabaseFactoryTests {
|
|||
db.shutdown();
|
||||
}
|
||||
|
||||
|
||||
private static class StubDatabasePopulator implements DatabasePopulator {
|
||||
|
||||
private boolean populateCalled;
|
||||
|
@ -28,6 +50,6 @@ public class EmbeddedDatabaseFactoryTests {
|
|||
public void populate(Connection connection) {
|
||||
this.populateCalled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue