jimm.datavision.testdata
Class SchemaGen

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by jimm.datavision.testdata.SchemaGen
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
MySQLSchemaGen, OracleSchemaGen, PostgreSQLSchemaGen

public abstract class SchemaGen
extends org.xml.sax.helpers.DefaultHandler

Skeleton for creating a schema.sql file by reading an XML description of a schema.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  boolean isFirstColumn
           
protected  boolean notNull
           
protected  boolean primaryKey
           
protected  int size
           
protected  java.lang.String type
           
 
Constructor Summary
SchemaGen()
           
 
Method Summary
protected  void column(org.xml.sax.Attributes attributes)
          Parses a column XML tag and calls printColumn.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
protected abstract  void endTable()
          Outputs the SQL needed to close a create table statement.
protected abstract  void makeTable(java.lang.String tableName)
          Outputs the SQL needed to create a database table.
protected  java.lang.String printableName(java.lang.String name)
           
protected  void printColumn(java.lang.String columnName, java.lang.String type, int size, boolean notNull, boolean primaryKey)
          Prints the SQL needed to create a database column within a create table statement.
protected  void printColumnName(java.lang.String columnName)
          Prints the column name, taking into account case, blanks, and other possibly funky things.
protected abstract  void printNotNull()
          Prints the SQL that defines a column as NOT NULL.
protected abstract  void printPrimaryKey()
          Prints the SQL that defines a column as a primary key.
protected abstract  void printType(java.lang.String type, int size)
          Prints the SQL that defines a column's type.
 void run(java.lang.String schemaXMLFile)
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
           
protected  void table(org.xml.sax.Attributes attributes)
          Parses a table XML tag and calls makeTable.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

protected java.lang.String type

size

protected int size

notNull

protected boolean notNull

primaryKey

protected boolean primaryKey

isFirstColumn

protected boolean isFirstColumn
Constructor Detail

SchemaGen

public SchemaGen()
Method Detail

run

public void run(java.lang.String schemaXMLFile)

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

table

protected void table(org.xml.sax.Attributes attributes)
Parses a table XML tag and calls makeTable.

Parameters:
attributes - XML element attributes
See Also:
makeTable(java.lang.String)

column

protected void column(org.xml.sax.Attributes attributes)
Parses a column XML tag and calls printColumn. Also handles commas and indentation.

Parameters:
attributes - XML element attributes
See Also:
makeTable(java.lang.String)

makeTable

protected abstract void makeTable(java.lang.String tableName)
Outputs the SQL needed to create a database table. Optionally prints the SQL needed to destroy the table first.


printableName

protected java.lang.String printableName(java.lang.String name)

endTable

protected abstract void endTable()
Outputs the SQL needed to close a create table statement.


printColumn

protected void printColumn(java.lang.String columnName,
                           java.lang.String type,
                           int size,
                           boolean notNull,
                           boolean primaryKey)
Prints the SQL needed to create a database column within a create table statement.


printColumnName

protected void printColumnName(java.lang.String columnName)
Prints the column name, taking into account case, blanks, and other possibly funky things.


printType

protected abstract void printType(java.lang.String type,
                                  int size)
Prints the SQL that defines a column's type.


printNotNull

protected abstract void printNotNull()
Prints the SQL that defines a column as NOT NULL.


printPrimaryKey

protected abstract void printPrimaryKey()
Prints the SQL that defines a column as a primary key.