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

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

public final class MySQLConnectionModelGenerator
extends MySQLConnection
implements IDBConnectionModelGenerator, IGeneralDBConnectionModelGenerator

This class can generate a model from a connection to a MySQL database.

Since:
0.9.2
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
MySQLConnectionModelGenerator()
          Default constructor
 
Method Summary
 DataBaseTable generateModel()
          Generate the database model
 java.lang.String getDefaultHost()
          Retrieve the default name of the database host
 java.lang.String getDefaultPort()
          Retrieve the default port number of the data base
 java.lang.String getDefaultUserName()
          Retrieve the default user name for the data base
 int getRating()
          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
 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.MySQLConnection
convert2Java, convert2JavaType, 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

MySQLConnectionModelGenerator

public MySQLConnectionModelGenerator()
Default constructor

Method Detail

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

generateModel

public DataBaseTable generateModel()
Generate the database model

Specified by:
generateModel in interface IBasicDBConnectionModelGenerator
Returns:
Database Table

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

getDefaultHost

public java.lang.String getDefaultHost()
Retrieve the default name of the database host

Specified by:
getDefaultHost in interface IBasicDBConnectionModelGenerator
Returns:
host name 'localhost'

getDefaultPort

public java.lang.String getDefaultPort()
Retrieve the default port number of the data base

Specified by:
getDefaultPort in interface IBasicDBConnectionModelGenerator
Returns:
port number '3306'

getDefaultUserName

public java.lang.String getDefaultUserName()
Retrieve the default user name for the data base

Specified by:
getDefaultUserName in interface IBasicDBConnectionModelGenerator
Returns:
user name 'root'

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()
Indicates if this database works through schemas

Specified by:
hasSchema in interface IBasicDBConnectionModelGenerator
Returns:
Until Version 5.1, MySQL doesn't work through schemas

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