public class TableBuilder
extends java.lang.Object
Table.
Example:
Table table = new TableBuilder("Test")
.addColumn(new ColumnBuilder("ID", DataType.LONG)
.setAutoNumber(true))
.addColumn(new ColumnBuilder("Name", DataType.TEXT))
.addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME)
.addColumns("ID").setPrimaryKey())
.toTable(db);
| Modifier and Type | Class and Description |
|---|---|
private static class |
TableBuilder.ReservedWords |
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<ColumnBuilder> |
_columns
columns for the new table
|
private boolean |
_escapeIdentifiers
whether or not table/column/index names are automatically escaped
|
private java.util.List<IndexBuilder> |
_indexes
indexes for the new table
|
private java.lang.String |
_name
name of the new table
|
private java.util.Map<java.lang.String,PropertyMap.Property> |
_props
table properties (if any)
|
private static java.lang.String |
ESCAPE_PREFIX
Prefix for column or table names that are reserved words
|
| Constructor and Description |
|---|
TableBuilder(java.lang.String name) |
TableBuilder(java.lang.String name,
boolean escapeIdentifiers) |
| Modifier and Type | Method and Description |
|---|---|
TableBuilder |
addColumn(ColumnBuilder column)
Adds a Column to the new table.
|
TableBuilder |
addColumns(java.util.Collection<? extends ColumnBuilder> columns)
Adds the Columns to the new table.
|
TableBuilder |
addIndex(IndexBuilder index)
Adds an IndexBuilder to the new table.
|
static java.lang.String |
escapeIdentifier(java.lang.String s) |
TableBuilder |
escapeName()
Escapes the new table's name using
escapeIdentifier(java.lang.String). |
static boolean |
isReservedWord(java.lang.String s) |
TableBuilder |
putProperty(java.lang.String name,
DataType type,
java.lang.Object value)
Sets the table property with the given name and type to the given value.
|
TableBuilder |
putProperty(java.lang.String name,
java.lang.Object value)
Sets the table property with the given name to the given value.
|
TableBuilder |
setEscapeIdentifiers(boolean escapeIdentifiers)
Sets whether or not subsequently added columns will have their names
automatically escaped
|
TableBuilder |
setPrimaryKey(java.lang.String... colNames)
Sets the names of the primary key columns for this table.
|
Table |
toTable(Database db)
Creates a new Table in the given Database with the currently configured
attributes.
|
private static final java.lang.String ESCAPE_PREFIX
private java.lang.String _name
private java.util.List<ColumnBuilder> _columns
private java.util.List<IndexBuilder> _indexes
private boolean _escapeIdentifiers
private java.util.Map<java.lang.String,PropertyMap.Property> _props
public TableBuilder(java.lang.String name)
public TableBuilder(java.lang.String name,
boolean escapeIdentifiers)
public TableBuilder addColumn(ColumnBuilder column)
public TableBuilder addColumns(java.util.Collection<? extends ColumnBuilder> columns)
public TableBuilder addIndex(IndexBuilder index)
public TableBuilder setEscapeIdentifiers(boolean escapeIdentifiers)
public TableBuilder setPrimaryKey(java.lang.String... colNames)
public TableBuilder escapeName()
escapeIdentifier(java.lang.String).public TableBuilder putProperty(java.lang.String name, java.lang.Object value)
PropertyMap.put(String,Object) for details on determining the
property type).public TableBuilder putProperty(java.lang.String name, DataType type, java.lang.Object value)
public Table toTable(Database db) throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String escapeIdentifier(java.lang.String s)
public static boolean isReservedWord(java.lang.String s)
true if the given string is a reserved word,
false otherwise