maito.browsing
Class ResourceBrowser

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

public class ResourceBrowser
extends java.lang.Object

A class that can be used for creating a view into the data in the resource database. Data is retrieved through sql queries. After a query is executed the data is available through the getResources() and getRelations() methods. Queries can also be used for deleting data from the database.

Author:
Antti Laitinen

Constructor Summary
ResourceBrowser()
          Creates a new ResourceBrowser instance.
 
Method Summary
 void executeSQL(java.lang.String sql, java.lang.String graph)
          Executes an SQL query in the resource database.
 java.lang.String[] getFileFormats()
          Returns all file formats that are supported by the FileExporter.
 java.lang.String[] getGraphs()
          Returns all existing resource graphs.
static void main(java.lang.String[] args)
           
 Resource nextResource()
          Returns the next Resource object produced by the latest query.
 boolean writeToFile(java.lang.String filename, java.lang.String format)
          Writes the current view into a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBrowser

public ResourceBrowser()
                throws java.lang.RuntimeException
Creates a new ResourceBrowser instance.

Throws:
java.lang.RuntimeException - Thrown when a database connection cannot be created.
Method Detail

getGraphs

public java.lang.String[] getGraphs()
Returns all existing resource graphs.

Returns:
An array containing the database name of each graph. If no resource graphs exist the array is empty.

nextResource

public Resource nextResource()
                      throws java.sql.SQLException
Returns the next Resource object produced by the latest query.

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

getFileFormats

public java.lang.String[] getFileFormats()
Returns all file formats that are supported by the FileExporter.

Returns:
An array containg the names of the supported file formats.

executeSQL

public void executeSQL(java.lang.String sql,
                       java.lang.String graph)
                throws java.sql.SQLException
Executes an SQL query in the resource database. The resulting data can be later retrieved using the getters in this class.

Parameters:
sql - The SQL query to be executed. The query must be syntactically correct SQL. Table names must be in format: database.table.
graph - The name of the database where the query is executed. Must be one of the Strings returned by getGraphs().
Throws:
java.sql.SQLException

writeToFile

public boolean writeToFile(java.lang.String filename,
                           java.lang.String format)
Writes the current view into a file.

Parameters:
filename - The path and filename of the file.
format - The format of the file. Must one of the supported formats.
Returns:
A boolean telling whether the file was saved successfully.

main

public static void main(java.lang.String[] args)