org.gcube.messaging.common.consumer.db
Class DBManager

java.lang.Object
  extended by org.gcube.messaging.common.consumer.db.DBManager
Direct Known Subclasses:
AccountingDBManager, AccountingSystemDBManager, MonitoringDBManager

public abstract class DBManager
extends java.lang.Object

Author:
Luca Frosini (CNR), Andrea Manzi(CERN)

Nested Class Summary
static interface DBManager.BaseConsumer
           
 
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.
abstract  void open()
          Load the HSQL Database Engine JDBC driver and open the connection to the db.
 java.sql.ResultSet query(java.lang.String expression)
          Executes SQL command SELECT and invokes the given consumer.
 void queryAndConsume(java.lang.String expression, DBManager.BaseConsumer consumer)
          Executes SQL command SELECT and invokes the given consumer.
 java.lang.String queryDBRS(java.lang.String query)
          Executes a query an populates a RS
 java.lang.String queryJSON(java.lang.String expression)
          Executes SQL command SELECT and invokes the given consumer, giging back JSON formatetted output.
static java.lang.String toJSon(java.sql.ResultSet resultSet)
           
 void update(java.lang.String expression)
          Executes SQL commands CREATE, DROP, INSERT and UPDATE.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBManager

public DBManager()
Constructor for SQLDBManager

Method Detail

open

public abstract void open()
                   throws java.lang.ClassNotFoundException,
                          java.sql.SQLException,
                          java.lang.Exception
Load the HSQL Database Engine JDBC driver and open the connection to the db.

Throws:
java.lang.ClassNotFoundException - if the HSQL Database Engine JDBC driver is not loaded
java.sql.SQLException - if the connection to the db fails
java.lang.Exception - if the tables creation fails

close

public void close()
           throws java.lang.Exception
Shutdown the db and close the connection to the db.

Throws:
java.lang.Exception

backup

public void backup()
            throws java.sql.SQLException,
                   java.lang.Exception
checkpoint the db and create a backup

Throws:
java.sql.SQLException - if the CHECKPOINT query fails
java.lang.Exception

queryDBRS

public java.lang.String queryDBRS(java.lang.String query)
                           throws ResultSetPool.PoolNotInitializedException,
                                  java.lang.Exception
Executes a query an populates a RS

Parameters:
query - the SQL Query
Returns:
the RS Epr
Throws:
java.lang.Exception
ResultSetPool.PoolNotInitializedException

queryAndConsume

public void queryAndConsume(java.lang.String expression,
                            DBManager.BaseConsumer consumer)
                     throws java.sql.SQLException,
                            java.lang.Exception
Executes SQL command SELECT and invokes the given consumer.

Parameters:
expression - the SQL expression to evaluate
consumer - the resultset consumer to invoke
Throws:
java.sql.SQLException - if the query fails
java.lang.Exception - if the given resultset consumer fails

query

public java.sql.ResultSet query(java.lang.String expression)
                         throws java.sql.SQLException,
                                java.lang.Exception
Executes SQL command SELECT and invokes the given consumer.

Parameters:
expression - the SQL expression to evaluate
Returns:
Result Set
Throws:
java.sql.SQLException - if the query fails
java.lang.Exception - if the given resultset consumer fails

queryJSON

public java.lang.String queryJSON(java.lang.String expression)
                           throws java.sql.SQLException,
                                  java.lang.Exception
Executes SQL command SELECT and invokes the given consumer, giging back JSON formatetted output.

Parameters:
expression - the SQL expression to evaluate
Returns:
Result Set
Throws:
java.sql.SQLException - if the query fails
java.lang.Exception - if the given resultset consumer fails

update

public void update(java.lang.String expression)
            throws java.lang.Exception
Executes SQL commands CREATE, DROP, INSERT and UPDATE.

Parameters:
expression - the SQL expression to modify the db
Throws:
java.lang.Exception

toJSon

public static java.lang.String toJSon(java.sql.ResultSet resultSet)
                               throws java.sql.SQLException
Parameters:
resultSet -
Returns:
Json String
Throws:
java.sql.SQLException