Class TableBuilder
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.builders.SQLBuilder
-
- com.jgcomptech.tools.databasetools.jdbc.builders.TableBuilder
-
public class TableBuilder extends SQLBuilder
A builder class for creating an CREATE sql statement to create a new table.- Since:
- 1.4.0
-
-
Constructor Summary
Constructors Constructor Description TableBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TableBuilder
addColumn(ColumnBuilder builder)
Adds a column to the table using the ColumnBuilder class.TableBuilder
addColumn(java.lang.String columnSql)
Adds a column to the table using a sql string.TypedStatement
build()
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.TypedStatement
build(Database db)
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.boolean
buildAndCreate()
Runs buildPreparedStatement, executes the statement and returns true if no errors occurred.TableBuilder
CREATE(java.lang.String tableName, Database db)
Generates sql code for creation of a table.-
Methods inherited from class com.jgcomptech.tools.databasetools.jdbc.builders.SQLBuilder
buildPreparedStatement, getSql, getStatement, setStatement, toString
-
-
-
-
Method Detail
-
CREATE
public TableBuilder CREATE(java.lang.String tableName, Database db) throws java.sql.SQLException
Generates sql code for creation of a table.- Parameters:
tableName
- the name of the table to createdb
- the database object for database type checking- Returns:
- the instance of the builder to continue building
- Throws:
java.lang.IllegalStateException
- if this is not the first method calledjava.sql.SQLException
- if a database access error occurs
-
addColumn
public TableBuilder addColumn(ColumnBuilder builder)
Adds a column to the table using the ColumnBuilder class.- Parameters:
builder
- the ColumnBuilder instance- Returns:
- the instance of the builder to continue building
- Throws:
java.lang.IllegalStateException
- if the CREATE statement is not called first
-
addColumn
public TableBuilder addColumn(java.lang.String columnSql)
Adds a column to the table using a sql string.- Parameters:
columnSql
- the sql statement to create the column- Returns:
- the instance of the builder to continue building
- Throws:
java.lang.IllegalStateException
- if the CREATE statement is not called first
-
build
public TypedStatement build(Database db) throws java.sql.SQLException
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.- Specified by:
build
in classSQLBuilder
- Parameters:
db
- the database to request thePreparedStatement
object from- Returns:
- a new instance of
TypedStatement
- Throws:
java.sql.SQLException
- if a database access error occurs
-
build
public TypedStatement build() throws java.sql.SQLException
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
. Uses the db object passed into the constructor.- Returns:
- a new instance of
TypedStatement
- Throws:
java.sql.SQLException
- if a database access error occurs
-
buildAndCreate
public boolean buildAndCreate() throws java.sql.SQLException
Runs buildPreparedStatement, executes the statement and returns true if no errors occurred.- Returns:
- the result of the statement as a boolean, true if no errors occurred
- Throws:
java.sql.SQLException
- if a database access error occurs
-
-