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

java.lang.Object
  extended by ch.sahits.codegen.java.input.db.DBConnection
      extended by ch.sahits.codegen.java.input.db.SQLServerConnection
          extended by ch.sahits.codegen.java.input.db.SQLServerConnectionModelGenerator
All Implemented Interfaces:
IDBConnectionModelGenerator, IBasicDBConnectionModelGenerator, IGeneralDBConnectionModelGenerator

public final class SQLServerConnectionModelGenerator
extends SQLServerConnection
implements IDBConnectionModelGenerator, IGeneralDBConnectionModelGenerator

This class can generate a model from a connection to a SQL Server database.

Since:
0.9.5
Author:
Andi Hotz

Field Summary
 
Fields inherited from class ch.sahits.codegen.java.input.db.DBConnection
conn, db, host, password, port, product, schema, table, user
 
Constructor Summary
SQLServerConnectionModelGenerator()
           
 
Method Summary
 DataBaseTable generateModel()
          Generate the database model
 java.lang.String getDefaultHost()
          Default Host: localhost
 java.lang.String getDefaultPort()
          Default Port 1433
 java.lang.String getDefaultUserName()
          Default user: sa (may be disabled by default e.g.
 int getRating()
          This method rates the implementation.
 int getWorkload()
          Defines how complex the generation of the model is.
 boolean hasSchema()
          SQL Server uses schema
 void init(java.lang.String hostname, java.lang.String uname, java.lang.String pwd, java.lang.String database, java.lang.String tablename, int port, java.lang.String schema)
          Initialize the generator by calling init(String, String, String, String, String, String, String, int, String) and passing an empty class and package name
 void init(java.lang.String hostname, java.lang.String uname, java.lang.String pwd, java.lang.String database, java.lang.String tablename, java.lang.String packageName, java.lang.String className, int _port, java.lang.String _schema)
          Initializes the connection data
 void setDatabase(java.lang.String dbName)
          Set the name of the database
 java.lang.String testConnection()
          Test the connection to the database.
 
Methods inherited from class ch.sahits.codegen.java.input.db.SQLServerConnection
convert2Java, createDataBaseTable, getConnectionDriverClass, getConnectionString, getConstraintFieldSQL, getIndexConstraintSQL, getTableSQL, loadDriver
 
Methods inherited from class ch.sahits.codegen.java.input.db.DBConnection
addFields2Index, getConstraintsFields, getPort, getSchema, getStructure, init, isAutGenKey, setHost, setPassword, setPort, setProduct, setSchema, setTableName, setUserName
 
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.model.IBasicDBConnectionModelGenerator
getConnectionDriverClass, getConnectionString, setHost, setPassword, setPort, setTableName, setUserName
 

Constructor Detail

SQLServerConnectionModelGenerator

public SQLServerConnectionModelGenerator()
Method Detail

generateModel

public DataBaseTable generateModel()
Generate the database model

Specified by:
generateModel in interface IBasicDBConnectionModelGenerator
Returns:
Database table model

getDefaultHost

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

Specified by:
getDefaultHost in interface IBasicDBConnectionModelGenerator
Returns:
localhost

getDefaultPort

public java.lang.String getDefaultPort()
Default Port 1433

Specified by:
getDefaultPort in interface IBasicDBConnectionModelGenerator
Returns:
1433

getDefaultUserName

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

Specified by:
getDefaultUserName in interface IBasicDBConnectionModelGenerator
Returns:
sa

getRating

public int getRating()
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:
getRating in interface IBasicDBConnectionModelGenerator
Returns:
1

getWorkload

public int getWorkload()
Defines how complex the generation of the model is.
For the retrieving of the table structure two tables must be querried. The third part of the costs are taken up by putting the pieces together

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

hasSchema

public boolean hasSchema()
SQL Server uses schema

Specified by:
hasSchema in interface IBasicDBConnectionModelGenerator
Returns:
true

init

public void init(java.lang.String hostname,
                 java.lang.String uname,
                 java.lang.String pwd,
                 java.lang.String database,
                 java.lang.String tablename,
                 java.lang.String packageName,
                 java.lang.String className,
                 int _port,
                 java.lang.String _schema)
          throws java.sql.SQLException
Initializes the connection data

Specified by:
init in interface IDBConnectionModelGenerator
Parameters:
hostname - of the db eg. localhost
uname - user name to connect to the DB
pwd - password of the user
database - or schema of the table
tablename - table name
packageName - name of the package
className - name of the class
_port - number
_schema - name
Throws:
java.sql.SQLException - Connecting failed probably due to incorrect input

setDatabase

public void setDatabase(java.lang.String dbName)
Set the name of the database

Specified by:
setDatabase in interface IBasicDBConnectionModelGenerator
Parameters:
dbName - database name

testConnection

public java.lang.String testConnection()
Test the connection to the database.

Specified by:
testConnection in interface IBasicDBConnectionModelGenerator
Returns:
Error message if the test failed or null

init

public void init(java.lang.String hostname,
                 java.lang.String uname,
                 java.lang.String pwd,
                 java.lang.String database,
                 java.lang.String tablename,
                 int port,
                 java.lang.String schema)
          throws java.sql.SQLException
Initialize the generator by calling init(String, String, String, String, String, String, String, int, String) and passing an empty class and package name

Specified by:
init in interface IGeneralDBConnectionModelGenerator
Parameters:
hostname - of the db eg. localhost
uname - user name to connect to the DB
pwd - password of the user
database - or schema of the table
tablename - table name
schema - Schema name
port - number
Throws:
java.sql.SQLException - Connecting failed probably due to incorrect input