Package org.opennms.core.test.db
Class TemporaryDatabasePostgreSQL
- java.lang.Object
-
- org.opennms.core.test.db.TemporaryDatabasePostgreSQL
-
- All Implemented Interfaces:
java.sql.Wrapper
,javax.sql.CommonDataSource
,javax.sql.DataSource
,javax.sql.XADataSource
,TemporaryDatabase
- Direct Known Subclasses:
MockDatabase
public class TemporaryDatabasePostgreSQL extends java.lang.Object implements TemporaryDatabase
- Author:
- Mathew Brozowski
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
LIQUIBASE_RELATIVE_PATH
protected static int
MAX_DATABASE_DROP_ATTEMPTS
static java.lang.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(java.lang.String testDatabase)
TemporaryDatabasePostgreSQL(java.lang.String testDatabase, boolean useExisting)
TemporaryDatabasePostgreSQL(java.lang.String testDatabase, java.lang.String driver, java.lang.String url, java.lang.String adminUser, java.lang.String adminPassword)
TemporaryDatabasePostgreSQL(java.lang.String testDatabase, java.lang.String driver, java.lang.String urlBase, java.lang.String adminUser, java.lang.String adminPassword, boolean useExisting)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
countRows(java.lang.String sql, java.lang.Object... values)
void
create()
protected void
createIntegrationTestTemplateDatabase(java.lang.String dbName)
void
drop()
static void
dumpThreads()
protected static void
failIfUnitTest()
java.lang.String
generateLiquibaseHash()
javax.sql.DataSource
getAdminDataSource()
javax.sql.XADataSource
getAdminXADataSource()
java.sql.Connection
getConnection()
java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
protected static java.lang.String
getDatabaseName(java.lang.Object hashMe)
javax.sql.DataSource
getDataSource()
java.lang.String
getIntegrationTestTemplateDatabaseName()
org.springframework.jdbc.core.JdbcTemplate
getJdbcTemplate()
int
getLoginTimeout()
java.io.PrintWriter
getLogWriter()
java.util.logging.Logger
getParentLogger()
java.lang.String
getTestDatabase()
javax.sql.XAConnection
getXAConnection()
javax.sql.XAConnection
getXAConnection(java.lang.String user, java.lang.String password)
javax.sql.XADataSource
getXADataSource()
boolean
isWrapperFor(java.lang.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(java.lang.String className)
void
setLoginTimeout(int seconds)
void
setLogWriter(java.io.PrintWriter out)
void
setMethodName(java.lang.String methodName)
void
setPlpgsqlIplike(boolean iplike)
void
setPopulateSchema(boolean populateSchema)
void
setTestDetails(java.lang.String testDetails)
protected static void
setupBlame(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, java.lang.String blame)
void
setupDatabase()
<T> T
unwrap(java.lang.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(java.lang.String stmt, java.lang.Object... values)
-
-
-
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 java.lang.String TEMPLATE_DATABASE_NAME_PREFIX
- See Also:
- Constant Field Values
-
LIQUIBASE_RELATIVE_PATH
public static final java.lang.String LIQUIBASE_RELATIVE_PATH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL() throws java.lang.Exception
- Throws:
java.lang.Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(java.lang.String testDatabase) throws java.lang.Exception
- Throws:
java.lang.Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(java.lang.String testDatabase, boolean useExisting) throws java.lang.Exception
- Throws:
java.lang.Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(java.lang.String testDatabase, java.lang.String driver, java.lang.String url, java.lang.String adminUser, java.lang.String adminPassword) throws java.lang.Exception
- Throws:
java.lang.Exception
-
TemporaryDatabasePostgreSQL
public TemporaryDatabasePostgreSQL(java.lang.String testDatabase, java.lang.String driver, java.lang.String urlBase, java.lang.String adminUser, java.lang.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(java.lang.String className)
- Specified by:
setClassName
in interfaceTemporaryDatabase
-
setMethodName
public void setMethodName(java.lang.String methodName)
- Specified by:
setMethodName
in interfaceTemporaryDatabase
-
setTestDetails
public void setTestDetails(java.lang.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(java.lang.String sql, java.lang.Object... values)
- Specified by:
countRows
in interfaceTemporaryDatabase
-
getTestDatabase
public java.lang.String getTestDatabase()
- Specified by:
getTestDatabase
in interfaceTemporaryDatabase
-
getIntegrationTestTemplateDatabaseName
public java.lang.String getIntegrationTestTemplateDatabaseName() throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
failIfUnitTest
protected static void failIfUnitTest() throws TemporaryDatabaseException
- Throws:
TemporaryDatabaseException
-
getDatabaseName
protected static java.lang.String getDatabaseName(java.lang.Object hashMe)
-
setupDatabase
public void setupDatabase() throws TemporaryDatabaseException
- Throws:
TemporaryDatabaseException
-
setupBlame
protected static void setupBlame(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, java.lang.String blame)
-
dumpThreads
public static void dumpThreads()
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
update
public void update(java.lang.String stmt, java.lang.Object... values)
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
- Specified by:
getLogWriter
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- Specified by:
setLogWriter
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException
- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException
- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfacejavax.sql.CommonDataSource
- Throws:
java.sql.SQLFeatureNotSupportedException
-
getAdminDataSource
public javax.sql.DataSource getAdminDataSource()
-
getAdminXADataSource
public javax.sql.XADataSource getAdminXADataSource()
-
getDataSource
public javax.sql.DataSource getDataSource()
-
getXADataSource
public javax.sql.XADataSource getXADataSource()
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.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 interfacejava.sql.Wrapper
- 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:
java.sql.SQLException
- If no object found that implements the interface- Since:
- 1.6
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.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 interfacejava.sql.Wrapper
- Parameters:
iface
- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
java.sql.SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface.- Since:
- 1.6
-
getXAConnection
public javax.sql.XAConnection getXAConnection() throws java.sql.SQLException
- Specified by:
getXAConnection
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
getXAConnection
public javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
- Specified by:
getXAConnection
in interfacejavax.sql.XADataSource
- Throws:
java.sql.SQLException
-
generateLiquibaseHash
public java.lang.String generateLiquibaseHash() throws java.security.NoSuchAlgorithmException, java.io.IOException, java.lang.Exception, liquibase.exception.ChangeLogParseException, liquibase.exception.LiquibaseException
- Throws:
java.security.NoSuchAlgorithmException
java.io.IOException
java.lang.Exception
liquibase.exception.ChangeLogParseException
liquibase.exception.LiquibaseException
-
createIntegrationTestTemplateDatabase
protected void createIntegrationTestTemplateDatabase(java.lang.String dbName) throws java.lang.ClassNotFoundException, MigrationException, java.lang.Throwable, java.sql.SQLException
- Throws:
java.lang.ClassNotFoundException
MigrationException
java.lang.Throwable
java.sql.SQLException
-
-