JavaScript is disabled on your browser.
java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractTableBuilder<T>
Type Parameters:
T - The implementation type for fluent chaining.
Direct Known Subclasses:
TableBuilder , TableBuilder , TableBuilder , TableBuilder , TableBuilder
public abstract class AbstractTableBuilder<T extends AbstractTableBuilder<T>>
extends Object
A fluent-style builder for programmatically creating database tables.
This class handles column definitions, keys, constraints, and table options,
abstracting away the differences between SQL dialects.
Constructor Summary
Constructors
Constructs a new AbstractTableBuilder.
Method Summary
All Methods Instance Methods Concrete Methods
Redefines a column to include the auto-increment property.
Adds a CHECK constraint to ensure valid data.
Defines a column in the table.
Assigns a default value to a column.
void
Drops the table if it exists in the database.
void
Compiles and executes the CREATE TABLE SQL statement based on the provided configuration.
Adds a foreign key constraint to the table.
Configures the builder to include the "IF NOT EXISTS" clause.
Sets one or more columns as the table's primary key.
Adds a unique constraint on the specified columns.
Constructor Details
AbstractTableBuilder
Constructs a new AbstractTableBuilder.
Parameters:
connection - The JDBC connection to use.
table - The name of the table to build.
Method Details
ifNotExists
Configures the builder to include the "IF NOT EXISTS" clause.
Returns:
The current instance cast to T.
column
Defines a column in the table.
Parameters:
name - The column name.
type - The SQL data type string (e.g., "INT", "TEXT", "VARCHAR(32)").
Returns:
The current instance cast to T.
primaryKey
public T primaryKey (String ... keys)
Sets one or more columns as the table's primary key.
Parameters:
keys - The column names to include in the primary key.
Returns:
The current instance cast to T.
autoIncrement
public T autoIncrement (String column)
Redefines a column to include the auto-increment property.
Parameters:
column - The name of the column to modify.
Returns:
The current instance cast to T.
foreignKey
Adds a foreign key constraint to the table.
Parameters:
column - The local column name.
referencesTable - The table name being referenced.
referencesColumn - The column name being referenced in the target table.
Returns:
The current instance cast to T.
unique
Adds a unique constraint on the specified columns.
Parameters:
columns - The columns that must contain unique data.
Returns:
The current instance cast to T.
check
Adds a CHECK constraint to ensure valid data.
Parameters:
expression - The SQL boolean expression to check.
Returns:
The current instance cast to T.
defaultValue
Assigns a default value to a column.
Parameters:
column - The name of the column.
defaultValue - The default value as a string (e.g., "'Unknown'" or "0").
Returns:
The current instance cast to T.
dropIfExists
public void dropIfExists ()
Drops the table if it exists in the database.
Throws:
RuntimeException - If the drop operation fails.
execute
public void execute ()
Compiles and executes the CREATE TABLE SQL statement based on the provided configuration.
Throws:
RuntimeException - If the table creation fails.