uk.ac.ic.doc.automed.reps
Class RelationalOutputter

java.lang.Object
  extended by uk.ac.ic.doc.automed.reps.RelationalOutputter

public class RelationalOutputter
extends java.lang.Object

Class the materialise an SQL oriented AutoMed schema

Author:
Andrew Smith - acs203

Nested Class Summary
(package private)  class RelationalOutputter.SQLColumn
           
(package private)  class RelationalOutputter.SQLTable
          A class to store info about a SQL table before it is materialised
 
Field Summary
private  java.util.ArrayList allSchemaObjects
          A list of all the Schema Objects of type 'sql' in this schema
private  java.sql.Connection con
           
private  java.util.HashSet createdTables
           
private  Schema[] dataSourceSchemas
          The wrapped source shema we'll get the data from
private  java.lang.String dbDriver
           
private  java.lang.String dbName
          The name of database we create
private  Schema dsSchema
           
private  java.lang.String modelName
          The name of the SQL model to materialise
private  java.lang.String password
           
private  java.lang.String peerName
          The name of the peer if we're using this in P2P
private  Schema schema
          The schema with the sql constructs to output
private static java.lang.String SQL_MODEL_NAME
           
private  java.util.HashMap sqlTables
           
private  int tableUniqueIdentifier
          An identifier to add to a table name to make it unique to stop lots of table already exists errors during testing
private  java.lang.String url
           
private  java.lang.String username
           
 
Constructor Summary
RelationalOutputter(AutoMedPeer peer, Schema schema)
          Creates a new instance of RelationalOutputter with a default output directory for use with an AutoMed peer
RelationalOutputter(Schema schema, java.lang.String dbName)
          Creates a new instance of RelationalOutputter with a default output directory
RelationalOutputter(Schema s, java.lang.String dbDriver, java.lang.String url, java.lang.String username, java.lang.String password)
          Creates a new instance of RelationalOutputter with a given DB url, username and password
 
Method Summary
private  RelationalOutputter.SQLTable addColumns(SchemaObject[] columnsAndKeys, RelationalOutputter.SQLTable table)
           
private  boolean checkTableExists(RelationalOutputter.SQLTable table)
          Check to see if this table exists
 void connectToDB()
          Connect to the local database
private  java.lang.String createFKStatement(RelationalOutputter.SQLTable table)
           
 java.lang.String createRelationalTables()
          Create the relational tables from the automed schema objects
private  java.lang.String createSQLStatement(RelationalOutputter.SQLTable table)
           
private  void executeSQL()
          Execute a SQL statement to create a table
private  java.lang.String insertValues(RelationalOutputter.SQLTable table)
           
private  ASG querySourceSchema(java.lang.String query)
          Get the data from the source Schema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schema

private Schema schema
The schema with the sql constructs to output


dsSchema

private Schema dsSchema

allSchemaObjects

private java.util.ArrayList allSchemaObjects
A list of all the Schema Objects of type 'sql' in this schema


dataSourceSchemas

private Schema[] dataSourceSchemas
The wrapped source shema we'll get the data from


modelName

private java.lang.String modelName
The name of the SQL model to materialise


dbName

private java.lang.String dbName
The name of database we create


createdTables

private java.util.HashSet createdTables

sqlTables

private java.util.HashMap sqlTables

con

private java.sql.Connection con

url

private java.lang.String url

username

private java.lang.String username

password

private java.lang.String password

dbDriver

private java.lang.String dbDriver

SQL_MODEL_NAME

private static final java.lang.String SQL_MODEL_NAME
See Also:
Constant Field Values

tableUniqueIdentifier

private int tableUniqueIdentifier
An identifier to add to a table name to make it unique to stop lots of table already exists errors during testing


peerName

private java.lang.String peerName
The name of the peer if we're using this in P2P

Constructor Detail

RelationalOutputter

public RelationalOutputter(Schema schema,
                           java.lang.String dbName)
                    throws AutoMedException
Creates a new instance of RelationalOutputter with a default output directory

Throws:
AutoMedException

RelationalOutputter

public RelationalOutputter(AutoMedPeer peer,
                           Schema schema)
                    throws AutoMedException
Creates a new instance of RelationalOutputter with a default output directory for use with an AutoMed peer

Throws:
AutoMedException

RelationalOutputter

public RelationalOutputter(Schema s,
                           java.lang.String dbDriver,
                           java.lang.String url,
                           java.lang.String username,
                           java.lang.String password)
                    throws AutoMedException
Creates a new instance of RelationalOutputter with a given DB url, username and password

Parameters:
source - The source schema
s - The schema to be materialised
dbDriver - The db driver string
xmlDoc - Whether or not there is a XML instance document
url - The url of the output database
username - The username to log into the target db
password - The password to log into the output db
Throws:
AutoMedException - Thrown when theres a problem
Method Detail

addColumns

private RelationalOutputter.SQLTable addColumns(SchemaObject[] columnsAndKeys,
                                                RelationalOutputter.SQLTable table)
                                         throws AutoMedException
Throws:
AutoMedException

createSQLStatement

private java.lang.String createSQLStatement(RelationalOutputter.SQLTable table)
                                     throws AutoMedException
Throws:
AutoMedException

createFKStatement

private java.lang.String createFKStatement(RelationalOutputter.SQLTable table)
                                    throws AutoMedException
Throws:
AutoMedException

insertValues

private java.lang.String insertValues(RelationalOutputter.SQLTable table)

checkTableExists

private boolean checkTableExists(RelationalOutputter.SQLTable table)
Check to see if this table exists


executeSQL

private void executeSQL()
                 throws java.lang.Exception
Execute a SQL statement to create a table

Throws:
java.lang.Exception

querySourceSchema

private ASG querySourceSchema(java.lang.String query)
Get the data from the source Schema


connectToDB

public void connectToDB()
Connect to the local database


createRelationalTables

public java.lang.String createRelationalTables()
                                        throws AutoMedException,
                                               java.lang.Exception
Create the relational tables from the automed schema objects

Returns:
Return the SQL statement string
Throws:
java.lang.Exception - A SQL problem
AutoMedException - A repository problem