org.gcube.vremanagement.softwarerepository.db
Class SQLDBManager

java.lang.Object
  extended by org.gcube.vremanagement.softwarerepository.db.SQLDBManager

public class SQLDBManager
extends java.lang.Object

This class is used for submitting query on db.

Author:
Luca Frosini (ISTI-CNR)

Nested Class Summary
static interface SQLDBManager.BaseConsumer
          Describe the Consumer of ResultSet returned quering the db
 
Constructor Summary
SQLDBManager()
          Constructor for SQLDBManager
SQLDBManager(java.lang.String dbFileName, java.lang.String username, java.lang.String password, java.io.File queriesFile)
          Constructor for SQLDBManager
 
Method Summary
 void close()
          Shutdown the db and close the connection to the db.
 void open()
          Load the HSQL Database Engine JDBC driver and open the connection to the db.
 void queryAndConsume(java.lang.String expression, SQLDBManager.BaseConsumer consumer)
          Executes SQL command SELECT and invokes the given consumer.
 void runSQLQuery(java.lang.String expression)
          Executes SQL commands CREATE, DROP, INSERT and UPDATE.
 java.sql.ResultSet runSQLSelect(java.lang.String expression)
          Executes SQL command SELECT and invokes the given consumer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLDBManager

public SQLDBManager()
Constructor for SQLDBManager


SQLDBManager

public SQLDBManager(java.lang.String dbFileName,
                    java.lang.String username,
                    java.lang.String password,
                    java.io.File queriesFile)
Constructor for SQLDBManager

Parameters:
dbFileName - file name of the db
username - username
password - password
queriesFile - query file for db initialization
Method Detail

open

public 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.sql.SQLException
Shutdown the db and close the connection to the db.

Throws:
java.sql.SQLException - if the SHUTDOWN query fails

queryAndConsume

public void queryAndConsume(java.lang.String expression,
                            SQLDBManager.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

runSQLSelect

public java.sql.ResultSet runSQLSelect(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

runSQLQuery

public void runSQLQuery(java.lang.String expression)
                 throws java.sql.SQLException
Executes SQL commands CREATE, DROP, INSERT and UPDATE.

Parameters:
expression - the SQL expression to modify the db
Throws:
java.sql.SQLException - if the query fails