public class DDLGeneratorWorker.Helper
extends java.lang.Object
add***()
methods. When the entire schema
information is collected, the result can be obtained using generate***()
methods.Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,UastHints> |
hints
Schema hints by schema name
|
private static int |
MAX_OBJECT_NAME_LEN
Max length of the database object name (most restrictive limit as for PostgreSQL)
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,DDLGeneratorWorker.Sequence>> |
sequences
The set of all sequences mapped by their schema.
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,DDLGeneratorWorker.Table>> |
tables
The set of all tables mapped by their schema.
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,WordTable>> |
wordTables
Word tables by name
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> |
wordTablesKeys
Word tables' keys DDLs by schema and word table name
|
private java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
wordTablesNames
The set of all objects' names generated for word tables by mapped by their schema.
|
Constructor and Description |
---|
Helper() |
Modifier and Type | Method and Description |
---|---|
void |
addField(java.lang.String dbName,
java.lang.String tableName,
java.lang.String legacy,
java.lang.String name,
java.lang.String type,
int extent,
int extentIndex,
boolean cs,
boolean notNull,
int scale)
Adds a new field to an existing table (added previously with
addTable() ). |
private void |
addFieldImpl(P2JField field,
Dialect dialect,
DDLGeneratorWorker.Table table,
java.lang.StringBuilder sb,
java.lang.String eoln)
Appends a field to a table DDL statement.
|
void |
addIndex(java.lang.String dbName,
java.lang.String tableName,
java.lang.String legacy,
java.lang.String name,
boolean primary,
boolean unique,
boolean word)
Adds a new index to an existing table (added previously with
addTable() ). |
P2JIndexComponent |
addIndexComponent(java.lang.String dbName,
java.lang.String tableName,
java.lang.String indexName,
java.lang.String property,
java.lang.String name,
java.lang.String legacy,
boolean isChar,
boolean isCS,
boolean isDesc)
Adds a new field to an existing table (added previously with
addTable() ). |
private void |
addLastFieldImpl(P2JField field,
Dialect dialect,
DDLGeneratorWorker.Table table,
java.lang.StringBuilder sb,
java.lang.String eoln)
Appends a last field to a table DDL statement.
|
void |
addSchema(java.lang.String dbName)
Adds a new schema.
|
void |
addSequence(java.lang.String dbName,
java.lang.String name,
java.lang.String legacy,
java.lang.Long init,
java.lang.Long increment,
java.lang.Long minVal,
java.lang.Long maxVal,
java.lang.Boolean cycle)
Records a new sequence.
|
void |
addTable(java.lang.String dbName,
java.lang.String tableName,
java.lang.String legacy)
Adds a new table to an existing schema (added previously with
addSchema() ). |
private void |
copySqlFile(java.io.File src,
java.lang.String destName)
Copies a generated SQL file to
$(output-root)/$(pkgroot)/dmo/_meta . |
void |
copyUDFs(java.lang.String dbName)
Copy UDFs script to the standard place
|
private java.lang.String |
createDbObjectName(java.lang.String dbName,
java.lang.String... parts)
Construct database object name concatenating parts
|
private void |
forAllDialects(java.lang.String dbName,
java.util.function.Consumer<Dialect> worker)
Do a job for all dialects
|
private void |
generateIndexDDLImpl(java.lang.String dbName,
Dialect dialect,
java.io.PrintStream out,
java.lang.String eoln)
Worker method for
generateIndexDDLs . |
void |
generateIndexDDLs(java.lang.String dbName)
Generates the DDLs needed to create all indexes for the tables in a database with a
specific schema.
|
private void |
generateSequenceDDLImpl(java.lang.String schema,
Dialect dialect,
java.io.PrintStream out,
java.lang.String eoln)
Worker method for
generateSequencesDDLs() . |
void |
generateSequenceDDLs(java.lang.String dbName)
Generates the DDLs needed to create all sequences in a database with a specific schema.
|
private void |
generateTableDDLImpl(java.lang.String dbName,
Dialect dialect,
java.io.PrintStream out,
java.lang.String eoln)
Worker method for
generateTableDDLs() . |
void |
generateTableDDLs(java.lang.String dbName)
Generates the DDLs needed to create all tables in a database with a specific schema.
|
private void |
generateWordTable(java.lang.String dbName,
DDLGeneratorWorker.Table table,
java.io.PrintStream out,
Dialect dialect,
java.lang.String eoln)
Generate auxiliary word table
|
void |
generateWordTablesDDLs(java.lang.String dbName)
Generate triggers' DDL to support word tables.
|
private java.io.File |
getDDLFolder()
Checks is the
ddl folder exists and returns it after making sure it exists. |
private java.lang.String |
getEndOfLine()
Get the EOLN sequence specific to target OS.
|
private UastHints |
getHints()
Get UastHints for a current source.
|
java.lang.String |
getWordTableName(java.lang.String dbName,
java.lang.String tableName,
java.lang.String indexName)
Get the name of the word table for the word index
|
private boolean |
isIndexComponent(P2JField field,
DDLGeneratorWorker.Table table)
Checks whether a field is part of an index.
|
private void |
preprocessIndices(java.lang.String dbName)
Preprocesses the indexes, dropping the UNIQUE option for those that are implicitly unique due to
a previous index having the same components has already been validated as unique.
|
private static final int MAX_OBJECT_NAME_LEN
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,DDLGeneratorWorker.Table>> tables
private final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> wordTablesNames
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,WordTable>> wordTables
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> wordTablesKeys
private final java.util.Map<java.lang.String,UastHints> hints
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,DDLGeneratorWorker.Sequence>> sequences
public void addSchema(java.lang.String dbName)
dbName
- The name of the schema. TODO: clarify: legacy/sqlpublic void addTable(java.lang.String dbName, java.lang.String tableName, java.lang.String legacy)
addSchema()
). In
case of validation error the method logs the event and returns without adding the table.dbName
- The target schema.tableName
- The SQL table name.legacy
- The legacy name.public void addField(java.lang.String dbName, java.lang.String tableName, java.lang.String legacy, java.lang.String name, java.lang.String type, int extent, int extentIndex, boolean cs, boolean notNull, int scale)
addTable()
). In
case of validation error the method logs the event and returns without adding the field.dbName
- The target schema.tableName
- The target (legacy) table name .legacy
- The legacy field name of the new field to be added.name
- The SQL name of the new field.type
- The type of the field.extent
- The extent of the field. If field is not an EXTENT, use 0.extentIndex
- In case of denormalized tables, this is the index of the extent field.cs
- Case sensitivity. Only taken into account when the current field is a character@
.notNull
- Flag for mandatory
fields.scale
- The scale. Only used when the declared field is decimal
.public java.lang.String getWordTableName(java.lang.String dbName, java.lang.String tableName, java.lang.String indexName)
dbName
- The target schema.tableName
- The target (legacy) table name .indexName
- The legacy name of the index.public void addIndex(java.lang.String dbName, java.lang.String tableName, java.lang.String legacy, java.lang.String name, boolean primary, boolean unique, boolean word)
addTable()
). In
case of validation error the method logs the event and returns without adding the index.dbName
- The target schema.tableName
- The target (legacy) table name .legacy
- The legacy field name of the new index to be added.name
- The SQL name of the new index.primary
- Flag for PRIMARY indexes.unique
- Flag for UNIQUE indexes.word
- Flag for WORD indexes (not used ATM).public P2JIndexComponent addIndexComponent(java.lang.String dbName, java.lang.String tableName, java.lang.String indexName, java.lang.String property, java.lang.String name, java.lang.String legacy, boolean isChar, boolean isCS, boolean isDesc)
addTable()
). In
case of validation error the method logs the event and returns without adding the table.dbName
- The target schema.tableName
- The target (legacy) table name .indexName
- The target (legacy) index name.property
- The property name of the field to be added as an index component.name
- The SQL column name of the field to be added as an index component.legacy
- The legacy field name of the field to be added as an index component.isChar
- Flag for character
fields.isCS
- The case-sensitivity of the field. Only if isChar
is true
.isDesc
- The direction of sorting. If true
the direction is descending.public void addSequence(java.lang.String dbName, java.lang.String name, java.lang.String legacy, java.lang.Long init, java.lang.Long increment, java.lang.Long minVal, java.lang.Long maxVal, java.lang.Boolean cycle)
dbName
- The schema where the sequence belongs to.name
- The SQL name for the new sequence.legacy
- The legacy name of the sequence.init
- The initial value of the sequence.increment
- The increment step of the sequence.minVal
- The minimum value of the sequence.maxVal
- The minimum value of the sequence.cycle
- true
when this is a cycling sequence.public void generateTableDDLs(java.lang.String dbName)
The method scans all dialects declared in p2j.cfg.xml
and generates a DDL script
for each one. The output is generated as ddl/schema_table_<schema>_<dialect>.sql
.
dbName
- The name of the schema to be processed.public void generateWordTablesDDLs(java.lang.String dbName)
dbName
- The name of the schema to be processed.public void generateSequenceDDLs(java.lang.String dbName)
ddl/schema_table_<schema>_<dialect>.sql
).dbName
- The name of the schema to be processed.public void generateIndexDDLs(java.lang.String dbName)
The method scans all dialects declared in p2j.cfg.xml
and generates a DDL script
for each one. The output is generated as ddl/schema_index_<schema>_<dialect>.sql
.
dbName
- The name of the schema to be processed.public void copyUDFs(java.lang.String dbName)
dbName
- database nameprivate java.io.File getDDLFolder()
ddl
folder exists and returns it after making sure it exists.private java.lang.String getEndOfLine()
private UastHints getHints()
private void forAllDialects(java.lang.String dbName, java.util.function.Consumer<Dialect> worker)
dbName
- database nameworker
- job workerprivate void preprocessIndices(java.lang.String dbName)
dbName
- The name of the schema to be processed.private void copySqlFile(java.io.File src, java.lang.String destName) throws java.io.IOException
$(output-root)/$(pkgroot)/dmo/_meta
.src
- The source file.destName
- The destination file name.java.io.IOException
- When a problem wa detected during copy operation.private void generateIndexDDLImpl(java.lang.String dbName, Dialect dialect, java.io.PrintStream out, java.lang.String eoln)
generateIndexDDLs
. It generates the DDLs needed to create all
indexes for the tables in a database with a specific schema and using a certain dialect.dbName
- The target schema.dialect
- The Dialect
to be used.out
- The PrintStream
used for output.eoln
- OS-specific end of line terminator.private void generateSequenceDDLImpl(java.lang.String schema, Dialect dialect, java.io.PrintStream out, java.lang.String eoln)
generateSequencesDDLs()
. It generates the DDLs needed to create
the sequences in a database with a specific schema and using a certain dialect.schema
- The target schema.dialect
- The Dialect
to be used.out
- The PrintStream
used for output.eoln
- OS-specific end of line terminator.private void generateTableDDLImpl(java.lang.String dbName, Dialect dialect, java.io.PrintStream out, java.lang.String eoln)
generateTableDDLs()
. It generates the DDLs needed to create all
tables in a database with a specific schema and using a certain dialect.dbName
- The target schema.dialect
- The Dialect
to be used.out
- The PrintStream
used for output.eoln
- OS-specific end of line terminator.private void generateWordTable(java.lang.String dbName, DDLGeneratorWorker.Table table, java.io.PrintStream out, Dialect dialect, java.lang.String eoln)
dbName
- The target schema.table
- The parent table.out
- The PrintStream
used for output.dialect
- The Dialect
to be used.eoln
- OS-specific end of line terminator.private void addFieldImpl(P2JField field, Dialect dialect, DDLGeneratorWorker.Table table, java.lang.StringBuilder sb, java.lang.String eoln)
datetime-tz
and case-insensitive character
fields), multiple
column are added.field
- The field to be added.dialect
- The dialect to be used.table
- The field's parent table.sb
- The string builder used for concatenate string data.eoln
- OS-dependent end of line terminator.private void addLastFieldImpl(P2JField field, Dialect dialect, DDLGeneratorWorker.Table table, java.lang.StringBuilder sb, java.lang.String eoln)
datetime-tz
and case-insensitive character
fields), multiple
column are added.field
- The field to be added.dialect
- The dialect to be used.table
- The field's parent table.sb
- The string builder used for concatenate string data.eoln
- OS-dependent end of line terminator.private boolean isIndexComponent(P2JField field, DDLGeneratorWorker.Table table)
character
case-insensitive fields
index components need special handling.field
- The field name to be checked.table
- The parent table of the field.true
only if the field is an index component.private java.lang.String createDbObjectName(java.lang.String dbName, java.lang.String... parts)
dbName
- The target schema.parts
- The parts of the name.