ch.sahits.codegen.java.input
Class SQLCreateScriptInput

java.lang.Object
  extended by ch.sahits.codegen.java.input.SQLCreateScriptInput
All Implemented Interfaces:
IDBInputParser, IInputParser, ISQLCreateToken
Direct Known Subclasses:
MySQLCreateScriptInputParser, OracleSQLCreateScriptInputParser, SQLServerCreateScriptInputParser

public abstract class SQLCreateScriptInput
extends java.lang.Object
implements IDBInputParser, ISQLCreateToken

Base class for the parsing. All essential stuff is in this class. Only some db specific data must be implemented by the concrete class.

Since:
0.9.0
Author:
Andi Hotz

Field Summary
protected  boolean initialized
          Flag indicates of the parser is sufficiently initialized for the parsing
protected  EParserState state
          Holds the state of the Parser
 
Fields inherited from interface ch.sahits.codegen.java.input.ISQLCreateToken
CLOSE_CURLY_BRACE, CREATE, CREATE_DELIMITER, FIELD_DEFLIMITER, INDEX, LEFT_PARENTHESIS, NOT, NULL, ON, OPEN_CURLY_BRACE, RIGHT_PARENTHESIS, TABLE, UNIQUE
 
Constructor Summary
SQLCreateScriptInput()
          Default constructor
 
Method Summary
protected  java.lang.String createIndexName(java.lang.String hint)
          Create an index name
protected  java.lang.String getLines()
          Retrieve the SQL create script for the table
protected abstract  boolean hasTypeSize(java.lang.String type)
          Check if the type has any size property
protected abstract  boolean isAutogenKey(java.lang.String fieldName, IDataBaseTable dbt)
          Check whether the field name is an autogenerated key.
protected abstract  boolean isIndexConstraintToken(java.lang.String token)
          Check if the token is a Index constraint token.
 EDBConnectionData needsDataBaseInformationForCompleetion()
          Indicate if the input file is self contained or if for compleetion of the model information from the second page is needed.
 DataBaseTable parse()
          Parse the create script and produce a database model
protected  DataBaseTableIndex parseIndex(java.util.StringTokenizer st, java.lang.String lastToken, DataBaseTable table)
          Parse the script for the index definition.
protected  DataBaseTable parseTable(java.util.StringTokenizer st, DataBaseTable dbt)
          Parse the script for the table definition.
protected abstract  DataBaseTable parseTable(java.util.StringTokenizer st, java.lang.String className)
          Parse the script for the table definition.
protected  void readFile(java.io.BufferedReader inputStream)
          Read the contents of the file into a string array
 java.lang.String unquote(java.lang.String s)
          Unquote the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.sahits.codegen.input.IDBInputParser
convert2JavaType, getDatabaseName, getDefaultHost, getDefaultPort, getDefaultUser, getPassword, hasSchema, init
 
Methods inherited from interface ch.sahits.codegen.input.IInputParser
getFileExtension, getRanking, getWorkload, init
 

Field Detail

state

protected EParserState state
Holds the state of the Parser


initialized

protected boolean initialized
Flag indicates of the parser is sufficiently initialized for the parsing

Constructor Detail

SQLCreateScriptInput

public SQLCreateScriptInput()
Default constructor

Method Detail

readFile

protected final void readFile(java.io.BufferedReader inputStream)
                       throws java.io.IOException
Read the contents of the file into a string array

Parameters:
inputStream - Input stream to be read from
Throws:
java.io.IOException - Exception while reading from the stream

parse

public DataBaseTable parse()
Parse the create script and produce a database model

Specified by:
parse in interface IDBInputParser
Specified by:
parse in interface IInputParser
Returns:
Model of the database table

isIndexConstraintToken

protected abstract boolean isIndexConstraintToken(java.lang.String token)
Check if the token is a Index constraint token. Since the token may varey from database product to product the actual implementation is deferred

Parameters:
token - to be checked
Returns:
true if the token is an index constraint token

parseIndex

protected DataBaseTableIndex parseIndex(java.util.StringTokenizer st,
                                        java.lang.String lastToken,
                                        DataBaseTable table)
Parse the script for the index definition. The recognized format is: CREATE [constraint_token] INDEX [schema.]index_name ON [schema.]table (columns)

Parameters:
st - StringTokernizer
lastToken -
table - table model the index belongs to
Returns:
database model

parseTable

protected abstract DataBaseTable parseTable(java.util.StringTokenizer st,
                                            java.lang.String className)
Parse the script for the table definition. The recognized format is: CREATE [GLOBAL TEMPORARY] TABLE [schema.]table (fields)

Parameters:
st - StringTokernizer
className - name of the class
Returns:
database model

parseTable

protected DataBaseTable parseTable(java.util.StringTokenizer st,
                                   DataBaseTable dbt)
Parse the script for the table definition. The recognized format is: CREATE [GLOBAL TEMPORARY] TABLE [schema.]table (fields)

Parameters:
st - StringTokernizer
dbt - object to store the parsed info into
Returns:
database model

hasTypeSize

protected abstract boolean hasTypeSize(java.lang.String type)
Check if the type has any size property

Parameters:
type - to be checked
Returns:
true if a size is expected

createIndexName

protected final java.lang.String createIndexName(java.lang.String hint)
Create an index name

Parameters:
hint - hit at the index name
Returns:
name for an index

isAutogenKey

protected abstract boolean isAutogenKey(java.lang.String fieldName,
                                        IDataBaseTable dbt)
Check whether the field name is an autogenerated key. The definition of autogenerated keys is database specific. It may be defined in the create statement or outside of it. "http://e-docs.bea.com/workshop/docs92/ws_platform/ejb/entity/conAutomaticPrimaryKeyGeneration.html"

Parameters:
fieldName - name of the field that is to be checked
dbt - Database table model for with the autogenerated key is searched
Returns:
true if the field is an autogenerated key
Since:
1.2.0

getLines

protected final java.lang.String getLines()
Retrieve the SQL create script for the table

Returns:
create script as a String

unquote

public final java.lang.String unquote(java.lang.String s)
Unquote the string. If the string is quoted several times only the most outer quotes are unquoted. The order of checked quoting characters are ", ', ยด,`.

Parameters:
s - input string
Returns:
unquoted string

needsDataBaseInformationForCompleetion

public EDBConnectionData needsDataBaseInformationForCompleetion()
Indicate if the input file is self contained or if for compleetion of the model information from the second page is needed.

Specified by:
needsDataBaseInformationForCompleetion in interface IInputParser
Returns: