Package org.duracloud.common.util
Class DatabaseUtil
- java.lang.Object
-
- org.duracloud.common.util.DatabaseUtil
-
public abstract class DatabaseUtil extends Object
This abstract class provides the ability to create/clear/remove a database and its tables. It also provides a 'javax.sql.DataSource' for the database. Finally, sql operations can be executed on the database through the retrieval of the 'JdbcOperations' object provided by the method: getOps().
- Author:
- Andrew Woods
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogstatic StringNOT_ENCRYPTED
-
Constructor Summary
Constructors Constructor Description DatabaseUtil(Credential cred, String baseDir)DatabaseUtil(Credential cred, String baseDir, String bootPassword)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclearDB()voiddisconnect()voidensureDatabaseExists()voidensureTablesExist()protected voidexecute(String sql)DataSourcegetDataSource()org.springframework.jdbc.core.JdbcOperationsgetOps()org.springframework.jdbc.core.JdbcTemplategetSimpleJdbcTemplate()protected abstract List<TableSpec>getTableSpecs()voidinitializeDB()This method sets-up empty tables for this database.
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
NOT_ENCRYPTED
public static String NOT_ENCRYPTED
-
-
Constructor Detail
-
DatabaseUtil
public DatabaseUtil(Credential cred, String baseDir)
-
DatabaseUtil
public DatabaseUtil(Credential cred, String baseDir, String bootPassword)
-
-
Method Detail
-
initializeDB
public void initializeDB() throws ExceptionThis method sets-up empty tables for this database.- Throws:
Exception
-
ensureDatabaseExists
public void ensureDatabaseExists()
-
ensureTablesExist
public void ensureTablesExist() throws SQLException- Throws:
SQLException
-
clearDB
public void clearDB()
-
disconnect
public void disconnect()
-
getSimpleJdbcTemplate
public org.springframework.jdbc.core.JdbcTemplate getSimpleJdbcTemplate()
-
getDataSource
public DataSource getDataSource()
-
getOps
public org.springframework.jdbc.core.JdbcOperations getOps()
-
execute
protected void execute(String sql)
-
-