velosurf.sql
Class ReverseEngineer

java.lang.Object
  extended by velosurf.sql.ReverseEngineer

public class ReverseEngineer
extends java.lang.Object

Class used to reverse engine a database.


Field Summary
private  Database db
          Database.
static int DEFAULT_REVERSE_MODE
          Default reverse engineering mode.
private  DriverInfo driverInfo
          Driver infos.
private  java.util.Map<java.lang.String,java.lang.String> entityByTableName
          map table->entity, valid only between readConfigFile and readMetaData.
static int REVERSE_FULL
          Full reverse engineering mode.
static int REVERSE_NONE
          No reverse engineering mode.
static int REVERSE_PARTIAL
          Partial reverse engineering mode.
static int REVERSE_TABLES
          Tables reverse engineering mode.
private  int reverseMode
          Reverse mode.
static java.lang.String[] reverseModeName
          Reverse engineering mode names.
 
Constructor Summary
ReverseEngineer(Database database)
          constructor.
 
Method Summary
private  java.lang.String adaptCase(java.lang.String name)
          adapt case
private  void addExportedKey(Entity entity, java.lang.String fkSchema, java.lang.String fkTable, java.util.List<java.lang.String> fkCols, java.util.List<java.lang.String> pkCols)
          Add a new exported key.
private  void addImportedKey(Entity entity, java.lang.String pkSchema, java.lang.String pkTable, java.util.List<java.lang.String> pkCols, java.util.List<java.lang.String> fkCols)
          Add a new imported key.
protected  void addTableMatching(java.lang.String tableName, Entity entity)
          add a table <-> entity matching.
private  java.lang.String getEntityByTable(java.lang.String schema, java.lang.String table)
          Get an entity by its table name.
private  java.lang.String getExportedKeyName(java.lang.String name)
          rough plural calculation.
private  void readForeignKeys(java.sql.DatabaseMetaData meta, Entity entity, java.lang.String tableName)
          Read foreign keys.
protected  void readMetaData()
          read the meta data from the database.
private  void readTableMetaData(java.sql.DatabaseMetaData meta, Entity entity, java.lang.String tableName)
          Read table meta data.
protected  void setDriverInfo(DriverInfo di)
          Driver infos setter.
protected  void setReverseMode(int reverseMethod)
          Set reverse mode.
private  java.util.List<java.lang.String> sortColumns(java.util.List<java.lang.String> ordered, java.util.List<java.lang.String> unordered, java.util.List<java.lang.String> target)
          Sort columns in target the same way unordered would have to be sorted to be like ordered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityByTableName

private java.util.Map<java.lang.String,java.lang.String> entityByTableName
map table->entity, valid only between readConfigFile and readMetaData.


db

private Database db
Database.


driverInfo

private DriverInfo driverInfo
Driver infos.


reverseMode

private int reverseMode
Reverse mode.


REVERSE_NONE

public static final int REVERSE_NONE
No reverse engineering mode.

See Also:
Constant Field Values

REVERSE_PARTIAL

public static final int REVERSE_PARTIAL
Partial reverse engineering mode.

See Also:
Constant Field Values

REVERSE_TABLES

public static final int REVERSE_TABLES
Tables reverse engineering mode.

See Also:
Constant Field Values

REVERSE_FULL

public static final int REVERSE_FULL
Full reverse engineering mode.

See Also:
Constant Field Values

DEFAULT_REVERSE_MODE

public static final int DEFAULT_REVERSE_MODE
Default reverse engineering mode.

See Also:
Constant Field Values

reverseModeName

public static java.lang.String[] reverseModeName
Reverse engineering mode names.

Constructor Detail

ReverseEngineer

public ReverseEngineer(Database database)
constructor.

Parameters:
database - database
Method Detail

setDriverInfo

protected void setDriverInfo(DriverInfo di)
Driver infos setter.

Parameters:
di - driver infos

setReverseMode

protected void setReverseMode(int reverseMethod)
Set reverse mode.

Parameters:
reverseMethod - reverse mode

addTableMatching

protected void addTableMatching(java.lang.String tableName,
                                Entity entity)
add a table <-> entity matching.

Parameters:
tableName -
entity -

readMetaData

protected void readMetaData()
                     throws java.sql.SQLException
read the meta data from the database.

Throws:
java.sql.SQLException - thrown by the database engine

readTableMetaData

private void readTableMetaData(java.sql.DatabaseMetaData meta,
                               Entity entity,
                               java.lang.String tableName)
                        throws java.sql.SQLException
Read table meta data.

Parameters:
meta - database meta data
entity - corresponding entity
tableName - table name
Throws:
java.sql.SQLException

readForeignKeys

private void readForeignKeys(java.sql.DatabaseMetaData meta,
                             Entity entity,
                             java.lang.String tableName)
                      throws java.sql.SQLException
Read foreign keys.

Parameters:
meta - database meta data
entity - entity
tableName - table name
Throws:
java.sql.SQLException

addExportedKey

private void addExportedKey(Entity entity,
                            java.lang.String fkSchema,
                            java.lang.String fkTable,
                            java.util.List<java.lang.String> fkCols,
                            java.util.List<java.lang.String> pkCols)
Add a new exported key.

Parameters:
entity - target entity
fkSchema - foreign key schema
fkTable - foreign key table
fkCols - foreign key columns
pkCols - primary key columns

addImportedKey

private void addImportedKey(Entity entity,
                            java.lang.String pkSchema,
                            java.lang.String pkTable,
                            java.util.List<java.lang.String> pkCols,
                            java.util.List<java.lang.String> fkCols)
Add a new imported key.

Parameters:
entity - target entity
pkSchema - primary key schema
pkTable - primary key table
pkCols - primary key columns
fkCols - foreign key columns

getEntityByTable

private java.lang.String getEntityByTable(java.lang.String schema,
                                          java.lang.String table)
Get an entity by its table name.

Parameters:
schema - schema name
table - table name
Returns:
entity name

sortColumns

private java.util.List<java.lang.String> sortColumns(java.util.List<java.lang.String> ordered,
                                                     java.util.List<java.lang.String> unordered,
                                                     java.util.List<java.lang.String> target)
Sort columns in target the same way unordered would have to be sorted to be like ordered.

Parameters:
ordered - ordered list reference
unordered - unordered list reference
target - target list
Returns:
sorted target list

adaptCase

private java.lang.String adaptCase(java.lang.String name)
adapt case

Parameters:
name - name to adapt
Returns:
adapted name

getExportedKeyName

private java.lang.String getExportedKeyName(java.lang.String name)
rough plural calculation.

Parameters:
name - singular
Returns:
plural


~ooOoo~