Class AbstractTableBuilder<T extends AbstractTableBuilder<T>>
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
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
ConstructorsConstructorDescriptionAbstractTableBuilder(Connection connection, String table) Constructs a new AbstractTableBuilder. -
Method Summary
Modifier and TypeMethodDescriptionautoIncrement(String column) Redefines a column to include the auto-increment property.Adds a CHECK constraint to ensure valid data.Defines a column in the table.defaultValue(String column, String defaultValue) Assigns a default value to a column.voidDrops the table if it exists in the database.voidexecute()Compiles and executes the CREATE TABLE SQL statement based on the provided configuration.foreignKey(String column, String referencesTable, String referencesColumn) Adds a foreign key constraint to the table.Configures the builder to include the "IF NOT EXISTS" clause.primaryKey(String... keys) 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
-
-
autoIncrement
-
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
-
check
-
defaultValue
-
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.
-