public abstract class DBManager extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
DBManager.BaseConsumer |
Modifier and Type | Field and Description |
---|---|
protected static File |
backupFolder |
protected static int |
backupIntervalMS |
protected Connection |
connection
Connection to the db - persist for life of program
|
protected String |
dbFileBaseFolder
dbFileName is used to open or create files that hold the state
of the db.
|
protected String |
dbFileName |
protected String |
dbName |
protected String |
password
Password for db connection
|
protected PoolManager |
poolManager |
protected File |
queriesFile
Queries file
|
protected String |
username
Username for db connection
|
Constructor and Description |
---|
DBManager()
Constructor for SQLDBManager
|
Modifier and Type | Method and Description |
---|---|
void |
backup()
checkpoint the db and create a backup
|
void |
close()
Shutdown the db and close the connection to the db.
|
protected void |
connectToEmbeddedDB()
Load the HSQL Database Engine JDBC driver
hsqldb.jar should be in the class path or made part of
the current jar
|
protected abstract void |
connectToMySql() |
protected void |
createDB()
Create db tables.
|
abstract void |
open()
Load the HSQL Database Engine JDBC driver and open the connection to the db.
|
ResultSet |
query(String expression)
Executes SQL command SELECT and invokes the given consumer.
|
void |
queryAndConsume(String expression,
DBManager.BaseConsumer consumer)
Executes SQL command SELECT and invokes the given consumer.
|
String |
queryJSON(String expression)
Executes SQL command SELECT and invokes the given consumer, giging back JSON formatetted output.
|
protected static String |
quote(String string)
Produce a string in double quotes with backslash sequences in all the
right places.
|
protected void |
reconnectToDB() |
static String |
toJSon(ResultSet resultSet) |
void |
update(String expression)
Executes SQL commands CREATE, DROP, INSERT and UPDATE.
|
protected void |
zipFolder(File[] files) |
protected Connection connection
protected static File backupFolder
protected String dbFileBaseFolder
protected String dbFileName
protected String dbName
protected String username
protected String password
protected File queriesFile
protected PoolManager poolManager
protected static int backupIntervalMS
public abstract void open() throws ClassNotFoundException, SQLException, Exception
ClassNotFoundException
- if the HSQL Database Engine JDBC driver is not loadedSQLException
- if the connection to the db failsException
- if the tables creation failspublic void close() throws Exception
Exception
public void backup() throws SQLException, Exception
SQLException
- if the CHECKPOINT query failsException
public void queryAndConsume(String expression, DBManager.BaseConsumer consumer) throws SQLException, Exception
expression
- the SQL expression to evaluateconsumer
- the resultset consumer to invokeSQLException
- if the query failsException
- if the given resultset consumer failspublic ResultSet query(String expression) throws SQLException, Exception
expression
- the SQL expression to evaluateSQLException
- if the query failsException
- if the given resultset consumer failspublic String queryJSON(String expression) throws SQLException, Exception
expression
- the SQL expression to evaluateSQLException
- if the query failsException
- if the given resultset consumer failspublic void update(String expression) throws Exception
expression
- the SQL expression to modify the dbException
protected void createDB() throws SQLException, Exception
SQLException
- if the tables creation failsException
- if the parsing of query file failspublic static String toJSon(ResultSet resultSet) throws SQLException
resultSet
- SQLException
protected static String quote(String string)
string
- A Stringprotected void connectToEmbeddedDB() throws Exception
Exception
Copyright © 2014. All Rights Reserved.