Class CreateTable
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.sql.h2.H2SqlPart
com.northconcepts.datapipeline.sql.h2.CreateTable
Generates a CREATE TABLE statement for H2.
Sample Generated SQL:
CREATE TABLE IF NOT EXISTS table_name (
user_id int,
email text,
PRIMARY KEY (user_id)
);
-
Constructor Summary
ConstructorsConstructorDescriptionCreateTable(String tableName) Constructs a CreateTable with the specified table name. -
Method Summary
Modifier and TypeMethodDescriptionaddColumn(CreateTableColumn column) Adds a column to this table.voidcollectSqlFragment(CodeWriter writer) Writes this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.Returns the list of columns.Returns the list of primary key columns.Returns the table name.booleanIndicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default true).setCheckIfNotExists(boolean checkIfNotExists) Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default true).setColumns(List<CreateTableColumn> columns) Sets the columns.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 (
user_id int,
email text
PRIMARY KEY (user_id)
)
Example output (pretty = false):
CREATE TABLE IF NOT EXISTS table_name (user_id int, email text, PRIMARY KEY (user_id))setTableName(String tableName) Sets the table name.Methods inherited from class com.northconcepts.datapipeline.sql.h2.H2SqlPart
escapeKeyword, placeBackTicksMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
CreateTable
public CreateTable() -
CreateTable
Constructs a CreateTable with the specified table name.- Parameters:
tableName- the table name
-
-
Method Details
-
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 (
user_id int,
email text
PRIMARY KEY (user_id)
)
Example output (pretty = false):
CREATE TABLE IF NOT EXISTS table_name (user_id int, email text, PRIMARY KEY (user_id)) -
collectSqlFragment
Description copied from class:SqlPartWrites this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.- Specified by:
collectSqlFragmentin classSqlPart
-
getTableName
Returns the table name.- Returns:
- the table name
-
setTableName
Sets the table name.- Parameters:
tableName- the table name- Returns:
- this instance
-
isCheckIfNotExists
public boolean isCheckIfNotExists()Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default true). -
setCheckIfNotExists
Indicates ifIF NOT EXISTSclause should be included in theCREATE TABLEstatement (default true). -
getColumns
Returns the list of columns.- Returns:
- the list of columns
-
setColumns
Sets the columns.- Parameters:
columns- the list of columns- Returns:
- this instance
-
addColumn
Adds a column to this table.- Parameters:
column- the column to add- Returns:
- this instance
-
getPrimaryKeyColumns
Returns the list of primary key columns.- Returns:
- the list of primary key columns
-