public class PostgreSQLDDLBuilder
extends java.lang.Object
Prevents SQL-Injection and Syntax Errors by centralizing the correct escaping and quoting of identifiers (Table names, Column names).
| Modifier and Type | Method and Description |
|---|---|
PostgreSQLDDLBuilder |
addColumn(java.lang.String columnDef)
Adds a complete column definition to the statement.
|
PostgreSQLDDLBuilder |
addPrimaryKey(java.lang.String column) |
PostgreSQLDDLBuilder |
alterColumnSetNotNull(java.lang.String columnName) |
PostgreSQLDDLBuilder |
alterColumnTypeUsing(java.lang.String columnName,
java.lang.String type,
java.lang.String usingExpr)
Alters the type of a column using an explicit casting expression.
|
static PostgreSQLDDLBuilder |
alterExtensionUpdateTo(java.lang.String extName,
java.lang.String version)
Creates an ALTER EXTENSION UPDATE TO statement.
|
static PostgreSQLDDLBuilder |
alterTable(java.lang.String tableName) |
static PostgreSQLDDLBuilder |
alterTableOnly(java.lang.String tableName) |
java.lang.String |
build() |
PostgreSQLDDLBuilder |
columns(java.lang.String column) |
PostgreSQLDDLBuilder |
columns(java.lang.String column1,
java.lang.String column2) |
static PostgreSQLDDLBuilder |
createExtension(java.lang.String extName) |
static PostgreSQLDDLBuilder |
createIndex(java.lang.String indexName) |
static PostgreSQLDDLBuilder |
createTable(java.lang.String tableName,
java.lang.String columnDefs) |
static PostgreSQLDDLBuilder |
createUniqueIndex(java.lang.String indexName) |
PostgreSQLDDLBuilder |
customDefinition(java.lang.String customDef)
Appends a raw custom definition to the DDL statement.
|
PostgreSQLDDLBuilder |
dropColumn(java.lang.String columnName) |
PostgreSQLDDLBuilder |
dropConstraint(java.lang.String constraintName) |
static PostgreSQLDDLBuilder |
dropIndex(java.lang.String indexName) |
static PostgreSQLDDLBuilder |
dropTable(java.lang.String tableName) |
PostgreSQLDDLBuilder |
inherit(java.lang.String parentTableName) |
PostgreSQLDDLBuilder |
inherits(java.lang.String parentTableName) |
PostgreSQLDDLBuilder |
noInherit(java.lang.String parentTableName) |
PostgreSQLDDLBuilder |
onTable(java.lang.String tableName) |
static java.lang.String |
quote(java.lang.String identifier)
Safely quotes a PostgreSQL identifier (e.g. table name, column name).
|
PostgreSQLDDLBuilder |
setFalseWhereNull(java.lang.String columnName) |
static PostgreSQLDDLBuilder |
update(java.lang.String tableName) |
PostgreSQLDDLBuilder |
using(java.lang.String indexType,
java.lang.String columnDef)
Appends the USING clause for indices.
|
public static java.lang.String quote(java.lang.String identifier)
public static PostgreSQLDDLBuilder alterTable(java.lang.String tableName)
public static PostgreSQLDDLBuilder alterTableOnly(java.lang.String tableName)
public static PostgreSQLDDLBuilder createTable(java.lang.String tableName, java.lang.String columnDefs)
public static PostgreSQLDDLBuilder dropTable(java.lang.String tableName)
public static PostgreSQLDDLBuilder update(java.lang.String tableName)
public static PostgreSQLDDLBuilder dropIndex(java.lang.String indexName)
public static PostgreSQLDDLBuilder createIndex(java.lang.String indexName)
public static PostgreSQLDDLBuilder createUniqueIndex(java.lang.String indexName)
public PostgreSQLDDLBuilder onTable(java.lang.String tableName)
public PostgreSQLDDLBuilder columns(java.lang.String column)
public PostgreSQLDDLBuilder columns(java.lang.String column1, java.lang.String column2)
public PostgreSQLDDLBuilder addPrimaryKey(java.lang.String column)
public PostgreSQLDDLBuilder using(java.lang.String indexType, java.lang.String columnDef)
Security Note: 'columnDef' is a SQL fragment (e.g. '"col" gin_trgm_ops') and must have its identifiers quoted by the caller.
public PostgreSQLDDLBuilder customDefinition(java.lang.String customDef)
Security Note: The caller is responsible for ensuring the fragment is safe.
public static PostgreSQLDDLBuilder createExtension(java.lang.String extName)
public static PostgreSQLDDLBuilder alterExtensionUpdateTo(java.lang.String extName, java.lang.String version)
Security Note: The version is a string literal (not an identifier), therefore single quotes are escaped instead of double quotes.
public PostgreSQLDDLBuilder dropConstraint(java.lang.String constraintName)
public PostgreSQLDDLBuilder dropColumn(java.lang.String columnName)
public PostgreSQLDDLBuilder addColumn(java.lang.String columnDef)
Security Note: Because this is a SQL fragment (e.g. '"colName" int8 NOT NULL'), it is NOT automatically quoted. The caller must ensure the column name inside the fragment is quoted.
public PostgreSQLDDLBuilder alterColumnSetNotNull(java.lang.String columnName)
public PostgreSQLDDLBuilder alterColumnTypeUsing(java.lang.String columnName, java.lang.String type, java.lang.String usingExpr)
Security Note: 'type' and 'usingExpr' are SQL expressions/keywords and are NOT quoted.
The caller is responsible for calling quote() on any column identifiers embedded within 'usingExpr'.
columnName - Will be safely quoted automatically.type - Raw PostgreSQL type (e.g. "varchar(255)"). Must not be quoted.usingExpr - Raw PostgreSQL expression (e.g. "CAST(\"col\" AS int8)"). Must not be quoted.public PostgreSQLDDLBuilder inherit(java.lang.String parentTableName)
public PostgreSQLDDLBuilder inherits(java.lang.String parentTableName)
public PostgreSQLDDLBuilder noInherit(java.lang.String parentTableName)
public PostgreSQLDDLBuilder setFalseWhereNull(java.lang.String columnName)
public java.lang.String build()
Copyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.