|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fesenmeyer.dbnormalizer.core.algorithms.NormalizationScriptBuilder
public class NormalizationScriptBuilder
This class creates a SQL script which can be used to apply
the normalization proposed by a NormalizationProposal
object
to a DB.
NOTE: The current implementation has some limitations:
FDAlgorithms.setKeysForTable(Table, Table)
.
Hence, in some cases, no foreign keys will be defined at all.Because of this limitations, first check the generated SQL script before applying it to the DB.
Field Summary | |
---|---|
private NormalizationProposal |
normProposal
The normalization proposal for which the sql script should be generated. |
Constructor Summary | |
---|---|
NormalizationScriptBuilder(NormalizationProposal normProposal)
Class constructor specifying the normalization proposal for which the sql script should be generated. |
Method Summary | |
---|---|
private StringBuffer |
buildAddFKConstraint(FK fk)
Builds a SQL statement which creates the foreign key (FK) constraint specified by the fk argument |
private StringBuffer |
buildAddFKConstraints(Collection<FK> fks)
Builds SQL statements which create the foreign key (FK) constraints specified by the fks argument |
private StringBuffer |
buildCreateTableScript(Table table)
Builds a SQL statement to create the table (without foreign keys) given by the table argument |
private StringBuffer |
buildCreateTablesScript(Collection<Table> createdTables)
Builds SQL statements to create the tables (without foreign keys) given by the createdTables argument. |
private StringBuffer |
buildCreateView(Collection<Table> createdTables,
Table oldTable)
Builds a CREATE VIEW statement for creating a view
which constructs the old table's data from the new (created) tables. |
private StringBuffer |
buildDataMigrationScript(Collection<Table> createdTables,
Table oldTable)
Builds a data migration script which copies the data from the old table to the new tables. |
private StringBuffer |
buildDataMigrationScript(Table createdTable,
Table oldTable)
Builds a data migration script which copies the appropriate data from the old table to one of the new (created) tables. |
private StringBuffer |
buildDropOldTableScript(Table oldTable)
Builds a statement which drops the old table with the CASCADE CONSTRAINTS option. |
private StringBuffer |
buildPrimaryKeyDef(PK pk)
Builds a primary key (PK) definition for the PK specified by argument pk |
private StringBuffer |
buildTableColumnDef(Table table,
TableColumn col)
Builds a table column definition for the column given by argument col |
private StringBuffer |
buildUniqueConstraintDef(Collection<String> attributes)
Builds a unique constraint definition for the specified attributes |
String |
createScript()
Creates a SQL script based on the normalization proposal. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private NormalizationProposal normProposal
Constructor Detail |
---|
public NormalizationScriptBuilder(NormalizationProposal normProposal)
normProposal
- a normalization proposalMethod Detail |
---|
public String createScript()
NormalizationScriptBuilder
private StringBuffer buildCreateTablesScript(Collection<Table> createdTables)
createdTables
- the tables for which CREATE TABLE-statements should
be build
private StringBuffer buildCreateTableScript(Table table)
table
- the table for which a CREATE TABLE-statement should
be build
private StringBuffer buildPrimaryKeyDef(PK pk)
pk
- a PK
private StringBuffer buildUniqueConstraintDef(Collection<String> attributes)
attributes
- a collection containing the attribute names
private StringBuffer buildTableColumnDef(Table table, TableColumn col)
table
- the table which contains the columncol
- the column
private StringBuffer buildDataMigrationScript(Collection<Table> createdTables, Table oldTable)
createdTables
- the created (new) tablesoldTable
- the old table
private StringBuffer buildDataMigrationScript(Table createdTable, Table oldTable)
createdTable
- one of the new (created) tablesoldTable
- the old table
private StringBuffer buildDropOldTableScript(Table oldTable)
CASCADE CONSTRAINTS
option.
oldTable
- the old table
DROP TABLE
-statementprivate StringBuffer buildAddFKConstraints(Collection<FK> fks)
fks
- the FKs to be defined
private StringBuffer buildAddFKConstraint(FK fk)
fk
- the FK to be defined
private StringBuffer buildCreateView(Collection<Table> createdTables, Table oldTable)
CREATE VIEW
statement for creating a view
which constructs the old table's data from the new (created) tables.
For this purpose, the NATURAL JOIN
operator has been used.
createdTables
- the new (created) tablesoldTable
- the old table
CREATE VIEW
statement
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |