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

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

public final class OracleSQLCreateScriptInputParser
extends SQLCreateScriptInput
implements IOracleCreateToken

This input parser handles the case of a Oracle create sql script as an input. E.g. CREATE TABLE user ( NAME varchar2(30) not null, SURNAME varchar2(30) not null, EMAIL varchar2(30) not null ); CREATE UNIQUE INDEX PK_USER ON USER (EMAIL)

Since:
0.9.0
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.IOracleCreateToken
BEFORE, BITMAP, INSERT, TRIGGER
 
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
OracleSQLCreateScriptInputParser()
          Default constructor needed for initialization as an extension.
 
Method Summary
 java.lang.Class convert2JavaType(java.lang.String type)
          Convert the corresponding Java type for a database type.
 java.lang.String getDatabaseName()
          Get the name of the database that is used for initialization of the wizard.
 java.lang.String getDefaultHost()
          Get the default value for the host for a database product that is used for initialization of the wizard e.g.
 int getDefaultPort()
          Get the default port number for a database product that is used for initialization of the wizard e.g. '1521'.
 java.lang.String getDefaultUser()
          Get the default user name for a database product that is used for initialization of the wizard e.g.
 java.lang.String getFileExtension()
          Only sql create scripts in an sql file can be parsed
 java.lang.String getPassword()
          Get the password of the database for the user name specified at IDBInputParser.getDefaultUser() that is used for initialization of the wizard.
 int getRanking()
          This method rates the implementation.
 int getWorkload()
          Defines how complex the generation of the model is.
 boolean hasSchema()
          Indicates if this database works through schemas
protected  boolean hasTypeSize(java.lang.String type)
          Check if the type has any size property.
 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)
          Check if a trigger is defined for the field on insert that referres to a sequence that fills the field true if such a trigger exists.
protected  boolean isIndexConstraintToken(java.lang.String token)
          Check if the token is a Index constraint token.
protected  DataBaseTable parseTable(java.util.StringTokenizer st, java.lang.String className)
          Parse the script for the table definition.
 
Methods inherited from class ch.sahits.codegen.java.input.SQLCreateScriptInput
createIndexName, getLines, needsDataBaseInformationForCompleetion, parse, parseIndex, parseTable, readFile, unquote
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OracleSQLCreateScriptInputParser

public OracleSQLCreateScriptInputParser()
Default constructor needed for initialization as an extension. After creating the parser it must be initialized with init(Object)

Method Detail

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 -

convert2JavaType

public java.lang.Class convert2JavaType(java.lang.String type)
Convert the corresponding Java type for a database type. The following mapping takes place.
Oracle DatatypeJava Object
VARCHAR2String
NVARCHAR2String
VARCHARString
CHARString
NCHARString
NUMBER(size)long
NUMBER(p,s)double
LONGString
DATEjava.sql.Date
TIMESTAMPlong
ROWIDjava.math.BigInteger
UROWIDjava.math.BigInteger
CLOBString
NCLOBString
The following types are not mapped:

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

parseTable

protected 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)

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

hasTypeSize

protected boolean hasTypeSize(java.lang.String type)
Check if the type has any size property. The following data-types are not mapped:

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

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()

getDatabaseName

public java.lang.String getDatabaseName()
Description copied from interface: IDBInputParser
Get the name of the database that is used for initialization of the wizard. The name may not be specified in which case an empty string is returned. The name must not be null.
Normally this should be an empty string since you want to generate a parser that works out of the box for all systems.

Specified by:
getDatabaseName in interface IDBInputParser
Returns:
empty String
See Also:
IDBInputParser.getDatabaseName()

getDefaultHost

public java.lang.String getDefaultHost()
Description copied from interface: IDBInputParser
Get the default value for the host for a database product that is used for initialization of the wizard e.g. 'localhost' The default host may not be specified in which case an empty string is returned. The default host must not be null.

Specified by:
getDefaultHost in interface IDBInputParser
Returns:
"localhost"
See Also:
IDBInputParser.getDefaultHost()

getDefaultPort

public int getDefaultPort()
Description copied from interface: IDBInputParser
Get the default port number for a database product that is used for initialization of the wizard e.g. '1521'. The default port may be 0 which means not specified but it must not be negative.

Specified by:
getDefaultPort in interface IDBInputParser
Returns:
1521
See Also:
IDBInputParser.getDefaultPort()

getDefaultUser

public java.lang.String getDefaultUser()
Description copied from interface: IDBInputParser
Get the default user name for a database product that is used for initialization of the wizard e.g. 'root'. The default user name may not be specified in which case an empty string is returned. The default user name must not be null.

Specified by:
getDefaultUser in interface IDBInputParser
Returns:
"sys"
See Also:
IDBInputParser.getDefaultUser()

getPassword

public java.lang.String getPassword()
Description copied from interface: IDBInputParser
Get the password of the database for the user name specified at IDBInputParser.getDefaultUser() that is used for initialization of the wizard. The password may not be specified in which case an empty string is returned. The password must not be null.
Normally this should be an empty string since you want to generate a parser that works out of the box for all systems.

Specified by:
getPassword in interface IDBInputParser
Returns:
empty String
See Also:
IDBInputParser.getPassword()

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

hasSchema

public boolean hasSchema()
Indicates if this database works through schemas

Specified by:
hasSchema in interface IDBInputParser
Returns:
true since Oracle embraces the schema concept

isIndexConstraintToken

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

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)
Check if a trigger is defined for the field on insert that referres to a sequence that fills the field true if such a trigger exists.

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:
true if the field is an autogenerated key