Skip to content

Commit d032c20

Browse files
committed
Polishing
Issue: SPR-10469
1 parent b4d6e27 commit d032c20

File tree

4 files changed

+62
-19
lines changed

4 files changed

+62
-19
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,24 +30,26 @@
3030
*/
3131
final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
3232

33-
private static H2EmbeddedDatabaseConfigurer INSTANCE;
33+
private static H2EmbeddedDatabaseConfigurer instance;
3434

3535
private final Class<? extends Driver> driverClass;
3636

37+
3738
/**
3839
* Get the singleton {@link H2EmbeddedDatabaseConfigurer} instance.
3940
* @return the configurer
4041
* @throws ClassNotFoundException if H2 is not on the classpath
4142
*/
4243
@SuppressWarnings("unchecked")
4344
public static synchronized H2EmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
44-
if (INSTANCE == null) {
45-
INSTANCE = new H2EmbeddedDatabaseConfigurer(
46-
(Class<? extends Driver>) ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader()));
45+
if (instance == null) {
46+
instance = new H2EmbeddedDatabaseConfigurer( (Class<? extends Driver>)
47+
ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader()));
4748
}
48-
return INSTANCE;
49+
return instance;
4950
}
5051

52+
5153
private H2EmbeddedDatabaseConfigurer(Class<? extends Driver> driverClass) {
5254
this.driverClass = driverClass;
5355
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,24 +30,26 @@
3030
*/
3131
final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
3232

33-
private static HsqlEmbeddedDatabaseConfigurer INSTANCE;
33+
private static HsqlEmbeddedDatabaseConfigurer instance;
3434

3535
private final Class<? extends Driver> driverClass;
3636

37+
3738
/**
3839
* Get the singleton {@link HsqlEmbeddedDatabaseConfigurer} instance.
3940
* @return the configurer
4041
* @throws ClassNotFoundException if HSQL is not on the classpath
4142
*/
4243
@SuppressWarnings("unchecked")
4344
public static synchronized HsqlEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
44-
if (INSTANCE == null) {
45-
INSTANCE = new HsqlEmbeddedDatabaseConfigurer(
46-
(Class<? extends Driver>) ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader()));
45+
if (instance == null) {
46+
instance = new HsqlEmbeddedDatabaseConfigurer( (Class<? extends Driver>)
47+
ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader()));
4748
}
48-
return INSTANCE;
49+
return instance;
4950
}
5051

52+
5153
private HsqlEmbeddedDatabaseConfigurer(Class<? extends Driver> driverClass) {
5254
this.driverClass = driverClass;
5355
}

spring-jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.jdbc.datasource.embedded;
218

319
import static org.junit.Assert.assertEquals;
@@ -10,21 +26,22 @@
1026
import org.springframework.jdbc.core.JdbcTemplate;
1127
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
1228

29+
/**
30+
* @author Keith Donald
31+
*/
1332
public class EmbeddedDatabaseFactoryBeanTests {
1433

1534
@Test
1635
public void testFactoryBeanLifecycle() throws Exception {
1736
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
1837
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
19-
populator.setScripts(new Resource[] {
20-
new ClassPathResource("db-schema.sql", getClass()),
21-
new ClassPathResource("db-test-data.sql", getClass())
22-
});
38+
populator.setScripts(new ClassPathResource("db-schema.sql", getClass()), new ClassPathResource("db-test-data.sql", getClass()));
2339
bean.setDatabasePopulator(populator);
2440
bean.afterPropertiesSet();
2541
DataSource ds = bean.getObject();
2642
JdbcTemplate template = new JdbcTemplate(ds);
2743
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
2844
bean.destroy();
2945
}
46+
3047
}
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1-
package org.springframework.jdbc.datasource.embedded;
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
import static org.junit.Assert.assertTrue;
17+
package org.springframework.jdbc.datasource.embedded;
418

519
import java.sql.Connection;
620

721
import org.junit.Test;
22+
823
import org.springframework.jdbc.datasource.init.DatabasePopulator;
924

25+
import static org.junit.Assert.*;
26+
27+
/**
28+
* @author Keith Donald
29+
*/
1030
public class EmbeddedDatabaseFactoryTests {
1131

1232
private EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory();
1333

34+
1435
@Test
1536
public void testGetDataSource() {
1637
StubDatabasePopulator populator = new StubDatabasePopulator();
@@ -20,6 +41,7 @@ public void testGetDataSource() {
2041
db.shutdown();
2142
}
2243

44+
2345
private static class StubDatabasePopulator implements DatabasePopulator {
2446

2547
private boolean populateCalled;
@@ -28,6 +50,6 @@ private static class StubDatabasePopulator implements DatabasePopulator {
2850
public void populate(Connection connection) {
2951
this.populateCalled = true;
3052
}
31-
3253
}
54+
3355
}

0 commit comments

Comments
 (0)