org.vizzini.database
Class Database

java.lang.Object
  extended by org.vizzini.database.Database
All Implemented Interfaces:
IDatabase

 class Database
extends Object
implements IDatabase

Provides a database implementation which uses the Hypersonic SQL Database.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
 
Fields inherited from interface org.vizzini.database.IDatabase
ID_FIELD_NAME
 
Constructor Summary
protected Database(DBDescriptor descriptor)
          Construct this object from the given database descriptor.
protected Database(DBDescriptor descriptor, boolean isFileBased)
          Construct this object from the given database descriptor.
(package private) Database(Document document)
          Construct this object from the given file.
(package private) Database(File file)
          Construct this object from the given file.
(package private) Database(InputStream inputStream)
          Construct this object from the given file.
 
Method Summary
protected  void create(DBDescriptor descriptor)
          Create the database tables using the given descriptor.
protected  List createRecordsFrom(ITableData tableData, ResultSet rs)
          Create IRecord objects from the given result set.
protected  void createTable(ITableData tableData)
          Create a database table using the given table data.
 List executeQuery(String expression)
          Returns a list of GenericData s which are derived from the result of the given query.
 Iterator getJoinData()
          Return an iterator over the join data.
 Iterator getJoinsFor(ITableData tableData)
          Return all joins which involve the given table.
 Iterator getJoinsFor(ITableData tableData0, ITableData tableData1)
          Return all joins which involve the given tables.
 Iterator getJunctionsFor(ITableData tableData)
          Return all junctions which involve the given table.
 Iterator getJunctionsFor(ITableData tableData0, ITableData tableData1)
          Return all junctions which involve the given tables.
 Iterator getTableData()
          Return an iterator over the table data.
 ITableData getTableData(String tableName)
          Return the table data with the given name.
 boolean isStringType(ITableData tableData, String columnName)
          Return true if the given column has string type.
 boolean isStringType(String tableName, String columnName)
          Return true if the given column has string type.
protected static void printList(String title, List rows)
           
 List select(ITableData tableData)
          Returns a list of IRecord s which are derived from the result of the given query.
 List select(ITableData tableData, IRecord record)
          Return a list of IRecord objects which belong to the named table and are joined to the given record.
 List select(ITableData tableData, String whereClause)
          Returns a list of IRecord s which are derived from the result of the given query.
 List select(String tableName)
          Returns a list of IRecord s which are derived from the result of the given query.
 List select(String tableName, String whereClause)
          Returns a list of IRecord s which are derived from the result of the given query.
 void shutdown()
          Shutdown the database connection.
 String toString()
          Return a string representation of this object.
 void update(String expression)
          Update the database by executing the given expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Database

protected Database(DBDescriptor descriptor)
            throws ClassNotFoundException,
                   SQLException
Construct this object from the given database descriptor.

Throws:
ClassNotFoundException
SQLException
Since:
v0.3

Database

protected Database(DBDescriptor descriptor,
                   boolean isFileBased)
            throws ClassNotFoundException,
                   SQLException
Construct this object from the given database descriptor.

Throws:
ClassNotFoundException
SQLException
Since:
v0.3

Database

Database(Document document)
   throws ClassNotFoundException,
          SQLException
Construct this object from the given file.

Parameters:
document - Document containing the database descriptor information.
Throws:
ClassNotFoundException
SQLException
Since:
v0.3

Database

Database(File file)
   throws ParserConfigurationException,
          SAXException,
          IOException,
          ClassNotFoundException,
          SQLException
Construct this object from the given file.

Parameters:
file - File containing the database descriptor information.
Throws:
ParserConfigurationException
SAXException
IOException
ClassNotFoundException
SQLException
Since:
v0.3

Database

Database(InputStream inputStream)
   throws ParserConfigurationException,
          SAXException,
          IOException,
          ClassNotFoundException,
          SQLException
Construct this object from the given file.

Parameters:
inputStream - Input stream containing the database descriptor information.
Throws:
ParserConfigurationException
SAXException
IOException
ClassNotFoundException
SQLException
Since:
v0.3
Method Detail

executeQuery

public List executeQuery(String expression)
                  throws SQLException
Returns a list of GenericData s which are derived from the result of the given query.

