edu.udo.cs.yale.tools.jdbc
Class DatabaseHandler

java.lang.Object
  extended by edu.udo.cs.yale.tools.jdbc.DatabaseHandler

public class DatabaseHandler
extends java.lang.Object

This class hides the database. Using connect(String,String,boolean), you can extablish a connection to the database. Once connected, queries and updates are possible.

Version:
$Id: DatabaseHandler.java,v 1.6 2006/09/29 10:59:41 ingomierswa Exp $
Author:
Timm Euler, Ingo Mierswa, Simon Fischer

Field Summary
private  java.lang.String databaseURL
           
private  java.sql.Connection myCon
           
 
Constructor Summary
DatabaseHandler(java.lang.String databaseURL)
          Constructor of the database handler.
 
Method Summary
 void addColumn(Attribute attribute, java.lang.String tableName)
          Adds a column for the given attribute to the table with name tableName.
 void commit()
          Makes all changes to the database permanent.
 void connect(java.lang.String username, java.lang.String passwd, boolean autoCommit)
          Establishes a connection to the database.
 int countRecords(java.sql.ResultSet rs)
          Counts the number of records in the given result set.
static java.util.List<Attribute> createAttributes(java.sql.ResultSet rs)
          Creates a list of attributes reflecting the result set's column meta data.
 void disconnect()
          Closes the connection to the database.
private  java.util.List<java.lang.String> getAllColumnNames(java.lang.String tableName)
           
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAllTableMetaData()
           
static java.lang.String getDatabaseName(Attribute attribute)
           
static int getYaleTypeIndex(int sqlType)
          Returns for the given SQL-type the name of the corresponding Yale-Type from edu.udo.cs.yale.tools.Ontology.
 java.sql.ResultSet query(java.lang.String sqlQuery)
          Executes the given SQL-Query.
 void removeColumn(Attribute attribute, java.lang.String tableName)
          Removes the column of the given attribute from the table with name tableName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

databaseURL

private java.lang.String databaseURL

myCon

private java.sql.Connection myCon
Constructor Detail

DatabaseHandler

public DatabaseHandler(java.lang.String databaseURL)
Constructor of the database handler. This constructor expects the URL definition of the database which is needed by the System DriverManager to create an appropriate driver.

Method Detail

connect

public void connect(java.lang.String username,
                    java.lang.String passwd,
                    boolean autoCommit)
             throws java.sql.SQLException
Establishes a connection to the database. Afterwards, queries and updates can be executed using the methods this class provides.

Parameters:
username - Name with which to log in to the database.
passwd - Password with which to log in to the database.
autoCommit - If TRUE, all changes to the database will be committed automatically. If FALSE, the commit()-Method has to be called to make changes permanent.
Throws:
java.sql.SQLException


disconnect

public void disconnect()
                throws java.sql.SQLException
Closes the connection to the database.

Throws:
java.sql.SQLException


query

public java.sql.ResultSet query(java.lang.String sqlQuery)
                         throws java.sql.SQLException
Executes the given SQL-Query. Only SQL-statements starting with "SELECT" (disregarding case) will be accepted. Any errors will result in an SQL-Exception being thrown.

Parameters:
sqlQuery - An SQL-String.
Returns:
A ResultSet-Object with the results of the query. The ResultSet is scrollable, but not not updatable. It will not show changes to the database made by others after this ResultSet was obtained.
Throws:
java.sql.SQLException


addColumn

public void addColumn(Attribute attribute,
                      java.lang.String tableName)
               throws java.sql.SQLException
Adds a column for the given attribute to the table with name tableName.

Throws:
java.sql.SQLException


removeColumn

public void removeColumn(Attribute attribute,
                         java.lang.String tableName)
                  throws java.sql.SQLException
Removes the column of the given attribute from the table with name tableName.

Throws:
java.sql.SQLException


countRecords

public int countRecords(java.sql.ResultSet rs)
                 throws java.sql.SQLException
Counts the number of records in the given result set.

Parameters:
rs - The ResultSet.
Throws:
java.sql.SQLException


commit

public void commit()
            throws java.sql.SQLException
Makes all changes to the database permanent.

Throws:
java.sql.SQLException


getYaleTypeIndex

public static int getYaleTypeIndex(int sqlType)
Returns for the given SQL-type the name of the corresponding Yale-Type from edu.udo.cs.yale.tools.Ontology.


createAttributes

public static java.util.List<Attribute> createAttributes(java.sql.ResultSet rs)
                                                  throws java.sql.SQLException
Creates a list of attributes reflecting the result set's column meta data.

Throws:
java.sql.SQLException


getDatabaseName

public static java.lang.String getDatabaseName(Attribute attribute)

getAllTableMetaData

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getAllTableMetaData()
                                                                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

getAllColumnNames

private java.util.List<java.lang.String> getAllColumnNames(java.lang.String tableName)
                                                    throws java.sql.SQLException
Throws:
java.sql.SQLException


Copyright © 2001-2006