public class CreateMySqlDdlFromSchemaDef extends MySqlPart
Generates MySQL DDL from SchemaDef
DROP TABLE IF EXISTS table_name;
CREATE TABLE IF NOT EXISTS table_name (
user_id bigint,
email text,
PRIMARY KEY (user_id)
);
CREATE INDEX idx_email ON table_name (email);
ALTER TABLE foreign_table_name
ADD CONSTRAINT fk_constraint_name FOREIGN KEY(fk_field_name)
REFERENCES primary_table_name (pk_field_name)
ON DELETE CASCADE
ON UPDATE RESTRICT;
Constructor and Description |
---|
CreateMySqlDdlFromSchemaDef(SchemaDef schemaDef) |
Modifier and Type | Method and Description |
---|---|
void |
collectSqlFragment(CodeWriter writer)
Generates DDL from
schemaDef and writes the output to writer . |
Integer |
getDefaultBigDecimalPrecision()
Returns the default precision of
FieldType.BIG_DECIMAL (default 20). |
Integer |
getDefaultBigDecimalScale()
Sets the default scale of
FieldType.BIG_DECIMAL (default 5). |
Integer |
getDefaultBigIntegerPrecision()
Returns the default precision of
FieldType.BIG_INTEGER (default 20). |
List<String> |
getEntityNames()
Returns entity names that are specified by
setEntityNames(java.util.List<java.lang.String>) to be included in the output DDL. |
SchemaDef |
getSchemaDef()
Returns provided
schemaDef . |
boolean |
isCheckIfDropTableExists()
Indicates if
IF EXISTS clause should be included in the DROP TABLE statement (default is true). |
boolean |
isCheckIfTableNotExists()
Indicates if
IF NOT EXISTS clause should be included in the CREATE TABLE statement (default is true). |
boolean |
isDropTable()
Indicates if drop table statement should be included in the output DDL for each entity
in the
schemaDef (default true). |
boolean |
isGenerateIndexes()
Indicates if DDL should be generated for indexes in the
schemaDef (default is true). |
boolean |
isGenerateRelationships()
Indicates if DDL should be generated for relationships in the
schemaDef (default is true). |
CreateMySqlDdlFromSchemaDef |
setCheckIfDropTableExists(boolean checkIfDropTableExists)
Indicates if
IF EXISTS clause should be included in the DROP TABLE statement (default is true). |
CreateMySqlDdlFromSchemaDef |
setCheckIfTableNotExists(boolean checkIfTableNotExists)
Indicates if
IF NOT EXISTS clause should be included in the CREATE TABLE statement (default is true). |
CreateMySqlDdlFromSchemaDef |
setDefaultBigDecimalPrecision(int defaultBigDecimalPrecision)
Sets a default precision for
FieldType.BIG_DECIMAL .This value will be used if no precision is specified for BIG_DECIMAL fields (default 20). |
CreateMySqlDdlFromSchemaDef |
setDefaultBigDecimalScale(Integer defaultBigDecimalScale)
Sets a default scale for
FieldType.BIG_DECIMAL (default 5).This value will be used if no scale is specified for BIG_DECIMAL fields. |
CreateMySqlDdlFromSchemaDef |
setDefaultBigIntegerPrecision(int defaultBigIntegerPrecision)
Sets a default precision for
FieldType.BIG_INTEGER (default 20).This value will be used if no precision is specified for BIG_INTEGER fields. |
CreateMySqlDdlFromSchemaDef |
setDropTable(boolean dropTable)
Indicates if drop table statement should be included in the output DDL for each entity
in the
schemaDef (default true). |
CreateMySqlDdlFromSchemaDef |
setEntityNames(List<String> entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
|
CreateMySqlDdlFromSchemaDef |
setEntityNames(String... entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
|
CreateMySqlDdlFromSchemaDef |
setGenerateIndexes(boolean generateIndexes)
Indicates if DDL should be generated for indexes in the
schemaDef (default is true). |
CreateMySqlDdlFromSchemaDef |
setGenerateRelationships(boolean generateRelationships)
Indicates if DDL should be generated for indexes in the
schemaDef (default is true). |
CreateMySqlDdlFromSchemaDef |
setPretty(boolean pretty)
Indicates if line breaks and indentations should be added to output DDL (default false).
Example output (pretty = true):
CREATE TABLE IF NOT EXISTS table_name (
Example output (pretty = false): CREATE TABLE IF NOT EXISTS table_name (id bigint, email text, PRIMARY KEY (user_id)); |
escapeKeyword, placeBackTicks
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
public CreateMySqlDdlFromSchemaDef(SchemaDef schemaDef)
public void collectSqlFragment(CodeWriter writer)
schemaDef
and writes the output to writer
.collectSqlFragment
in class SqlPart
public boolean isGenerateIndexes()
schemaDef
(default is true).public CreateMySqlDdlFromSchemaDef setGenerateIndexes(boolean generateIndexes)
schemaDef
(default is true).public boolean isGenerateRelationships()
schemaDef
(default is true).public CreateMySqlDdlFromSchemaDef setGenerateRelationships(boolean generateRelationships)
schemaDef
(default is true).public boolean isCheckIfTableNotExists()
IF NOT EXISTS
clause should be included in the CREATE TABLE
statement (default is true).public CreateMySqlDdlFromSchemaDef setCheckIfTableNotExists(boolean checkIfTableNotExists)
IF NOT EXISTS
clause should be included in the CREATE TABLE
statement (default is true).public boolean isCheckIfDropTableExists()
IF EXISTS
clause should be included in the DROP TABLE
statement (default is true).public CreateMySqlDdlFromSchemaDef setCheckIfDropTableExists(boolean checkIfDropTableExists)
IF EXISTS
clause should be included in the DROP TABLE
statement (default is true).public List<String> getEntityNames()
setEntityNames(java.util.List<java.lang.String>)
to be included in the output DDL.public CreateMySqlDdlFromSchemaDef setEntityNames(List<String> entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
entityNames
will be excluded from the generated SQL including relationships
that involve any of them.public CreateMySqlDdlFromSchemaDef setEntityNames(String... entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
entityNames
will be excluded from the generated SQL including relationships
that involve any of them.public CreateMySqlDdlFromSchemaDef setPretty(boolean pretty)
CREATE TABLE IF NOT EXISTS table_name (
id bigint,
email text
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS table_name (id bigint, email text, PRIMARY KEY (user_id));
public boolean isDropTable()
schemaDef
(default true).public CreateMySqlDdlFromSchemaDef setDropTable(boolean dropTable)
schemaDef
(default true).public Integer getDefaultBigIntegerPrecision()
FieldType.BIG_INTEGER
(default 20).public CreateMySqlDdlFromSchemaDef setDefaultBigIntegerPrecision(int defaultBigIntegerPrecision)
FieldType.BIG_INTEGER
(default 20).BIG_INTEGER
fields.public Integer getDefaultBigDecimalPrecision()
FieldType.BIG_DECIMAL
(default 20).public CreateMySqlDdlFromSchemaDef setDefaultBigDecimalPrecision(int defaultBigDecimalPrecision)
FieldType.BIG_DECIMAL
.BIG_DECIMAL
fields (default 20).public Integer getDefaultBigDecimalScale()
FieldType.BIG_DECIMAL
(default 5).public CreateMySqlDdlFromSchemaDef setDefaultBigDecimalScale(Integer defaultBigDecimalScale)
FieldType.BIG_DECIMAL
(default 5).BIG_DECIMAL
fields.Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.