Package org.opennms.core.test.db
Class TemporaryDatabasePostgreSQL
- java.lang.Object
-
- org.opennms.core.test.db.TemporaryDatabasePostgreSQL
-
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
,XADataSource
,TemporaryDatabase
- Direct Known Subclasses:
MockDatabase
public class TemporaryDatabasePostgreSQL extends Object implements TemporaryDatabase
- Author:
- Mathew Brozowski
-
-
Field Summary
Fields Modifier and Type Field Description static String
LIQUIBASE_RELATIVE_PATH
protected static int
MAX_DATABASE_DROP_ATTEMPTS
static String
TEMPLATE_DATABASE_NAME_PREFIX
-
Fields inherited from interface org.opennms.core.test.db.TemporaryDatabase
ADMIN_PASSWORD_PROPERTY, ADMIN_USER_PROPERTY, DEFAULT_ADMIN_PASSWORD, DEFAULT_ADMIN_USER, DEFAULT_DRIVER, DEFAULT_URL, DRIVER_PROPERTY, URL_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description TemporaryDatabasePostgreSQL()
TemporaryDatabasePostgreSQL(String testDatabase)
TemporaryDatabasePostgreSQL(String testDatabase, boolean useExisting)
TemporaryDatabasePostgreSQL(String testDatabase, String driver, String url, String adminUser, String adminPassword)
TemporaryDatabasePostgreSQL(String testDatabase, String driver, String urlBase, String adminUser, String adminPassword, boolean useExisting)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
countRows(String sql, Object... values)
void
create()
protected void
createIntegrationTestTemplateDatabase(String dbName)
void
drop()
static void
dumpThreads()
protected static void
failIfUnitTest()
String
generateLiquibaseHash()
DataSource
getAdminDataSource()
XADataSource
getAdminXADataSource()
Connection
getConnection()
Connection
getConnection(String username, String password)
protected static String
getDatabaseName(Object hashMe)
DataSource
getDataSource()
String
getIntegrationTestTemplateDatabaseName()
org.springframework.jdbc.core.JdbcTemplate
getJdbcTemplate()
int
getLoginTimeout()
PrintWriter
getLogWriter()
Logger
getParentLogger()
String
getTestDatabase()
XAConnection
getXAConnection()
XAConnection
getXAConnection(String user, String password)
XADataSource
getXADataSource()
boolean
isWrapperFor(Class<?> iface)
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.void
setClassName(String className)
void
setLoginTimeout(int seconds)
void
setLogWriter(PrintWriter out)
void
setMethodName(String methodName)
void
setPlpgsqlIplike(boolean iplike)
void
setPopulateSchema(boolean populateSchema)
void
setTestDetails(String testDetails)
protected static void
setupBlame(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String blame)
void
setupDatabase()
<T> T
unwrap(Class<T> iface)
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.void
update(String stmt, Object... values)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Methods inherited from interface javax.sql.XADataSource
createXAConnectionBuilder
-
-
-
-
Field Detail
-
MAX_DATABASE_DROP_ATTEMPTS
protected static final int MAX_DATABASE_DROP_ATTEMPTS
- See Also:
- Constant Field Values
-
TEMPLATE_DATABASE_NAME_PREFIX
public static final String TEMPLATE_DATABASE_NAME_PREFIX
- See Also:
- Constant Field Values
-
LIQUIBASE_RELATIVE_PATH
public static final String LIQUIBASE_RELATIVE_PATH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(String testDatabase) throws Exception
- Throws:
Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(String testDatabase, boolean useExisting) throws Exception
- Throws:
Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(String testDatabase, String driver, String url, String adminUser, String adminPassword) throws Exception
- Throws:
Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(String testDatabase, String driver, String urlBase, String adminUser, String adminPassword, boolean useExisting) throws TemporaryDatabaseException
- Throws:
TemporaryDatabaseException
-
-
Method Detail
-
setPlpgsqlIplike
public void setPlpgsqlIplike(boolean iplike)
- Specified by:
setPlpgsqlIplike
in interfaceTemporaryDatabase
-
setPopulateSchema
public void setPopulateSchema(boolean populateSchema)
- Specified by:
setPopulateSchema
in interfaceTemporaryDatabase
-
setClassName
public void setClassName(String className)
- Specified by:
setClassName
in interfaceTemporaryDatabase
-
setMethodName
public void setMethodName(String methodName)
- Specified by:
setMethodName
in interfaceTemporaryDatabase
-
setTestDetails
public void setTestDetails(String testDetails)
- Specified by:
setTestDetails
in interfaceTemporaryDatabase
-
create
public void create() throws TemporaryDatabaseException
- Specified by:
create
in interfaceTemporaryDatabase
- Throws:
TemporaryDatabaseException
-
drop
public void drop() throws TemporaryDatabaseException
- Specified by:
drop
in interfaceTemporaryDatabase
- Throws:
TemporaryDatabaseException
-
getJdbcTemplate
public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
- Specified by:
getJdbcTemplate
in interfaceTemporaryDatabase
-
countRows
public int countRows(String sql, Object... values)
- Specified by:
countRows
in interfaceTemporaryDatabase
-
getTestDatabase
public String getTestDatabase()
- Specified by:
getTestDatabase
in interfaceTemporaryDatabase
-
getIntegrationTestTemplateDatabaseName
public String getIntegrationTestTemplateDatabaseName() throws Throwable
- Throws:
Throwable
-
failIfUnitTest
protected static void failIfUnitTest() throws TemporaryDatabaseException
- Throws:
TemporaryDatabaseException
-
setupDatabase
public void setupDatabase() throws TemporaryDatabaseException
- Throws:
TemporaryDatabaseException
-
setupBlame
protected static void setupBlame(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String blame)
-
dumpThreads
public static void dumpThreads()
-
getConnection
public Connection getConnection() throws SQLException
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Specified by:
getLogWriter
in interfaceXADataSource
- Throws:
SQLException
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Specified by:
setLogWriter
in interfaceXADataSource
- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Specified by:
setLoginTimeout
in interfaceXADataSource
- Throws:
SQLException
-
getLoginTimeout
public int getLoginTimeout() throws SQLException
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Specified by:
getLoginTimeout
in interfaceXADataSource
- Throws:
SQLException
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
getAdminDataSource
public DataSource getAdminDataSource()
-
getAdminXADataSource
public XADataSource getAdminXADataSource()
-
getDataSource
public DataSource getDataSource()
-
getXADataSource
public XADataSource getXADataSource()
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
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 callingunwrap
recursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then anSQLException
is thrown.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- A Class defining an interface that the result must implement.- Returns:
- an object that implements the interface. May be a proxy for the actual implementing object.
- Throws:
SQLException
- If no object found that implements the interface- Since:
- 1.6
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
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 callingisWrapperFor
on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared tounwrap
so that callers can use this method to avoid expensiveunwrap
calls that may fail. If this method returns true then callingunwrap
with the same argument should succeed.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
iface
- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface.- Since:
- 1.6
-
getXAConnection
public XAConnection getXAConnection() throws SQLException
- Specified by:
getXAConnection
in interfaceXADataSource
- Throws:
SQLException
-
getXAConnection
public XAConnection getXAConnection(String user, String password) throws SQLException
- Specified by:
getXAConnection
in interfaceXADataSource
- Throws:
SQLException
-
generateLiquibaseHash
public String generateLiquibaseHash() throws NoSuchAlgorithmException, IOException, Exception, liquibase.exception.ChangeLogParseException, liquibase.exception.LiquibaseException
- Throws:
NoSuchAlgorithmException
IOException
Exception
liquibase.exception.ChangeLogParseException
liquibase.exception.LiquibaseException
-
createIntegrationTestTemplateDatabase
protected void createIntegrationTestTemplateDatabase(String dbName) throws ClassNotFoundException, MigrationException, Throwable, SQLException
-
-