Package ru.curs.celesta.score
Class BasicTable
- java.lang.Object
-
- ru.curs.celesta.score.NamedElement
-
- ru.curs.celesta.score.GrainElement
-
- ru.curs.celesta.score.DataGrainElement
-
- ru.curs.celesta.score.BasicTable
-
- All Implemented Interfaces:
HasColumns
,TableElement
- Direct Known Subclasses:
ReadOnlyTable
,Table
public abstract class BasicTable extends DataGrainElement implements TableElement
Super class forTable
andReadOnlyTable
that encompasses common logic for both table types.- Since:
- 2019-07-14
- Author:
- Pavel Perminov (packpaul@mail.ru)
-
-
Field Summary
-
Fields inherited from class ru.curs.celesta.score.NamedElement
MAX_IDENTIFIER_LENGTH
-
Fields inherited from interface ru.curs.celesta.score.TableElement
YOU_CANNOT_DROP_A_COLUMN_THAT_BELONGS_TO
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(Column<?> column)
Adds a column to the table.void
finalizePK()
Finalizes the creation of the primary key.Optional<IntegerColumn>
getAutoincrementedColumn()
Returns the integer column with default value provided by a sequence (or empty Optional if such column does not exists).Column<?>
getColumn(String colName)
Returns a column by its name or throws an exception with a message that the column is not found.int
getColumnIndex(String name)
Column index in the list of columns.Map<String,Column<?>>
getColumns()
Unmodified list of table columns.Set<ForeignKey>
getForeignKeys()
Returns a set of foreign keys for the table.List<String>
getImplements()
Returns interfaces that are implemented by the cursor (values of 'implements' property) for this table.Set<Index>
getIndices()
Returns a set of indices for the table.String
getPkConstraintName()
Returns PK constraint name.Map<String,Column<?>>
getPrimaryKey()
Returns unmodified map of primary key columns.boolean
hasMaterializedViews()
Returns true in case there are materialized views built on top of this table.boolean
isAutoUpdate()
Whether autoupdate is on/off.
false
value indicates that the table was created with the option WITH NO STRUCTURE UPDATE and it won't take part in the DB autoupdate.void
removeColumn(Column<?> column)
Removes a column from the table.void
setAutoUpdate(boolean autoUpdate)
Sets or clears the option WITH NO STRUCTURE UPDATE.void
setPK(String... columnNames)
Sets primary key on the table in a form of array of columns.void
setPkConstraintName(String pkConstraintName)
Sets the name of constraint for the primary key.String
toString()
-
Methods inherited from class ru.curs.celesta.score.DataGrainElement
delete
-
Methods inherited from class ru.curs.celesta.score.GrainElement
getGrain, getGrainPart
-
Methods inherited from class ru.curs.celesta.score.NamedElement
equals, getCelestaDoc, getName, getQuotedName, getQuotedNameIfNeeded, hashCode, limitName, limitName, setCelestaDoc
-
Methods inherited from interface ru.curs.celesta.score.TableElement
getGrain, getName, getQuotedName, getQuotedNameIfNeeded, hasPrimeKey
-
-
-
-
Method Detail
-
getColumns
public Map<String,Column<?>> getColumns()
Unmodified list of table columns.- Specified by:
getColumns
in interfaceHasColumns
- Specified by:
getColumns
in interfaceTableElement
-
getColumn
public final Column<?> getColumn(String colName) throws ParseException
Description copied from interface:TableElement
Returns a column by its name or throws an exception with a message that the column is not found.- Specified by:
getColumn
in interfaceTableElement
- Parameters:
colName
- column name- Returns:
- Throws:
ParseException
- if a column with the specified name is not found in the table
-
getPrimaryKey
public final Map<String,Column<?>> getPrimaryKey()
Description copied from interface:TableElement
Returns unmodified map of primary key columns.- Specified by:
getPrimaryKey
in interfaceTableElement
- Returns:
- map of column name -> column
-
addColumn
public void addColumn(Column<?> column) throws ParseException
Adds a column to the table.- Specified by:
addColumn
in interfaceTableElement
- Parameters:
column
- new column- Throws:
ParseException
- if a column with the same name is already defined
-
setPK
public void setPK(String... columnNames) throws ParseException
Sets primary key on the table in a form of array of columns. It is used for dynamic metadata management.- Parameters:
columnNames
- array of columns- Throws:
ParseException
- in case when an empty array is passed in
-
removeColumn
public final void removeColumn(Column<?> column) throws ParseException
Description copied from interface:TableElement
Removes a column from the table.- Specified by:
removeColumn
in interfaceTableElement
- Parameters:
column
- existing column- Throws:
ParseException
- if the column couldn't be removed
-
finalizePK
public void finalizePK() throws ParseException
Finalizes the creation of the primary key.- Throws:
ParseException
- if the primary key is empty.
-
getForeignKeys
public Set<ForeignKey> getForeignKeys()
Returns a set of foreign keys for the table.- Returns:
-
getPkConstraintName
public final String getPkConstraintName()
Description copied from interface:TableElement
Returns PK constraint name.- Specified by:
getPkConstraintName
in interfaceTableElement
- Returns:
-
setPkConstraintName
public void setPkConstraintName(String pkConstraintName) throws ParseException
Sets the name of constraint for the primary key.- Parameters:
pkConstraintName
- PK constraint name- Throws:
ParseException
- incorrect name
-
isAutoUpdate
public boolean isAutoUpdate()
Whether autoupdate is on/off.
false
value indicates that the table was created with the option WITH NO STRUCTURE UPDATE and it won't take part in the DB autoupdate. Default istrue
.- Returns:
-
setAutoUpdate
public void setAutoUpdate(boolean autoUpdate)
Sets or clears the option WITH NO STRUCTURE UPDATE.- Parameters:
autoUpdate
-true
if the table is updated automatically,false
- in the opposite case.
-
getColumnIndex
public final int getColumnIndex(String name)
Description copied from interface:HasColumns
Column index in the list of columns.- Specified by:
getColumnIndex
in interfaceHasColumns
- Parameters:
name
- column name.
-
hasMaterializedViews
public boolean hasMaterializedViews()
Returns true in case there are materialized views built on top of this table.
-
getAutoincrementedColumn
public Optional<IntegerColumn> getAutoincrementedColumn()
Returns the integer column with default value provided by a sequence (or empty Optional if such column does not exists).
-
-