ch.sahits.codegen.java.input.db
Class MySQLCreateScriptInputParser

java.lang.Object
  extended by ch.sahits.codegen.java.input.SQLCreateScriptInput
      extended by ch.sahits.codegen.java.input.db.MySQLCreateScriptInputParser
All Implemented Interfaces:
IDBInputParser, IInputParser, IMySQLCreateToken, ISQLCreateToken

public final class MySQLCreateScriptInputParser
extends SQLCreateScriptInput
implements IMySQLCreateToken

This input parser handles the case of a MySQL create sql script as an input. E.g. CREATE TABLE `usergroup` ( `ID` int(11) NOT NULL auto_increment, `NAME` varchar(40) NOT NULL, `GRUPPE_C` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `NAME` (`NAME`) )

Since:
0.9.5
Author:
Andi Hotz

Field Summary
 
Fields inherited from class ch.sahits.codegen.java.input.SQLCreateScriptInput
initialized, state
 
Fields inherited from interface ch.sahits.codegen.java.input.db.IMySQLCreateToken
AUTO_INCREMENT, BTREE, CHECK, CONSTRAINT, FOREIGN, FULLTEXT, HASH, KEY, PRIMARY, REFERENCES, RTREE, SPATIAL, USING
 
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
MySQLCreateScriptInputParser()
           
 
Method Summary
 java.lang.Class convert2JavaType(java.lang.String type)
          Convert the corresponding Java type for a database type
 java.lang.String getDatabaseName()
          Default database name
 java.lang.String getDefaultHost()
          Default Host: localhost
 int getDefaultPort()
          Default port: 3306
 java.lang.String getDefaultUser()
          Default user root
 java.lang.String getFileExtension()
          Only sql create scripts in an sql file can be parsed
 java.lang.String getPassword()
          Default password
 int getRanking()
          This method rates the implementation.
 int getWorkload()
          Defines how complex the generation of the model is.
 boolean hasSchema()
          MySQL has no schema concept
protected  boolean hasTypeSize(java.lang.String type)
          Check if the type has a length definition
 void init(java.lang.Object createFileName)
          Initialize the the parser with a file name to be parsed
 void init(java.lang.String inputFile)
          Initialize the parser with the file
protected  boolean isAutogenKey(java.lang.String fieldName, IDataBaseTable dbt)
          Pseudo implementation since the information of the auto generated key is handled within the parseField(StringTokenizer, String, DataBaseTable) method
protected  boolean isIndexConstraintToken(java.lang.String token)
          Check if the token is a Index constraint token.
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  DataBaseTable parseTable(java.util.StringTokenizer st, java.lang.String className)
          Parse the table
 
Methods inherited from class ch.sahits.codegen.java.input.SQLCreateScriptInput
createIndexName, getLines, needsDataBaseInformationForCompleetion, parse, readFile, unquote
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MySQLCreateScriptInputParser

public MySQLCreateScriptInputParser()
Method Detail

getFileExtension

public java.lang.String getFileExtension()
Only sql create scripts in an sql file can be parsed

Specified by:
getFileExtension in interface IInputParser
Returns:
sql
See Also:
IInputParser.getFileExtension()

getRanking

public int getRanking()
This method rates the implementation. Since this Interface is used for an extension point Implementations with the highest ranking are choosen. Since this is the default implementation the ranking is low

Specified by:
getRanking in interface IInputParser
Returns:
1

getWorkload

public int getWorkload()
Defines how complex the generation of the model is.

Specified by:
getWorkload in interface IInputParser
Returns:
Number of work steps

convert2JavaType

public java.lang.Class convert2JavaType(java.lang.String type)
Convert the corresponding Java type for a database type

Specified by:
convert2JavaType in interface IDBInputParser
Parameters:
type - database type
Returns:
Java type

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)

Overrides:
parseTable in class SQLCreateScriptInput
Parameters:
st - StringTokernizer
dbt - object to store the parsed info into
Returns:
database model

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 [UNIQUE] INDEX [schema.]index_name ON [schema.]table (columns)

Overrides:
parseIndex in class SQLCreateScriptInput
Parameters:
st - StringTokernizer
table - table model the index belongs to
Returns:
database model

hasTypeSize

protected boolean hasTypeSize(java.lang.String type)
Check if the type has a length definition

Specified by:
hasTypeSize in class SQLCreateScriptInput
Parameters:
type - to be checked
Returns:
true if a size is expected

parseTable

protected DataBaseTable parseTable(java.util.StringTokenizer st,
                                   java.lang.String className)
Parse the table

Specified by:
parseTable in class SQLCreateScriptInput
Parameters:
st - StringTokernizer
className - name of the class
Returns:
database model

getDatabaseName

public java.lang.String getDatabaseName()
Default database name

Specified by:
getDatabaseName in interface IDBInputParser
Returns:
''

getDefaultHost

public java.lang.String getDefaultHost()
Default Host: localhost

Specified by:
getDefaultHost in interface IDBInputParser
Returns:
localhost

getDefaultPort

public int getDefaultPort()
Default port: 3306

Specified by:
getDefaultPort in interface IDBInputParser
Returns:
3306

getDefaultUser

public java.lang.String getDefaultUser()
Default user root

Specified by:
getDefaultUser in interface IDBInputParser
Returns:
root

getPassword

public java.lang.String getPassword()
Default password

Specified by:
getPassword in interface IDBInputParser
Returns:
password

hasSchema

public boolean hasSchema()
MySQL has no schema concept

Specified by:
hasSchema in interface IDBInputParser
Returns:
false

init

public void init(java.lang.Object createFileName)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Initialize the the parser with a file name to be parsed

Specified by:
init in interface IDBInputParser
Parameters:
createFileName - name of the file to be parsed
Throws:
java.io.FileNotFoundException - file could not be found
java.io.IOException - File could not be read

init

public void init(java.lang.String inputFile)
Initialize the parser with the file

Specified by:
init in interface IInputParser
Parameters:
inputFile -

isIndexConstraintToken

protected boolean isIndexConstraintToken(java.lang.String token)
Check if the token is a Index constraint token. Valid tokens are UNIQUE

Specified by:
isIndexConstraintToken in class SQLCreateScriptInput
Parameters:
token - to be checked
Returns:
true if the token is an index constraint token

isAutogenKey

protected boolean isAutogenKey(java.lang.String fieldName,
                               IDataBaseTable dbt)
Pseudo implementation since the information of the auto generated key is handled within the parseField(StringTokenizer, String, DataBaseTable) method

Specified by:
isAutogenKey in class SQLCreateScriptInput
Parameters:
fieldName - name of the field that is to be checked
dbt - Database table model for with the autogenerated key is searched
Returns:
false
Since:
1.2.0