Class CreateMySqlDdlFromSchemaDef
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.sql.mysql.MySqlPart
com.northconcepts.datapipeline.sql.mysql.CreateMySqlDdlFromSchemaDef
Generates MySQL DDL from SchemaDef
Sample Generated SQL:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcollectSqlFragment(CodeWriter writer) Generates DDL fromschemaDefand writes the output towriter.Returns the default precision ofFieldType.BIG_DECIMAL(default 20).Sets the default scale ofFieldType.BIG_DECIMAL(default 5).Returns the default precision ofFieldType.BIG_INTEGER(default 20).Returns entity names that are specified bysetEntityNames(java.util.List<java.lang.String>)to be included in the output DDL.Returns providedschemaDef.booleanIndicates ifIF EXISTSclause should be included in theDROP TABLEstatement (default is true).booleanIndicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default is true).booleanIndicates if drop table statement should be included in the output DDL for each entity in theschemaDef(default true).booleanIndicates if DDL should be generated for indexes in theschemaDef(default is true).booleanIndicates if DDL should be generated for relationships in theschemaDef(default is true).setCheckIfDropTableExists(boolean checkIfDropTableExists) Indicates ifIF EXISTSclause should be included in theDROP TABLEstatement (default is true).setCheckIfTableNotExists(boolean checkIfTableNotExists) Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default is true).setDefaultBigDecimalPrecision(int defaultBigDecimalPrecision) Sets a default precision forFieldType.BIG_DECIMAL.
This value will be used if no precision is specified forBIG_DECIMALfields (default 20).setDefaultBigDecimalScale(Integer defaultBigDecimalScale) Sets a default scale forFieldType.BIG_DECIMAL(default 5).
This value will be used if no scale is specified forBIG_DECIMALfields.setDefaultBigIntegerPrecision(int defaultBigIntegerPrecision) Sets a default precision forFieldType.BIG_INTEGER(default 20).
This value will be used if no precision is specified forBIG_INTEGERfields.setDropTable(boolean dropTable) Indicates if drop table statement should be included in the output DDL for each entity in theschemaDef(default true).setEntityNames(String... entityNames) Set entity names that should be included in the output DDL (all entities will be included by default).setEntityNames(List<String> entityNames) Set entity names that should be included in the output DDL (all entities will be included by default).setGenerateIndexes(boolean generateIndexes) Indicates if DDL should be generated for indexes in theschemaDef(default is true).setGenerateRelationships(boolean generateRelationships) Indicates if DDL should be generated for indexes in theschemaDef(default is true).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 (
id bigint,
email text
PRIMARY KEY (user_id)
);
Example output (pretty = false):
CREATE TABLE IF NOT EXISTS table_name (id bigint, email text, PRIMARY KEY (user_id));Methods inherited from class com.northconcepts.datapipeline.sql.mysql.MySqlPart
escapeKeyword, placeBackTicksMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
CreateMySqlDdlFromSchemaDef
-
-
Method Details
-
collectSqlFragment
Generates DDL fromschemaDefand writes the output towriter.- Specified by:
collectSqlFragmentin classSqlPart
-
getSchemaDef
Returns providedschemaDef. -
isGenerateIndexes
public boolean isGenerateIndexes()Indicates if DDL should be generated for indexes in theschemaDef(default is true). -
setGenerateIndexes
Indicates if DDL should be generated for indexes in theschemaDef(default is true). -
isGenerateRelationships
public boolean isGenerateRelationships()Indicates if DDL should be generated for relationships in theschemaDef(default is true). -
setGenerateRelationships
Indicates if DDL should be generated for indexes in theschemaDef(default is true). -
isCheckIfTableNotExists
public boolean isCheckIfTableNotExists()Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default is true). -
setCheckIfTableNotExists
Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default is true). -
isCheckIfDropTableExists
public boolean isCheckIfDropTableExists()Indicates ifIF EXISTSclause should be included in theDROP TABLEstatement (default is true). -
setCheckIfDropTableExists
Indicates ifIF EXISTSclause should be included in theDROP TABLEstatement (default is true). -
getEntityNames
Returns entity names that are specified bysetEntityNames(java.util.List<java.lang.String>)to be included in the output DDL. -
setEntityNames
Set entity names that should be included in the output DDL (all entities will be included by default).
Entities that are not listed inentityNameswill be excluded from the generated SQL including relationships that involve any of them. -
setEntityNames
Set entity names that should be included in the output DDL (all entities will be included by default).
Entities that are not listed inentityNameswill be excluded from the generated SQL including relationships that involve any of them. -
setPretty
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 (
id bigint,
email text
PRIMARY KEY (user_id)
);
Example output (pretty = false):
CREATE TABLE IF NOT EXISTS table_name (id bigint, email text, PRIMARY KEY (user_id)); -
isDropTable
public boolean isDropTable()Indicates if drop table statement should be included in the output DDL for each entity in theschemaDef(default true). -
setDropTable
Indicates if drop table statement should be included in the output DDL for each entity in theschemaDef(default true). -
getDefaultBigIntegerPrecision
Returns the default precision ofFieldType.BIG_INTEGER(default 20). -
setDefaultBigIntegerPrecision
Sets a default precision forFieldType.BIG_INTEGER(default 20).
This value will be used if no precision is specified forBIG_INTEGERfields. -
getDefaultBigDecimalPrecision
Returns the default precision ofFieldType.BIG_DECIMAL(default 20). -
setDefaultBigDecimalPrecision
Sets a default precision forFieldType.BIG_DECIMAL.
This value will be used if no precision is specified forBIG_DECIMALfields (default 20). -
getDefaultBigDecimalScale
Sets the default scale ofFieldType.BIG_DECIMAL(default 5). -
setDefaultBigDecimalScale
Sets a default scale forFieldType.BIG_DECIMAL(default 5).
This value will be used if no scale is specified forBIG_DECIMALfields.
-