diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java index 197b5fb6be..a6353f4b1e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java @@ -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 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) ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader())); + if (instance == null) { + instance = new H2EmbeddedDatabaseConfigurer( (Class) + ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader())); } - return INSTANCE; + return instance; } + private H2EmbeddedDatabaseConfigurer(Class driverClass) { this.driverClass = driverClass; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java index 4e4f9646ea..fdab4e8967 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java @@ -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 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) ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader())); + if (instance == null) { + instance = new HsqlEmbeddedDatabaseConfigurer( (Class) + ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader())); } - return INSTANCE; + return instance; } + private HsqlEmbeddedDatabaseConfigurer(Class driverClass) { this.driverClass = driverClass; } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java index 1ad8cbd86f..97326b470e 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java @@ -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(); } + } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java index 77970dbe08..ed585d5049 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryTests.java @@ -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; } - } + }