Specified by:
executeQuery in interface IDatabase
Parameters:
expression - An SQL expression, typically a select.
Throws:
SQLException
Since:
v0.3

getJoinData

public Iterator getJoinData()
Return an iterator over the join data.

Specified by:
getJoinData in interface IDatabase
Since:
v0.3

getJoinsFor

public Iterator getJoinsFor(ITableData tableData)
Return all joins which involve the given table.

Specified by:
getJoinsFor in interface IDatabase
Returns:
A list containing IAssociation s.
Since:
v0.3

getJoinsFor

public Iterator getJoinsFor(ITableData tableData0,
                            ITableData tableData1)
Return all joins which involve the given tables.

Specified by:
getJoinsFor in interface IDatabase
Returns:
A list containing IAssociation s.
Since:
v0.3

getJunctionsFor

public Iterator getJunctionsFor(ITableData tableData)
Return all junctions which involve the given table.

Specified by:
getJunctionsFor in interface IDatabase
Returns:
A list containing IAssociation s.
Since:
v0.3

getJunctionsFor

public Iterator getJunctionsFor(ITableData tableData0,
                                ITableData tableData1)
Return all junctions which involve the given tables.

Specified by:
getJunctionsFor in interface IDatabase
Returns:
A list containing IAssociation s.
Since:
v0.3

getTableData

public Iterator getTableData()
Return an iterator over the table data.

Specified by:
getTableData in interface IDatabase
Since:
v0.3

getTableData

public ITableData getTableData(String tableName)
Return the table data with the given name.

Specified by:
getTableData in interface IDatabase
Since:
v0.3

isStringType

public boolean isStringType(String tableName,
                            String columnName)
Return true if the given column has string type.

Specified by:
isStringType in interface IDatabase
Since:
v0.3

isStringType

public boolean isStringType(ITableData tableData,
                            String columnName)
Return true if the given column has string type.

Specified by:
isStringType in interface IDatabase
Since:
v0.3

select

public List select(String tableName)
            throws SQLException
Returns a list of IRecord s which are derived from the result of the given query.

Specified by:
select in interface IDatabase
Parameters:
tableName - The table name from which to select.
Throws:
SQLException
Since:
v0.3

select

public List select(ITableData tableData)
            throws SQLException
Returns a list of IRecord s which are derived from the result of the given query.

Specified by:
select in interface IDatabase
Parameters:
tableData - The table data from which to select.
Throws:
SQLException
Since:
v0.3

select

public List select(String tableName,
                   String whereClause)
            throws SQLException
Returns a list of IRecord s which are derived from the result of the given query.

Specified by:
select in interface IDatabase
Parameters:
tableName - The table name from which to select.
whereClause - An optional where clause (without the where).
Throws:
SQLException
Since:
v0.3

select

public List select(ITableData tableData,
                   String whereClause)
            throws SQLException
Returns a list of IRecord s which are derived from the result of the given query.

Specified by:
select in interface IDatabase
Parameters:
tableData - The table data from which to select.
whereClause - An optional where clause (without the where).
Throws:
SQLException
Since:
v0.3

select

public List select(ITableData tableData,
                   IRecord record)
            throws SQLException
Return a list of IRecord objects which belong to the named table and are joined to the given record.

Specified by:
select in interface IDatabase
Parameters:
tableData - The table data from which to select.
record - The object to which the answers are related.
Throws:
SQLException
Since:
v0.3

shutdown

public void shutdown()
              throws SQLException
Shutdown the database connection.

Specified by:
shutdown in interface IDatabase
Throws:
SQLException
Since:
v0.3

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Since:
v0.3

update

public void update(String expression)
            throws SQLException
Update the database by executing the given expression. Use for SQL commands DROP and INSERT and UPDATE

Specified by:
update in interface IDatabase
Parameters:
expression - The expression to execute.
Throws:
SQLException

printList

protected static void printList(String title,
                                List rows)

create

protected void create(DBDescriptor descriptor)
Create the database tables using the given descriptor.

Since:
v0.3

createRecordsFrom

protected List createRecordsFrom(ITableData tableData,
                                 ResultSet rs)
                          throws SQLException
Create IRecord objects from the given result set.

Throws:
SQLException
Since:
v0.3

createTable

protected void createTable(ITableData tableData)
Create a database table using the given table data.

Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02