Skip to content

Commit 42690a9

Browse files
committed
Overhaul Javadoc for embedded database support
1 parent c61d62e commit 42690a9

File tree

7 files changed

+70
-44
lines changed

7 files changed

+70
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -25,7 +25,7 @@
2525

2626
/**
2727
* {@link EmbeddedDatabaseConfigurer} for the Apache Derby database 10.6+.
28-
* Call {@link #getInstance()} to get the singleton instance of this class.
28+
* <p>Call {@link #getInstance()} to get the singleton instance of this class.
2929
*
3030
* @author Oliver Gierke
3131
* @author Juergen Hoeller

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -19,11 +19,14 @@
1919
import javax.sql.DataSource;
2020

2121
/**
22-
* A handle to an EmbeddedDatabase instance.
23-
* Is a {@link DataSource}.
24-
* Adds a shutdown operation so the embedded database instance can be shutdown.
22+
* {@code EmbeddedDatabase} serves as a handle to an embedded database instance.
23+
*
24+
* <p>An {@code EmbeddedDatabase} is also a {@link DataSource} and adds a
25+
* {@link #shutdown} operation so that the embedded database instance can be
26+
* shutdown.
2527
*
2628
* @author Keith Donald
29+
* @author Sam Brannen
2730
* @since 3.0
2831
*/
2932
public interface EmbeddedDatabase extends DataSource {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* A builder that provides a convenient API for constructing an embedded database.
2525
*
26-
* <p>Usage example:
26+
* <h3>Usage Example</h3>
2727
* <pre class="code">
2828
* EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
2929
* EmbeddedDatabase db = builder.setType(H2).addScript("schema.sql").addScript("data.sql").build();
@@ -66,9 +66,10 @@ public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader) {
6666

6767
/**
6868
* Set the name of the embedded database.
69-
* <p>Defaults to "testdb" if not called.
69+
* <p>Defaults to {@link EmbeddedDatabaseFactory#DEFAULT_DATABASE_NAME} if
70+
* not called.
7071
* @param databaseName the database name
71-
* @return this, to facilitate method chaining
72+
* @return {@code this}, to facilitate method chaining
7273
*/
7374
public EmbeddedDatabaseBuilder setName(String databaseName) {
7475
this.databaseFactory.setDatabaseName(databaseName);
@@ -79,17 +80,17 @@ public EmbeddedDatabaseBuilder setName(String databaseName) {
7980
* Set the type of embedded database.
8081
* <p>Defaults to HSQL if not called.
8182
* @param databaseType the database type
82-
* @return this, to facilitate method chaining
83+
* @return {@code this}, to facilitate method chaining
8384
*/
8485
public EmbeddedDatabaseBuilder setType(EmbeddedDatabaseType databaseType) {
8586
this.databaseFactory.setDatabaseType(databaseType);
8687
return this;
8788
}
8889

8990
/**
90-
* Add a SQL script to execute to populate the database.
91+
* Add an SQL script to execute to initialize or populate the database.
9192
* @param sqlResource the sql resource location
92-
* @return this, to facilitate method chaining
93+
* @return {@code this}, to facilitate method chaining
9394
*/
9495
public EmbeddedDatabaseBuilder addScript(String sqlResource) {
9596
this.databasePopulator.addScript(this.resourceLoader.getResource(sqlResource));
@@ -98,9 +99,9 @@ public EmbeddedDatabaseBuilder addScript(String sqlResource) {
9899

99100
/**
100101
* Add default scripts to execute to populate the database.
101-
* <p>The default scripts are {@code schema.sql} to create the db
102-
* schema and {@code data.sql} to populate the db with data.
103-
* @return this, to facilitate method chaining
102+
* <p>The default scripts are {@code "schema.sql"} to create the database
103+
* schema and {@code "data.sql"} to populate the database with data.
104+
* @return {@code this}, to facilitate method chaining
104105
*/
105106
public EmbeddedDatabaseBuilder addDefaultScripts() {
106107
addScript("schema.sql");

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -19,11 +19,12 @@
1919
import org.springframework.util.Assert;
2020

2121
/**
22-
* Maps well-known {@link EmbeddedDatabaseType embedded database types} to
22+
* Maps well-known {@linkplain EmbeddedDatabaseType embedded database types} to
2323
* {@link EmbeddedDatabaseConfigurer} strategies.
2424
*
2525
* @author Keith Donald
2626
* @author Oliver Gierke
27+
* @author Sam Brannen
2728
* @since 3.0
2829
*/
2930
final class EmbeddedDatabaseConfigurerFactory {
@@ -39,7 +40,7 @@ public static EmbeddedDatabaseConfigurer getConfigurer(EmbeddedDatabaseType type
3940
case DERBY:
4041
return DerbyEmbeddedDatabaseConfigurer.getInstance();
4142
default:
42-
throw new UnsupportedOperationException("Other embedded database types not yet supported");
43+
throw new UnsupportedOperationException("Embedded database type [" + type + "] is not supported");
4344
}
4445
}
4546
catch (ClassNotFoundException ex) {
@@ -49,6 +50,7 @@ public static EmbeddedDatabaseConfigurer getConfigurer(EmbeddedDatabaseType type
4950
}
5051

5152
private EmbeddedDatabaseConfigurerFactory() {
53+
/* no-op */
5254
}
5355

5456
}

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.sql.Connection;
2121
import java.sql.SQLException;
2222
import java.util.logging.Logger;
23+
2324
import javax.sql.DataSource;
2425

2526
import org.apache.commons.logging.Log;
@@ -30,8 +31,10 @@
3031
import org.springframework.util.Assert;
3132

3233
/**
33-
* Creates an {@link EmbeddedDatabase} instance. Callers are guaranteed that
34-
* the returned database has been fully initialized and populated.
34+
* Factory for creating {@link EmbeddedDatabase} instances.
35+
*
36+
* <p>Callers are guaranteed that a returned database has been fully initialized
37+
* and populated.
3538
*
3639
* <p>Can be configured:
3740
* <ul>
@@ -43,19 +46,26 @@
4346
* <li>Call {@link #setDatabasePopulator(DatabasePopulator)} to change the
4447
* algorithm used to populate the database.
4548
* <li>Call {@link #setDataSourceFactory(DataSourceFactory)} to change the type
46-
* of DataSource used to connect to the database.
47-
* <li>Call {@link #getDatabase()} to get the {@link EmbeddedDatabase} instance.
49+
* of {@link DataSource} used to connect to the database.
4850
* </ul>
4951
*
52+
* <p>Call {@link #getDatabase()} to get the {@link EmbeddedDatabase} instance.
53+
*
5054
* @author Keith Donald
5155
* @author Juergen Hoeller
56+
* @author Sam Brannen
5257
* @since 3.0
5358
*/
5459
public class EmbeddedDatabaseFactory {
5560

61+
/**
62+
* Default name for an embedded database: &quot;testdb&quot;.
63+
*/
64+
public static final String DEFAULT_DATABASE_NAME = "testdb";
65+
5666
private static Log logger = LogFactory.getLog(EmbeddedDatabaseFactory.class);
5767

58-
private String databaseName = "testdb";
68+
private String databaseName = DEFAULT_DATABASE_NAME;
5969

6070
private DataSourceFactory dataSourceFactory = new SimpleDriverDataSourceFactory();
6171

@@ -67,16 +77,18 @@ public class EmbeddedDatabaseFactory {
6777

6878

6979
/**
70-
* Set the name of the database. Defaults to "testdb".
71-
* @param databaseName name of the test database
80+
* Set the name of the database.
81+
* <p>Defaults to {@value #DEFAULT_DATABASE_NAME}.
82+
* @param databaseName name of the embedded database
7283
*/
7384
public void setDatabaseName(String databaseName) {
74-
Assert.notNull(databaseName, "Database name is required");
85+
Assert.hasText(databaseName, "Database name is required");
7586
this.databaseName = databaseName;
7687
}
7788

7889
/**
79-
* Set the factory to use to create the DataSource instance that connects to the embedded database.
90+
* Set the factory to use to create the {@link DataSource} instance that
91+
* connects to the embedded database.
8092
* <p>Defaults to {@link SimpleDriverDataSourceFactory}.
8193
*/
8294
public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
@@ -85,9 +97,10 @@ public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {
8597
}
8698

8799
/**
88-
* Set the type of embedded database to use. Call this when you wish to configure
89-
* one of the pre-supported types. Defaults to HSQL.
90-
* @param type the test database type
100+
* Set the type of embedded database to use.
101+
* <p>Call this when you wish to configure one of the pre-supported types.
102+
* <p>Defaults to HSQL.
103+
* @param type the database type
91104
*/
92105
public void setDatabaseType(EmbeddedDatabaseType type) {
93106
this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(type);
@@ -102,7 +115,9 @@ public void setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer) {
102115
}
103116

104117
/**
105-
* Set the strategy that will be used to populate the embedded database. Defaults to null.
118+
* Set the strategy that will be used to initialize or populate the embedded
119+
* database.
120+
* <p>Defaults to {@code null}.
106121
* @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabasePopulator
107122
*/
108123
public void setDatabasePopulator(DatabasePopulator populator) {
@@ -121,8 +136,10 @@ public EmbeddedDatabase getDatabase() {
121136

122137

123138
/**
124-
* Hook to initialize the embedded database. Subclasses may call to force initialization. After calling this method,
125-
* {@link #getDataSource()} returns the DataSource providing connectivity to the db.
139+
* Hook to initialize the embedded database. Subclasses may call this method
140+
* to force initialization.
141+
* <p>After calling this method, {@link #getDataSource()} returns the
142+
* {@link DataSource} providing connectivity to the database.
126143
*/
127144
protected void initDatabase() {
128145
// Create the embedded database source first
@@ -150,9 +167,10 @@ protected void initDatabase() {
150167
}
151168

152169
/**
153-
* Hook to shutdown the embedded database. Subclasses may call to force shutdown.
170+
* Hook to shutdown the embedded database. Subclasses may call this method
171+
* to force shutdown.
154172
* <p>After calling, {@link #getDataSource()} returns {@code null}.
155-
* Does nothing if no embedded database has been initialized.
173+
* <p>Does nothing if no embedded database has been initialized.
156174
*/
157175
protected void shutdownDatabase() {
158176
if (this.dataSource != null) {
@@ -162,9 +180,11 @@ protected void shutdownDatabase() {
162180
}
163181

164182
/**
165-
* Hook that gets the DataSource that provides the connectivity to the embedded database.
166-
* <p>Returns {@code null} if the DataSource has not been initialized or the database
167-
* has been shut down. Subclasses may call to access the DataSource instance directly.
183+
* Hook that gets the {@link DataSource} that provides the connectivity to the
184+
* embedded database.
185+
* <p>Returns {@code null} if the {@code DataSource} has not been initialized
186+
* or if the database has been shut down. Subclasses may call this method to
187+
* access the {@code DataSource} instance directly.
168188
*/
169189
protected final DataSource getDataSource() {
170190
return this.dataSource;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -21,8 +21,8 @@
2121
import org.springframework.util.ClassUtils;
2222

2323
/**
24-
* Initializes an H2 embedded database instance.
25-
* Call {@link #getInstance()} to get the singleton instance of this class.
24+
* {@link EmbeddedDatabaseConfigurer} for an H2 embedded database instance.
25+
* <p>Call {@link #getInstance()} to get the singleton instance of this class.
2626
*
2727
* @author Oliver Gierke
2828
* @author Juergen Hoeller

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -21,8 +21,8 @@
2121
import org.springframework.util.ClassUtils;
2222

2323
/**
24-
* Initializes an HSQL embedded database instance.
25-
* Call {@link #getInstance()} to get the singleton instance of this class.
24+
* {@link EmbeddedDatabaseConfigurer} for an HSQL embedded database instance.
25+
* <p>Call {@link #getInstance()} to get the singleton instance of this class.
2626
*
2727
* @author Keith Donald
2828
* @author Oliver Gierke

0 commit comments

Comments
 (0)