|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gcube.messaging.common.consumer.db.DBManager
public abstract class DBManager
Nested Class Summary | |
---|---|
static interface |
DBManager.BaseConsumer
|
Field Summary | |
---|---|
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 Summary | |
---|---|
DBManager()
Constructor for SQLDBManager |
Method Summary | |
---|---|
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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
public DBManager()
Method Detail |
---|
public abstract void open() throws ClassNotFoundException, SQLException, Exception
ClassNotFoundException
- if the HSQL Database Engine JDBC driver is not loaded
SQLException
- if the connection to the db fails
Exception
- if the tables creation failspublic void close() throws Exception
Exception
public void backup() throws SQLException, Exception
SQLException
- if the CHECKPOINT query fails
Exception
public void queryAndConsume(String expression, DBManager.BaseConsumer consumer) throws SQLException, Exception
expression
- the SQL expression to evaluateconsumer
- the resultset consumer to invoke
SQLException
- if the query fails
Exception
- if the given resultset consumer failspublic ResultSet query(String expression) throws SQLException, Exception
expression
- the SQL expression to evaluate
SQLException
- if the query fails
Exception
- if the given resultset consumer failspublic String queryJSON(String expression) throws SQLException, Exception
expression
- the SQL expression to evaluate
SQLException
- if the query fails
Exception
- if the given resultset consumer failspublic void update(String expression) throws Exception
expression
- the SQL expression to modify the db
Exception
protected void createDB() throws SQLException, Exception
SQLException
- if the tables creation fails
Exception
- if the parsing of query file failspublic static String toJSon(ResultSet resultSet) throws SQLException
resultSet
-
SQLException
protected static String quote(String string)
string
- A String
protected void zipFolder(File[] files) throws Exception
Exception
protected abstract void connectToMySql() throws Exception
Exception
protected void connectToEmbeddedDB() throws Exception
Exception
protected void reconnectToDB() throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |