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

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

public final class SQLServerCreateScriptInputParser
extends SQLCreateScriptInput
implements ISQLServerCreateToken

Creating a DataBaseTable object model from a SQL Server create script

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.ISQLServerCreateToken
CHECK, CLUSTERED, CONSTRAINT, FOREIGN, IDENTITY, KEY, NONCLUSTERED, PRIMARY
 
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
SQLServerCreateScriptInputParser()
           
 
Method Summary
 java.lang.Class<?> convert2JavaType(java.lang.String type)
          Convert the corresponding Java type for a database type
 java.lang.String getDatabaseName()
          Database name
 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()
          default port: 1433
 java.lang.String getDefaultUser()
          Default user: sa (may be disabled by default e.g.
 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()
          SQL Server uses schemas
protected  boolean hasTypeSize(java.lang.String type)
          Check if the type has a length definition
 void init(java.lang.Object obj)
          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 auto generated key is set in the method parseField(StringTokenizer, String, DataBaseTable)
protected  boolean isIndexConstraintToken(java.lang.String token)
          Index constraint token
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 script for the table definition.
 
Methods inherited from class ch.sahits.codegen.java.input.SQLCreateScriptInput
createIndexName, getLines, needsDataBaseInformationForCompleetion, parse, parseIndex, readFile, unquote
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLServerCreateScriptInputParser

public SQLServerCreateScriptInputParser()
Method Detail

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

isIndexConstraintToken

protected boolean isIndexConstraintToken(java.lang.String token)
Index constraint token

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

parseTable

protected DataBaseTable parseTable(java.util.StringTokenizer st,
                                   java.lang.String className)
Description copied from class: SQLCreateScriptInput
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

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 field type
Returns:
Java representation of the field type

getDatabaseName

public java.lang.String getDatabaseName()
Database name

Specified by:
getDatabaseName in interface IDBInputParser
Returns:
''

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

getDefaultPort

public int getDefaultPort()
default port: 1433

Specified by:
getDefaultPort in interface IDBInputParser
Returns:
1433

getDefaultUser

public java.lang.String getDefaultUser()
Default user: sa (may be disabled by default e.g. SQLExpress 2005 onwards)

Specified by:
getDefaultUser in interface IDBInputParser
Returns:
sa

getPassword

public java.lang.String getPassword()
Default password

Specified by:
getPassword in interface IDBInputParser
Returns:
''

hasSchema

public boolean hasSchema()
SQL Server uses schemas

Specified by:
hasSchema in interface IDBInputParser
Returns:
true

init

public void init(java.lang.Object obj)
          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:
obj - name of the file to be parsed
Throws:
java.io.FileNotFoundException - file could not be found
java.io.IOException - File could not be read

getFileExtension

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

Specified by:
getFileExtension in interface IInputParser
Returns:
file extension
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

init

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

Specified by:
init in interface IInputParser
Parameters:
inputFile -

parseTable

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

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

isAutogenKey

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

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