easik.sketch.util.Export
Class SketchToSchema

java.lang.Object
  extended by easik.sketch.util.Export.SketchToSchema

public class SketchToSchema
extends java.lang.Object

Sketch to Schema is a class which will accept a sketch and then generate an SQL schema. It can currently create a schema without constraints. Constraints will be implemented later using SQL triggers.

Version:
2006-06-16 Vera Ranieri
Author:
Rob Fletcher 2005, Vera Ranieri 2006

Field Summary
private  java.lang.String _createString
          The string CREATE DATABASE name
private  ExportHandler _eHandler
          The export handler associated with this sketch
private  java.util.LinkedList<java.lang.String> _finalTables
          A list of all the table to be defined
private  java.util.ArrayList<java.lang.String> _procedures
          A list of al the procedures to be defined.
private  ExportTriggerFormatter _triggers
          The Trigger formatter associated with this sketch
private  java.lang.String _useString
          The string USE name
 
Constructor Summary
SketchToSchema(ExportHandler sh, java.lang.String name)
          This is the constructor that takes the ExportHandler containing information via the XML file (that is, bypassing all sketch information) and provides the output schema.
 
Method Summary
private  void addUnmarkedParents(java.util.HashMap tables, java.util.LinkedList workingSet, java.util.ListIterator<ExportTable> listIterator, ExportTable currentTable)
          Find all the unmarked parents of marked nodes, add them to the provided listIterator.
private  boolean areNeighborsMarked(java.util.HashMap tables, ExportTable t)
          A helper method which will check to see if the neighbours of a current table have been marked.
 java.util.ArrayList<java.lang.String> getConstraints()
          Getter method for the set of constraints of the schema.
 java.lang.String getCreateString()
          Getter method for the CREATE DATABASE name SQL string
private  java.util.LinkedList<ExportTable> getSinks(java.util.HashMap tables)
          Find all the tables in the sketch that do not have any outgoing edges.
 java.util.LinkedList<java.lang.String> getTables()
          Getter method for the constructed set of tables
 java.util.ArrayList<java.lang.String> getTriggers()
          Getter method for all triggers formed from the table.
 java.lang.String getUseString()
          Getter method for the USE database SQL string.
private  java.lang.String newTable(ExportTable table)
          Given a table, create a SQL table (which is a string).
private  void printSchemaInfo()
          Temporary method to print schema info.
private  void setConstraints()
          Sets the constraint string for this schema
 void setCreateString(java.lang.String name)
          Setter method for the CREATE DATABASE name SQL string.
private  void setTables()
          A method to set all tables associated with the schema.
 void setUseString(java.lang.String name)
          Sets the USE database string for the schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_finalTables

private java.util.LinkedList<java.lang.String> _finalTables
A list of all the table to be defined


_procedures

private java.util.ArrayList<java.lang.String> _procedures
A list of al the procedures to be defined.


_createString

private java.lang.String _createString
The string CREATE DATABASE name


_useString

private java.lang.String _useString
The string USE name


_triggers

private ExportTriggerFormatter _triggers
The Trigger formatter associated with this sketch


_eHandler

private ExportHandler _eHandler
The export handler associated with this sketch

Constructor Detail

SketchToSchema

public SketchToSchema(ExportHandler sh,
                      java.lang.String name)
This is the constructor that takes the ExportHandler containing information via the XML file (that is, bypassing all sketch information) and provides the output schema.

Parameters:
sh - The ExportHandler containg information about the sketch gleaned from the XML file.
name - The name of the database to be created.
Method Detail

setTables

private void setTables()
A method to set all tables associated with the schema. Setting the tables includes setting all primary, foreign, and unique keys for the table.


getSinks

private java.util.LinkedList<ExportTable> getSinks(java.util.HashMap tables)
Find all the tables in the sketch that do not have any outgoing edges.

Parameters:
tables - The hashmap of all tables contained in this sketch
Returns:
A linked list of the current sinks

areNeighborsMarked

private boolean areNeighborsMarked(java.util.HashMap tables,
                                   ExportTable t)
A helper method which will check to see if the neighbours of a current table have been marked.

Parameters:
tables - The tables of this sketch
t - The current table for which it must be determined whether neighbours are marked.
Returns:
The truth about the marked neighbors (true if they are marked)

addUnmarkedParents

private void addUnmarkedParents(java.util.HashMap tables,
                                java.util.LinkedList workingSet,
                                java.util.ListIterator<ExportTable> listIterator,
                                ExportTable currentTable)
Find all the unmarked parents of marked nodes, add them to the provided listIterator.

Parameters:
tables - The set of tables for the sketch
workingSet - The tables which are currently 'in play'
listIterator - The list iterator containing where we are in the nodes
currentTable - The table whose unmarked parents we're looking for

newTable

private java.lang.String newTable(ExportTable table)
Given a table, create a SQL table (which is a string).

Parameters:
table - The table which is getting its own SQL table
Returns:
A String containing a light description of the table (keys and foreign keys)
Since:
2006-05-17, Vera Ranieri

getTables

public java.util.LinkedList<java.lang.String> getTables()
Getter method for the constructed set of tables

Returns:
The tables needed in the schema
Since:
2006-05-10, Vera Ranieri

getConstraints

public java.util.ArrayList<java.lang.String> getConstraints()
Getter method for the set of constraints of the schema.

Returns:
The constraints needed in the schema
Since:
2006-05-10, Vera Ranieri

getTriggers

public java.util.ArrayList<java.lang.String> getTriggers()
Getter method for all triggers formed from the table. Triggers are amalgamated into one arraylist for easy access for passing to the jdbc connector.

Returns:
The arraylist of all triggers
Since:
2006-06-16, Vera Ranieri

getCreateString

public java.lang.String getCreateString()
Getter method for the CREATE DATABASE name SQL string

Returns:
The "CREATE DATABASE..." string
Since:
2006-05-10, Vera Ranieri

setCreateString

public void setCreateString(java.lang.String name)
Setter method for the CREATE DATABASE name SQL string. Takes the name of the database as the input, and appends it to the appropriate SQL string that will create a database.

Parameters:
name - The name of the database
Since:
2006-05-17, Vera Ranieri

getUseString

public java.lang.String getUseString()
Getter method for the USE database SQL string.

Returns:
The "USE ... " string
Since:
2006-05-17, Vera Ranieri

setUseString

public void setUseString(java.lang.String name)
Sets the USE database string for the schema.

Parameters:
name - The name of the database
Since:
2006-05-17, Vera Ranieri

setConstraints

private void setConstraints()
Sets the constraint string for this schema

Since:
2006-06-09, Vera Ranieri

printSchemaInfo

private void printSchemaInfo()
Temporary method to print schema info. Will be removed once all testing is completed

Since:
2006-05-18, Vera Ranieri