EmbeddedDatabase instance.
Callers are guaranteed that the returned database has been fully initialized and populated.
The factory can be configured as follows:
generateUniqueDatabaseName to set a unique, random name
for the database.
setDatabaseName to set an explicit name for the database.
setDatabaseType to set the database type if you wish to
use one of the supported types.
setDatabaseConfigurer to configure support for a custom
embedded database type.
setDatabasePopulator to change the algorithm used to
populate the database.
setDataSourceFactory to change the type of
DataSource used to connect to the database.
After configuring the factory, call getDatabase() to obtain
a reference to the EmbeddedDatabase instance.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private EmbeddedDatabaseConfigurer | |
| private String | |
| private DatabasePopulator | |
| private DataSource | |
| private DataSourceFactory | |
| public static final String | DEFAULT_DATABASE_NAME
Default name for an embedded database: testdb. |
| private boolean | |
| private static final Log |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public EmbeddedDatabase | getDatabase()
Factory method that returns the embedded database
instance, which is also a |
| protected final DataSource | getDataSource()
Hook that gets the |
| protected void | |
| public void | setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer)
Set the strategy that will be used to configure the embedded database instance. |
| public void | |
| public void | setDatabasePopulator(DatabasePopulator populator)
Set the strategy that will be used to initialize or populate the embedded database. |
| public void | setDatabaseType(EmbeddedDatabaseType
the database type type)Set the type of embedded database to use. |
| public void | setDataSourceFactory(DataSourceFactory dataSourceFactory)
Set the factory to use to create the |
| public void | setGenerateUniqueDatabaseName(boolean generateUniqueDatabaseName)
Set the |
| protected void |
| databaseConfigurer | back to summary |
|---|---|
| private EmbeddedDatabaseConfigurer databaseConfigurer
| |
| databaseName | back to summary |
|---|---|
| private String databaseName | |
| databasePopulator | back to summary |
|---|---|
| private DatabasePopulator databasePopulator
| |
| dataSource | back to summary |
|---|---|
| private DataSource dataSource
| |
| dataSourceFactory | back to summary |
|---|---|
| private DataSourceFactory dataSourceFactory | |
| DEFAULT_DATABASE_NAME | back to summary |
|---|---|
| public static final String DEFAULT_DATABASE_NAME Default name for an embedded database: testdb. | |
| generateUniqueDatabaseName | back to summary |
|---|---|
| private boolean generateUniqueDatabaseName | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| EmbeddedDatabaseFactory | back to summary |
|---|---|
| public EmbeddedDatabaseFactory() | |
| getDatabase | back to summary |
|---|---|
| public EmbeddedDatabase getDatabase() Factory method that returns the embedded database
instance, which is also a | |
| getDataSource | back to summary |
|---|---|
| protected final DataSource getDataSource() Hook that gets the Returns
| |
| initDatabase | back to summary |
|---|---|
| protected void initDatabase() Hook to initialize the embedded database. If the Subclasses may call this method to force initialization; however, this method should only be invoked once. After calling this method, | |
| setDatabaseConfigurer | back to summary |
|---|---|
| public void setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer) Set the strategy that will be used to configure the embedded database instance. Call this when you wish to use an embedded database type not already supported. | |
| setDatabaseName | back to summary |
|---|---|
| public void setDatabaseName(String databaseName) Set the name of the database. Defaults to testdb. Will be overridden if the
| |
| setDatabasePopulator | back to summary |
|---|---|
| public void setDatabasePopulator(DatabasePopulator populator) Set the strategy that will be used to initialize or populate the embedded database. Defaults to | |
| setDatabaseType | back to summary |
|---|---|
| public void setDatabaseType(EmbeddedDatabaseType type) Set the type of embedded database to use. Call this when you wish to configure one of the pre-supported types. Defaults to HSQL.
| |
| setDataSourceFactory | back to summary |
|---|---|
| public void setDataSourceFactory(DataSourceFactory dataSourceFactory) Set the factory to use to create the Defaults to | |
| setGenerateUniqueDatabaseName | back to summary |
|---|---|
| public void setGenerateUniqueDatabaseName(boolean generateUniqueDatabaseName) Set the Setting this flag to
| |
| shutdownDatabase | back to summary |
|---|---|
| protected void shutdownDatabase() Hook to shut down the embedded database. Subclasses may call this method to force shutdown. After calling, Does nothing if no embedded database has been initialized. | |
| Modifier and Type | Field and Description |
|---|---|
| private final DataSource |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Connection | getConnection()
Implements javax. Attempts to establish a connection with the data source that
this |
| public Connection | getConnection(String
the database user on whose behalf the connection is
being made username, String the user's password password)Implements javax. Attempts to establish a connection with the data source that
this |
| public int | getLoginTimeout()
Implements javax. Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. |
| public PrintWriter | getLogWriter()
Implements javax. Retrieves the log writer for this |
| public Logger | getParentLogger()
Implements javax. Return the parent Logger of all the Loggers used by this data source. |
| public boolean | isWrapperFor(Class<?>
a Class defining an interface. iface)Implements java. Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |
| public void | setLoginTimeout(int
the data source login time limit seconds)Implements javax. Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. |
| public void | setLogWriter(PrintWriter
the new log writer; to disable logging, set to null out)Implements javax. Sets the log writer for this |
| public void | shutdown()
Implements org. Shut down this embedded database. |
| public <T> T | unwrap(Class<T>
A Class defining an interface that the result must implement. iface)Implements java. Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. |
| dataSource | back to summary |
|---|---|
| private final DataSource dataSource | |
| EmbeddedDataSourceProxy | back to summary |
|---|---|
| public EmbeddedDataSourceProxy(DataSource dataSource) | |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Implements javax. Doc from javax. Attempts to establish a connection with the data source that
this
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(String username, String password) throws SQLException Implements javax. Doc from javax. Attempts to establish a connection with the data source that
this
| |
| getLoginTimeout | back to summary |
|---|---|
| public int getLoginTimeout() throws SQLException Implements javax. Doc from javax. Gets the maximum time in seconds that this data source can wait
while attempting to connect to a database. A value of zero
means that the timeout is the default system timeout
if there is one; otherwise, it means that there is no timeout.
When a
| |
| getLogWriter | back to summary |
|---|---|
| public PrintWriter getLogWriter() throws SQLException Implements javax. Doc from javax. Retrieves the log writer for this The log writer is a character output stream to which all logging
and tracing messages for this data source will be
printed. This includes messages printed by the methods of this
object, messages printed by methods of other objects manufactured
by this object, and so on. Messages printed to a data source
specific log writer are not printed to the log writer associated
with the
| |
| getParentLogger | back to summary |
|---|---|
| public Logger getParentLogger() Implements javax. Doc from javax. Return the parent Logger of all the Loggers used by this data source. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this data source. Configuring this Logger will affect all of the log messages generated by the data source. In the worst case, this may be the root Logger. | |
| isWrapperFor | back to summary |
|---|---|
| public boolean isWrapperFor(Class<?> iface) throws SQLException Implements java. Doc from java. Returns true if this either implements the interface argument or is directly or indirectly a wrapper
for an object that does. Returns false otherwise. If this implements the interface then return true,
else if this is a wrapper then return the result of recursively calling
| |
| setLoginTimeout | back to summary |
|---|---|
| public void setLoginTimeout(int seconds) throws SQLException Implements javax. Doc from javax. Sets the maximum time in seconds that this data source will wait
while attempting to connect to a database. A value of zero
specifies that the timeout is the default system timeout
if there is one; otherwise, it specifies that there is no timeout.
When a
| |
| setLogWriter | back to summary |
|---|---|
| public void setLogWriter(PrintWriter out) throws SQLException Implements javax. Doc from javax. Sets the log writer for this The log writer is a character output stream to which all logging
and tracing messages for this data source will be
printed. This includes messages printed by the methods of this
object, messages printed by methods of other objects manufactured
by this object, and so on. Messages printed to a data source-
specific log writer are not printed to the log writer associated
with the
| |
| shutdown | back to summary |
|---|---|
| public void shutdown() Implements org. Doc from org. Shut down this embedded database.
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> iface) throws SQLException Implements java. Doc from java. Returns an object that implements the given interface to allow access to
non-standard methods, or standard methods not exposed by the proxy.
If the receiver implements the interface then the result is the receiver
or a proxy for the receiver. If the receiver is a wrapper
and the wrapped object implements the interface then the result is the
wrapped object or a proxy for the wrapped object. Otherwise return the
the result of calling
| |