public class MemoryDbManager
extends java.lang.Object
BaseJDBCTestCase
does, with the exception of deleting the
databases.
Note: It may be possible to integrate this functionality into the existing JUnit framework, for instance if you want to run the entire test suite with the in-memory back end.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTR_CREATE |
private java.util.ArrayList<java.sql.Connection> |
CONNECTIONS
List of openend connections, closed at clean up.
|
private java.util.ArrayList<java.lang.String> |
DATABASES
List of created databases, deleted at clean up.
|
private static MemoryDbManager |
DBM
Shared manager instance.
|
private static java.lang.String |
JDBC_PREFIX
JDBC protocl prefix used for in-memory databases.
|
private java.util.ArrayList<java.sql.Statement> |
STATEMENTS
List of openend statements, closed at clean up.
|
Constructor and Description |
---|
MemoryDbManager() |
Modifier and Type | Method and Description |
---|---|
void |
cleanUp()
Cleans up database resources by closing known statements and
connection, and deleting known in-memory databases.
|
java.sql.Connection |
createDatabase(java.lang.String dbName)
Creates a new database and keeps track of it to delete it when the
clean up is invoked.
|
java.sql.Connection |
createDatabase(java.lang.String dbName,
java.lang.String dbAttributes,
java.lang.String user,
java.lang.String password)
Creates a new database and keeps track of it to delete it when the
clean up is invoked.
|
java.sql.Statement |
createStatement(java.sql.Connection con)
Creates a new statement from the given connection and keeps track of
it and closes it when the clean up is invoked.
|
void |
dropDatabase(java.lang.String dbNameAndAttributes)
Drops the specified database.
|
java.sql.Connection |
getConnection(java.lang.String dbNameAndAttributes)
Creates a new connection to the specified database (url).
|
static MemoryDbManager |
getSharedInstance()
Returns a shared manager instance.
|
java.sql.PreparedStatement |
prepareStatement(java.sql.Connection con,
java.lang.String sql)
Creates a new prepared statement from the given connection and keeps
track of it and closes it when the clean up is invoked.
|
private static final java.lang.String ATTR_CREATE
private static final java.lang.String JDBC_PREFIX
private static final MemoryDbManager DBM
private final java.util.ArrayList<java.sql.Statement> STATEMENTS
private final java.util.ArrayList<java.sql.Connection> CONNECTIONS
private final java.util.ArrayList<java.lang.String> DATABASES
public static MemoryDbManager getSharedInstance()
public java.sql.Connection getConnection(java.lang.String dbNameAndAttributes) throws java.sql.SQLException
Note that the specified URL will be appended to a fixed JDBC protcol prefix.
dbNameAndAttributes
- database name and any JDBC url attributesjava.sql.SQLException
- if connecting to the database failspublic java.sql.Statement createStatement(java.sql.Connection con) throws java.sql.SQLException
con
- the connection to use for creationjava.sql.SQLException
- if creating the statement failscleanUp()
public java.sql.PreparedStatement prepareStatement(java.sql.Connection con, java.lang.String sql) throws java.sql.SQLException
con
- the connection to use for creationsql
- the sql text to preparejava.sql.SQLException
- if creating the statement failscleanUp()
public void dropDatabase(java.lang.String dbNameAndAttributes) throws java.sql.SQLException
Note that the specified URL will be appended to a fixed JDBC protcol prefix.
dbNameAndAttributes
- the database name and any attributes
required to access the database (excluding the delete
attribute, which is added by this method)java.sql.SQLException
- if deleting the database failspublic java.sql.Connection createDatabase(java.lang.String dbName) throws java.sql.SQLException
If the database already exists, a connection to the existing database is returned.
dbName
- the database namejava.sql.SQLException
- if creating or connecting to the database failspublic java.sql.Connection createDatabase(java.lang.String dbName, java.lang.String dbAttributes, java.lang.String user, java.lang.String password) throws java.sql.SQLException
If the database already exists, a connection to the existing database is returned.
dbName
- the database namedbAttributes
- database attributes (i.e. encryption)user
- user namepassword
- user passwordjava.sql.SQLException
- if creating or connecting to the database failspublic void cleanUp() throws java.sql.SQLException
java.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.