Class DerbyMaster
- java.lang.Object
-
- com.ibm.fhir.database.utils.derby.DerbyMaster
-
- All Implemented Interfaces:
AutoCloseable
public class DerbyMaster extends Object implements AutoCloseable
Set up an instance of Derby for use with unit tests
-
-
Constructor Summary
Constructors Constructor Description DerbyMaster(String database)Public constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidcreateSchema(IConnectionProvider pool, IVersionHistoryService vhs, PhysicalDataModel pdm)Ask the schema to apply itself to our target (adapter pattern)voidcreateSchema(IConnectionProvider pool, PhysicalDataModel pdm)Ask the schema to apply itself to our target (adapter pattern)voidcreateSchemaIfNeeded(String schemaName)Derby setSchema fails if the schema doesn't exist, so we need to create that now in order for our connections to succeed when we build out the FHIR databasestatic voiddropDatabase(String database)Drop the contents of the database on disk.voiddumpLockInfo()Diagnostic utility to display all the current locks in the Derby databasestatic voiddumpLockInfo(Connection c)Dump locks using the given connectionConnectiongetConnection()Get a connection to the configured Derby database, creating the database if necessary.IDatabaseTranslatorgetTranslator()Get the statement translator we use for DerbyvoidrunWithAdapter(IConnectionProvider pool, Consumer<IDatabaseAdapter> fn)Run theIDatabaseAdaptercommand fn using a DerbyAdapter for the given connection poolvoidrunWithAdapter(Consumer<IDatabaseAdapter> fn)Run the function with an adapter configured for this databasestatic voidshutdown(String databaseName)
-
-
-
Constructor Detail
-
DerbyMaster
public DerbyMaster(String database)
Public constructor- Parameters:
database-- Throws:
IllegalStateException- if the Derby driver class is not found
-
-
Method Detail
-
createSchemaIfNeeded
public void createSchemaIfNeeded(String schemaName)
Derby setSchema fails if the schema doesn't exist, so we need to create that now in order for our connections to succeed when we build out the FHIR database- Parameters:
schemaName-
-
dropDatabase
public static void dropDatabase(String database)
Drop the contents of the database on disk. Must contain 'derby/' in the path as a simple check against accidentally wiping the wrong files- Parameters:
database-
-
getConnection
public Connection getConnection() throws SQLException
Get a connection to the configured Derby database, creating the database if necessary.- Returns:
- Throws:
SQLException
-
getTranslator
public IDatabaseTranslator getTranslator()
Get the statement translator we use for Derby- Returns:
-
createSchema
public void createSchema(IConnectionProvider pool, PhysicalDataModel pdm)
Ask the schema to apply itself to our target (adapter pattern)- Parameters:
pool- the connection poolpdm- the data model to create
-
createSchema
public void createSchema(IConnectionProvider pool, IVersionHistoryService vhs, PhysicalDataModel pdm)
Ask the schema to apply itself to our target (adapter pattern)- Parameters:
pool- the connection poolvhs- current version history servicepdm- the data model we want to create
-
runWithAdapter
public void runWithAdapter(IConnectionProvider pool, Consumer<IDatabaseAdapter> fn)
Run theIDatabaseAdaptercommand fn using a DerbyAdapter for the given connection pool- Parameters:
pool- provides database connectionsfn- the command to execute
-
runWithAdapter
public void runWithAdapter(Consumer<IDatabaseAdapter> fn)
Run the function with an adapter configured for this database- Parameters:
fn-
-
dumpLockInfo
public void dumpLockInfo()
Diagnostic utility to display all the current locks in the Derby database
-
dumpLockInfo
public static void dumpLockInfo(Connection c)
Dump locks using the given connection- Parameters:
c-
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
shutdown
public static void shutdown(String databaseName)
-
-