maito.browsing
Class DatabaseManager

java.lang.Object
  extended by maito.browsing.DatabaseManager

public class DatabaseManager
extends java.lang.Object

A class that takes care of all database related operations for the class maito.browsing.ResourceBrowser

Author:
Antti Laitinen

Constructor Summary
protected DatabaseManager()
          Creates a new DatabaseManager object.
 
Method Summary
protected  void executeLatestQuery()
           
protected  void executeSQL(java.lang.String sql, java.lang.String graph)
          Executes an SQL query in the database.
protected  java.lang.String[] getGraphs()
          Returns all available resource graphs (database names).
protected  ResourceRelation[] getRelations(Resource resource)
          Fetches all relations for a single resource.
protected  Resource nextResource()
          Fetches the next resource produced by the latest query (by the method executeSQL()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseManager

protected DatabaseManager()
                   throws java.sql.SQLException
Creates a new DatabaseManager object.

Throws:
java.sql.SQLException - Thrown when initialization of the database connection fails
Method Detail

executeSQL

protected void executeSQL(java.lang.String sql,
                          java.lang.String graph)
                   throws java.sql.SQLException
Executes an SQL query in the database. Creates and returns Resource objects reflecting each row.

Parameters:
sql - The whole query.
database - The name of the database where the query is executed in.
Throws:
java.sql.SQLException

executeLatestQuery

protected void executeLatestQuery()
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

nextResource

protected Resource nextResource()
                         throws java.sql.SQLException
Fetches the next resource produced by the latest query (by the method executeSQL()).

Returns:
A Resource object. null if the latest query didn't produce any Resources or if all Resources are already fetched using this method.
Throws:
java.sql.SQLException

getGraphs

protected java.lang.String[] getGraphs()
Returns all available resource graphs (database names).

Returns:
An array of existing database names. If no resource graphs exist the array is empty.

getRelations

protected ResourceRelation[] getRelations(Resource resource)
                                   throws java.sql.SQLException
Fetches all relations for a single resource.

Parameters:
resource -
Returns:
An array of the ResourceRelation object. null if no relations exist.
Throws:
java.sql.SQLException