Package com.gengoai.sql.object
Class Table
- java.lang.Object
-
- com.gengoai.sql.object.SQLObject
-
- com.gengoai.sql.object.Table
-
- All Implemented Interfaces:
NamedSQLElement
,SQLOperable
,SQLElement
,Serializable
public class Table extends SQLObject implements NamedSQLElement, SQLOperable
The type Table.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Table(String name)
Instantiates a new Table.Table(String name, SQLElement tableType)
Instantiates a new Table.Table(String name, SQLElement tableType, @NonNull List<Column> columns, @NonNull List<Constraint> constraints)
Instantiates a new Table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AlterTable
addColumn(@NonNull Column column)
Adds the given column to the table definition generating anAlterTable
statement to perform on the database.AlterTable
addConstraint(@NonNull Constraint constraint)
Adds the givenConstraint
to the table definition generating anAlterTable
statement to perform on the database.AlterTable
alterColumn(@NonNull String name, @NonNull Consumer<Column> consumer)
Alters the definition of the given column generating anAlterTable
statement to perform on the database.int
batchInsert(@NonNull SQLContext context, @NonNull Stream<Map<String,?>> values)
Batch insert int.int
batchUpsert(@NonNull SQLContext context, @NonNull List<String> indexedColumns, @NonNull Stream<Map<String,?>> values)
Batch upsert int.Column
column(String name)
Column column.long
count(@NonNull SQLContext context)
Performs aselect count(0)
from this table.int
delete(@NonNull SQLContext context, @NonNull SQLElement where)
Deletes all rows matching the given where criteriaint
deleteAll(@NonNull SQLContext context)
Deletes all rows from the tableAlterTable
dropColumn(@NonNull String name)
Removes the column with the given name from the table definition generating anAlterTable
statement to perform on the database.boolean
dropIndex(@NonNull SQLContext context, String name)
Drop index boolean.boolean
dropIndexIfExists(@NonNull SQLContext context, String name)
Drop index if exists boolean.boolean
exists(@NonNull SQLContext context)
Checks if this table exists in the database using the givenSQLContext
String
getKeyword()
Gets the SQL Keyword associated with the objectIndexBuilder
index(String name)
Index index builder.Insert
insert()
Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.int
insert(@NonNull SQLContext context, @NonNull Map<String,Object> values)
Insert int.Insert
insert(@NonNull InsertType insertType)
Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.SQLOperable
qualifiedColumnName(@NonNull Column column)
Gets the qualified column name, i.e.SQLOperable
qualifiedColumnName(@NonNull String column)
Gets the qualified column name, i.e.AlterTable
renameColumn(@NonNull String name, @NonNull String newName)
Renames the column with the given name to the given new name generating anAlterTable
statement to execute on the database.AlterTable
renameTable(@NonNull String newName)
Renames the table to the given new name generating anAlterTable
statement to execute on the database.Select
select()
Creates a select statement selecting from this table with nothing else specifiedSelect
select(@NonNull SQLElement... columns)
Creates a select statement selecting from this table returning the specified columnsSelect
select(@NonNull String... columns)
Creates a select statement selecting from this table returning the specified columnsSelect
selectAll()
Creates a select statement selecting all columns from this table.Update
update()
Creates an update statement for this tableint
update(@NonNull SQLContext context, @NonNull UpdateType updateType, @NonNull Map<String,SQLElement> setParameters, @NonNull SQLElement where)
int
update(@NonNull SQLContext context, @NonNull Map<String,SQLElement> setParameters, @NonNull SQLElement where)
Update
update(@NonNull UpdateType updateType)
Creates an update statement for this tableboolean
upsert(@NonNull SQLContext context, String indexedColumn, @NonNull Map<String,Object> values)
Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.boolean
upsert(@NonNull SQLContext context, List<String> indexedColumns, @NonNull Map<String,Object> values)
Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.-
Methods inherited from class com.gengoai.sql.object.SQLObject
create, create, createIfNotExists, drop, drop, dropIfExists, getName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gengoai.sql.NamedSQLElement
getName
-
Methods inherited from interface com.gengoai.sql.SQLElement
getClassName
-
-
-
-
Constructor Detail
-
Table
public Table(String name, SQLElement tableType)
Instantiates a new Table.- Parameters:
name
- the name of the TabletableType
- RDMS specific string defining type of table
-
Table
public Table(String name)
Instantiates a new Table.- Parameters:
name
- the name of the Table
-
Table
public Table(String name, SQLElement tableType, @NonNull @NonNull List<Column> columns, @NonNull @NonNull List<Constraint> constraints)
Instantiates a new Table.- Parameters:
name
- the name of the TabletableType
- RDMS specific string defining type of tablecolumns
- the columns on the tableconstraints
- the constraints on the table
-
-
Method Detail
-
addColumn
public AlterTable addColumn(@NonNull @NonNull Column column)
Adds the given column to the table definition generating anAlterTable
statement to perform on the database.- Parameters:
column
- the column to add- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
addConstraint
public AlterTable addConstraint(@NonNull @NonNull Constraint constraint)
Adds the givenConstraint
to the table definition generating anAlterTable
statement to perform on the database.- Parameters:
constraint
- the table constraint to add- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
alterColumn
public AlterTable alterColumn(@NonNull @NonNull String name, @NonNull @NonNull Consumer<Column> consumer)
Alters the definition of the given column generating anAlterTable
statement to perform on the database.- Parameters:
name
- the column to alterconsumer
- the consumer to use to update the column definition- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
batchInsert
public int batchInsert(@NonNull @NonNull SQLContext context, @NonNull @NonNull Stream<Map<String,?>> values) throws SQLException
Batch insert int.- Parameters:
context
- the contextvalues
- the values- Returns:
- the int
- Throws:
SQLException
- the sql exception
-
batchUpsert
public int batchUpsert(@NonNull @NonNull SQLContext context, @NonNull @NonNull List<String> indexedColumns, @NonNull @NonNull Stream<Map<String,?>> values) throws SQLException
Batch upsert int.- Parameters:
context
- the contextindexedColumns
- the indexed columnsvalues
- the values- Returns:
- the int
- Throws:
SQLException
- the sql exception
-
column
public Column column(String name)
Column column.- Parameters:
name
- the name- Returns:
- the column
-
count
public long count(@NonNull @NonNull SQLContext context) throws SQLException
Performs aselect count(0)
from this table.- Parameters:
context
- the context to perform the query on- Returns:
- the result of the select count query
- Throws:
SQLException
- something happened trying to query
-
delete
public int delete(@NonNull @NonNull SQLContext context, @NonNull @NonNull SQLElement where) throws SQLException
Deletes all rows matching the given where criteria- Parameters:
context
- theSQLContext
to perform the delete onwhere
- the criteria for row deletion- Returns:
- the number of items deleted
- Throws:
SQLException
- something happened trying to update
-
deleteAll
public int deleteAll(@NonNull @NonNull SQLContext context) throws SQLException
Deletes all rows from the table- Parameters:
context
- theSQLContext
to perform the delete on- Returns:
- the number of items deleted
- Throws:
SQLException
- something happened trying to update
-
dropColumn
public AlterTable dropColumn(@NonNull @NonNull String name)
Removes the column with the given name from the table definition generating anAlterTable
statement to perform on the database.- Parameters:
name
- the name of the column to drop- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
dropIndex
public boolean dropIndex(@NonNull @NonNull SQLContext context, String name) throws SQLException
Drop index boolean.- Parameters:
context
- the contextname
- the name- Returns:
- the boolean
- Throws:
SQLException
- the sql exception
-
dropIndexIfExists
public boolean dropIndexIfExists(@NonNull @NonNull SQLContext context, String name) throws SQLException
Drop index if exists boolean.- Parameters:
context
- the contextname
- the name- Returns:
- the boolean
- Throws:
SQLException
- the sql exception
-
exists
public boolean exists(@NonNull @NonNull SQLContext context) throws SQLException
Checks if this table exists in the database using the givenSQLContext
- Parameters:
context
- the context to use to check for the table's existence.- Returns:
- True if table exists, False otherwise
- Throws:
SQLException
- something happened trying to query for table existence
-
getKeyword
public String getKeyword()
Description copied from class:SQLObject
Gets the SQL Keyword associated with the object- Specified by:
getKeyword
in classSQLObject
- Returns:
- the SQL keyword
-
index
public IndexBuilder index(String name)
Index index builder.- Parameters:
name
- the name- Returns:
- the index builder
-
insert
public Insert insert()
Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.- Returns:
- the insert statement
-
insert
public Insert insert(@NonNull @NonNull InsertType insertType)
Creates an Insert statement for this table automatically filling in the columns with those that are required and setting the values to either be default (if no columns are required) or named parameters based on the column name.- Parameters:
insertType
- the type of insert to perform- Returns:
- the insert statement
-
insert
public int insert(@NonNull @NonNull SQLContext context, @NonNull @NonNull Map<String,Object> values) throws SQLException
Insert int.- Parameters:
context
- the contextvalues
- the values- Returns:
- the int
- Throws:
SQLException
- the sql exception
-
qualifiedColumnName
public SQLOperable qualifiedColumnName(@NonNull @NonNull Column column)
Gets the qualified column name, i.e.table.column
- Parameters:
column
- the column name- Returns:
- the SQLOperable representing the qualified column name
-
qualifiedColumnName
public SQLOperable qualifiedColumnName(@NonNull @NonNull String column)
Gets the qualified column name, i.e.table.column
- Parameters:
column
- the column name- Returns:
- the SQLOperable representing the qualified column name
-
renameColumn
public AlterTable renameColumn(@NonNull @NonNull String name, @NonNull @NonNull String newName)
Renames the column with the given name to the given new name generating anAlterTable
statement to execute on the database.- Parameters:
name
- the current column namenewName
- the new column name- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
renameTable
public AlterTable renameTable(@NonNull @NonNull String newName)
Renames the table to the given new name generating anAlterTable
statement to execute on the database.- Parameters:
newName
- the new table name- Returns:
- the
AlterTable
statement needed to sync the code definition with the database definition
-
select
public Select select(@NonNull @NonNull String... columns)
Creates a select statement selecting from this table returning the specified columns- Parameters:
columns
- the columns to select- Returns:
- the select statement
-
select
public Select select(@NonNull @NonNull SQLElement... columns)
Creates a select statement selecting from this table returning the specified columns- Parameters:
columns
- the columns to select- Returns:
- the select statement
-
select
public Select select()
Creates a select statement selecting from this table with nothing else specified- Returns:
- the select statement
-
selectAll
public Select selectAll()
Creates a select statement selecting all columns from this table.- Returns:
- the select statement
-
update
public Update update()
Creates an update statement for this table- Returns:
- the update statement
-
update
public Update update(@NonNull @NonNull UpdateType updateType)
Creates an update statement for this table- Parameters:
updateType
- the type of update to perform- Returns:
- the update statement
-
update
public int update(@NonNull @NonNull SQLContext context, @NonNull @NonNull UpdateType updateType, @NonNull @NonNull Map<String,SQLElement> setParameters, @NonNull @NonNull SQLElement where) throws SQLException
- Throws:
SQLException
-
update
public int update(@NonNull @NonNull SQLContext context, @NonNull @NonNull Map<String,SQLElement> setParameters, @NonNull @NonNull SQLElement where) throws SQLException
- Throws:
SQLException
-
upsert
public boolean upsert(@NonNull @NonNull SQLContext context, String indexedColumn, @NonNull @NonNull Map<String,Object> values) throws SQLException
Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.- Parameters:
context
- the context to perform the upsert overindexedColumn
- the column used to determine insert or upsertvalues
- the values of the row to be upserted- Returns:
- True if one or more rows were modified.
- Throws:
SQLException
- the sql exception
-
upsert
public boolean upsert(@NonNull @NonNull SQLContext context, List<String> indexedColumns, @NonNull @NonNull Map<String,Object> values) throws SQLException
Perform an upsert on the table using the given context, list of columns to base the upsert on, and values to upserted.- Parameters:
context
- the context to perform the upsert overindexedColumns
- the columns used to determine insert or upsertvalues
- the values of the row to be upserted- Returns:
- True if one or more rows were modified.
- Throws:
SQLException
- the sql exception
-
-