public class CreatePostgreSqlDdlFromSchemaDef extends SqlPart
Generates PostgreSQL DDL from SchemaDef
DROP TABLE IF EXISTS table_name;
CREATE TABLE IF NOT EXISTS table_name (
user_id serial,
email text,
PRIMARY KEY (user_id)
);
CREATE INDEX IF NOT EXISTS idx_email ON table_name (email);
ALTER TABLE IF EXISTS 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 |
---|
CreatePostgreSqlDdlFromSchemaDef(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 |
isCheckIfForeignTableExists()
Indicates if
IF EXISTS clause should be included in the ALTER TABLE statement (default is true). |
boolean |
isCheckIfIndexNotExists()
Indicates if
IF NOT EXISTS clause should be included in the CREATE INDEX 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). |
CreatePostgreSqlDdlFromSchemaDef |
setCheckIfDropTableExists(boolean checkIfDropTableExists)
Indicates if
IF EXISTS clause should be included in the DROP TABLE statement (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
setCheckIfForeignTableExists(boolean checkIfForeignTableExists)
Indicates if
IF EXISTS clause should be included in the ALTER TABLE statement (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
setCheckIfIndexNotExists(boolean checkIfIndexNotExists)
Indicates if
IF NOT EXISTS clause should be included in the CREATE INDEX statement (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
setCheckIfTableNotExists(boolean checkIfTableNotExists)
Indicates if
IF NOT EXISTS clause should be included in the CREATE TABLE statement (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
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). |
CreatePostgreSqlDdlFromSchemaDef |
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. |
CreatePostgreSqlDdlFromSchemaDef |
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. |
CreatePostgreSqlDdlFromSchemaDef |
setDropTable(boolean dropTable)
Indicates if drop table statement should be included in the output DDL for each entity
in the
schemaDef (default true). |
CreatePostgreSqlDdlFromSchemaDef |
setEntityNames(List<String> entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
|
CreatePostgreSqlDdlFromSchemaDef |
setEntityNames(String... entityNames)
Set entity names that should be included in the output DDL (all entities will be included by default).
|
CreatePostgreSqlDdlFromSchemaDef |
setGenerateIndexes(boolean generateIndexes)
Indicates if DDL should be generated for indexes in the
schemaDef (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
setGenerateRelationships(boolean generateRelationships)
Indicates if DDL should be generated for indexes in the
schemaDef (default is true). |
CreatePostgreSqlDdlFromSchemaDef |
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 serial, email text, PRIMARY KEY (user_id)); |
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
public CreatePostgreSqlDdlFromSchemaDef(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 CreatePostgreSqlDdlFromSchemaDef setGenerateIndexes(boolean generateIndexes)
schemaDef
(default is true).public boolean isGenerateRelationships()
schemaDef
(default is true).public CreatePostgreSqlDdlFromSchemaDef 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 CreatePostgreSqlDdlFromSchemaDef 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 CreatePostgreSqlDdlFromSchemaDef setCheckIfDropTableExists(boolean checkIfDropTableExists)
IF EXISTS
clause should be included in the DROP TABLE
statement (default is true).public boolean isCheckIfIndexNotExists()
IF NOT EXISTS
clause should be included in the CREATE INDEX
statement (default is true).public CreatePostgreSqlDdlFromSchemaDef setCheckIfIndexNotExists(boolean checkIfIndexNotExists)
IF NOT EXISTS
clause should be included in the CREATE INDEX
statement (default is true).public boolean isCheckIfForeignTableExists()
IF EXISTS
clause should be included in the ALTER TABLE
statement (default is true).public CreatePostgreSqlDdlFromSchemaDef setCheckIfForeignTableExists(boolean checkIfForeignTableExists)
IF EXISTS
clause should be included in the ALTER TABLE
statement (default is true).public List<String> getEntityNames()
setEntityNames(java.util.List<java.lang.String>)
to be included in the output DDL.public CreatePostgreSqlDdlFromSchemaDef 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 CreatePostgreSqlDdlFromSchemaDef 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 CreatePostgreSqlDdlFromSchemaDef setPretty(boolean pretty)
CREATE TABLE IF NOT EXISTS table_name (
id serial,
email text
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS table_name (id serial, email text, PRIMARY KEY (user_id));
public boolean isDropTable()
schemaDef
(default true).public CreatePostgreSqlDdlFromSchemaDef setDropTable(boolean dropTable)
schemaDef
(default true).public Integer getDefaultBigIntegerPrecision()
FieldType.BIG_INTEGER
(default 20).public CreatePostgreSqlDdlFromSchemaDef setDefaultBigIntegerPrecision(int defaultBigIntegerPrecision)
FieldType.BIG_INTEGER
(default 20).BIG_INTEGER
fields.public Integer getDefaultBigDecimalPrecision()
FieldType.BIG_DECIMAL
(default 20).public CreatePostgreSqlDdlFromSchemaDef setDefaultBigDecimalPrecision(int defaultBigDecimalPrecision)
FieldType.BIG_DECIMAL
.BIG_DECIMAL
fields (default 20).public Integer getDefaultBigDecimalScale()
FieldType.BIG_DECIMAL
(default 5).public CreatePostgreSqlDdlFromSchemaDef setDefaultBigDecimalScale(Integer defaultBigDecimalScale)
FieldType.BIG_DECIMAL
(default 5).BIG_DECIMAL
fields.Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.