public interface BBjAdminTable extends BBjAdminCommitPropertyWriter, java.io.Serializable
Represents an individual table in a database. The BBjAdminTable contains the properties describing the various parts of the table as well as methods to get the list of available columns, indexes, etc. Note that table definitions can differ from the actual structure of the table's data file so it is important to make sure that the definition matches the data file to eliminate confusion. For example a table definition can contain index definitions that are not actually present on the table's data file. This means that while the table definition says a particular set of columns are indexed, unless those are actually present on the data file, that index is not usable by the SQL engine's optimizer.
There are several ways to make changes to table definitions. One is using the Enterprise Manager. You can also make changes programmatically. The easiest way to change table structure is to use the SQL ALTER TABLE statement. The ALTER TABLE docs can be found here: ALTER TABLE.
ALTER TABLE statements are executed from an SQL tools such as the Enterprise Manager or your JDBC/ODBC program and look something like this:
ALTER TABLE my_table ADD COLUMN my_col VARCHAR(25)
ALTER TABLE my_table DROP COLUMN my_old_col
ALTER TABLE my_table ALTER COLUMN last_name VARCHAR (100)
Note that each ALTER TABLE statement will rewrite the entire data file to adjust the record layout/size so keep that in mind when using ALTER TABLE.
An alternative approach is to use the Admin API. With this method you can make numerous changes to the structure at one time and then only rewrite the data file once. This is more complex but more flexible as well (this is used by the Enterprise Manager). This can be done from a BBj or Java program. There is a handy method to change a table definition using a string template which many may find helpful. Here is a short example to give you an idea of how you could do this in BBj. One thing to keep in mind is that the Admin API gives you the ability to change the table definition without changing the data file, or to change the data file as well. Make sure to use the correct method to get the desired effect. The example below shows how you could add a new column to the CATEGORY table in the ChileCompany database, and also change the size of another column at the same time. You can play around with the ChileCompany DB to get a feel for it. Note the string template. We changed DESC to 130 characters and added NEW_COL at the end:
declare BBjAdminBase admin!
declare BBjAdminDatabase db!
declare BBjAdminTable table!
REM Get a connection to the Admin system and then grab the database object
admin! = BBjAdminFactory.getBBjAdmin("admin","admin123")
db! = admin!.getDatabase("ChileCompany")
REM Get the table instance and change the column definitions.
table! = db!.getTable("CATEGORY")
tmpl$ = "PROD_CAT:C(2),DESC:C(130),COST_METHOD:C(5),COST_ACCOUNT:C(8),SALE_ACCOUNT:C(8),INV_ACCOUNT:C(8),NEW_COL:C(10**)"
table!.setTemplate(tmpl$)
REM This call tells the call to commit() to rewrite the data file. If you don't want
REM to rewrite the data file, set this to 0 (false)
table!.setShouldCommitUpdateDataFile(1)
REM Write your changes and update the data file.
table!.commit()
The easiest way is with SQL using:
CREATE FULLTEXT INDEX ON my_table(col1, col2)
With the Admin API you can do it as well. To use the Admin API use the following example:
api! = BBjAdminFactory.getBBjAdmin("admin", "admin123")
db! = api!.getDatabase("MyDatabase")
table! = db!.getTable("MY_TABLE")
REM Specify the list of columns to include in the FULLTEXT index
indexCols! = api!.createBBjList()
indexCols!.add("COL1")
indexCols!.add("COL2")
table!.setList(BBjAdminTable.FULLTEXT_COLUMNS, indexCols!)
REM Save the table definition which will create the FULLTEXT index. Note, this
REM may take a while if the table large.
table!.commit()
REM Make sure to cleanup the API instance.
api!.release()
Modifier and Type | Interface and Description |
---|---|
static class |
BBjAdminTable.Type
Data file type for the table.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALERT_TYPE |
static java.lang.String |
ANALYZER
Lucene analyzer class to use on the FULLTEXT index if one is present on this table.
|
static java.lang.String |
DATA_FILE
Path to the data file.
|
static java.lang.String |
DATA_FILE_FULL_PATH
Read-only full path to the data file.
|
static java.lang.String |
DESCRIPTION
Description of the table.
|
static java.lang.String |
ENCRYPTION_STRING
File encryption string if this table's data file is encrypted.
|
static java.lang.String |
FILE_PASSWORD
File password to use for this table if it is password protected.
|
static java.lang.String |
FILE_TYPE
File type defined for this table.
|
static int |
FILE_TYPE_DIRECT_SORT
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_DIRECTORY
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_ESQL
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_MKEYED
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_MKEYED_64BIT
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_MKEYED_64BIT_RECOVERABLE
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_MKEYED_RECOVERABLE
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_PROGRAM
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_STRING
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_VKEYED
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_XKEYED
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static int |
FILE_TYPE_XKEYED_RECOVERABLE
Used in conjunction with the FILE_TYPE property indicating the type of file housing the data for the table.
|
static java.lang.String |
FULLTEXT_COLUMNS
List of the columns that make up the FULLTEXT index if one is present.
|
static java.lang.String |
FULLTEXT_INDEX_ENABLED
True if the FULLTEXT index on this table (if there is one) is enabled.
|
static java.lang.String |
KEY_SIZE
Key size if this is a single keyed file or 0 if it is multi-keyed.
|
static java.lang.String |
LAST_ANALYSIS
Date of the last time this table was successfully analyzed.
|
static java.lang.String |
LAST_ANALYSIS_EXCEPTION
If table analysis failed on the table, this is the exception that was generated.
|
static java.lang.String |
MAX_ROW_COUNT
Maximum number of rows allowed in the table's data file or 0 if no limit.
|
static java.lang.String |
NAME
Name of the table.
|
static java.lang.String |
ORIGINAL_NAME
Original name of the table.
|
static java.lang.String |
RECORD_SIZE
Record size of the table's data file.
|
static java.lang.String |
ROW_COUNT
Number of rows in the table.
|
static java.lang.String |
SCHEMA
Schema name for the table.
|
static java.lang.String |
STOPWORDS_LANG
Lucene stopwords language code to use for the FULLTEXT index if one is present on this table.
|
static java.lang.String |
TEMPLATE
String template used to define the table.
|
Modifier and Type | Method and Description |
---|---|
BBjAdminColumn |
createColumn()
Creates a new instance of a BBjAdminColumn on the table.
|
BBjAdminCrossReference |
createCrossReference()
Creates a new instance of a BBjAdminCrossReference (foreign key).
|
BBjAdminIndex |
createIndex()
Creates a new instance of a BBjAdminIndex on the table.
|
BBjAdminColumn |
getColumn(java.lang.String p_column)
Gets an instance of BBjAdminColumn from the table for the specified
column name.
|
BBjAdminList<BBjAdminColumn> |
getColumns()
Get a list of the columns in the table.
|
BBjAdminList<BBjAdminCrossReference> |
getCrossReferences()
Returns a list of the cross references (foreign keys) on this table.
|
BBjAdminList<BBjAdminProperty> |
getDescriptiveProperties()
Used primarily by GUI applications like the Enterprise Manager to dynamically generate
an admin UI.
|
BBjAdminList<BBjAdminIndex> |
getIndexes()
Get a list of the indexes in the table.
|
BBjAdminList<BBjAdminIndex> |
getIndexesFromDataFile()
Derives and returns a list of indexes from the data file associated with this table
even before the table has ever been committed to the database.
|
int |
getMaxColumnValueLength(java.lang.String p_column) |
java.lang.String |
getTemplate()
Get a BBj string template from the column definitions.
|
java.lang.String |
getTemplate(boolean p_detailed)
Get a BBj string template from the column definitions.
|
BBjAdminTriggers |
getTriggers()
Returns the triggers on this table's data file if there are any, or null if there are none.
|
BBjAdminTable.Type |
getType()
Get the data file type of the data file used by the table.
|
void |
rebuildFullTextIndex()
Rebuilds the current FULLTEXT index if one is present.
|
void |
setColumns(BBjAdminList<BBjAdminColumn> p_columns)
Set a new list of columns for this table (not committed).
|
void |
setCrossReferences(BBjAdminList<BBjAdminCrossReference> p_crossReferences)
Sets the list of cross references (foreign keys) on this table.
|
void |
setDescriptiveProperties(BBjAdminList<BBjAdminProperty> p_descriptiveProps)
Used primarily by GUI applications like the Enterprise Manager to dynamically generate
an admin UI.
|
void |
setIndexes(BBjAdminList<BBjAdminIndex> p_indexes)
Set a new list of indexes for this table (not committed).
|
void |
setShouldCommitUpdateDataFile(boolean p_update)
Sets whether a commit should also update/create the data file, or if is should
only make changes to the data dictionary.
|
void |
setTemplate(java.lang.String p_template)
Very powerful, helpful method to set all the column definitions at one time from a
standard BBj string template.
|
boolean |
shouldCommitUpdateDataFile()
Should commit update the data file?
|
void |
shouldCommitUpdateDataFile(boolean p_update)
Deprecated.
|
void |
startAnalysis()
Starts table analysis on this table.
|
getChangedProperties, getClearedProperties, getOriginalProperties
addType, canAddNewProperties, canClear, clear, clearProperties, clearProperty, getReadOnly, hasChanged, isReadOnly, setBoolean, setDouble, setInt, setList, setLong, setProperties, setString, setValue
checkValueEqual, contains, contains, getBoolean, getDouble, getInt, getList, getLong, getProperties, getString, getType, getTypes, getValue
commit, rollback
static final java.lang.String NAME
static final java.lang.String ORIGINAL_NAME
static final java.lang.String DESCRIPTION
static final java.lang.String DATA_FILE
static final java.lang.String DATA_FILE_FULL_PATH
static final java.lang.String TEMPLATE
static final java.lang.String LAST_ANALYSIS
static final java.lang.String LAST_ANALYSIS_EXCEPTION
static final java.lang.String ROW_COUNT
static final java.lang.String SCHEMA
static final java.lang.String FILE_TYPE
static final java.lang.String FILE_PASSWORD
static final java.lang.String ENCRYPTION_STRING
static final java.lang.String ALERT_TYPE
static final java.lang.String KEY_SIZE
static final java.lang.String RECORD_SIZE
static final java.lang.String MAX_ROW_COUNT
static final java.lang.String FULLTEXT_COLUMNS
static final java.lang.String FULLTEXT_INDEX_ENABLED
static final java.lang.String ANALYZER
static final java.lang.String STOPWORDS_LANG
static final int FILE_TYPE_DIRECT_SORT
static final int FILE_TYPE_STRING
static final int FILE_TYPE_PROGRAM
static final int FILE_TYPE_DIRECTORY
static final int FILE_TYPE_MKEYED
static final int FILE_TYPE_MKEYED_RECOVERABLE
static final int FILE_TYPE_MKEYED_64BIT
static final int FILE_TYPE_MKEYED_64BIT_RECOVERABLE
static final int FILE_TYPE_XKEYED
static final int FILE_TYPE_XKEYED_RECOVERABLE
static final int FILE_TYPE_VKEYED
static final int FILE_TYPE_ESQL
boolean shouldCommitUpdateDataFile()
BBjAdminCommitWriter.commit()
method.@Deprecated void shouldCommitUpdateDataFile(boolean p_update)
setShouldCommitUpdateDataFile(boolean)
p_update
- void setShouldCommitUpdateDataFile(boolean p_update)
p_update
- BBjAdminTable.Type getType() throws BBjAdminException
BBjAdminTable.Type
enum.BBjAdminException
java.lang.String getTemplate() throws BBjAdminException
BBjAdminException
java.lang.String getTemplate(boolean p_detailed) throws BBjAdminException
p_detailed
- True if you want the detailed attributes filled in as well.BBjAdminException
void setTemplate(java.lang.String p_template) throws BBjAdminException
p_template
- Standard BBj string template to use to define the columns for
the table.BBjAdminException
BBjAdminList<BBjAdminColumn> getColumns() throws BBjAdminException
BBjAdminCommitWriter.commit()
method to save the changes. Call the
setShouldCommitUpdateDataFile(boolean)
passing in true to have the BBjAdminCommitWriter.commit()
call
update the table's data file structure to match the definitions.BBjAdminColumn
objects that define the table.BBjAdminException
BBjAdminList<BBjAdminCrossReference> getCrossReferences() throws BBjAdminException
BBjAdminCrossReference
objects on this table. This will not return
anything on legacy data dictionaries unless the table is an ESQL table. Enhanced dictionaries
support cross references (foreign keys).BBjAdminException
void setColumns(BBjAdminList<BBjAdminColumn> p_columns) throws BBjAdminException
p_columns
- BBjAdminException
void setCrossReferences(BBjAdminList<BBjAdminCrossReference> p_crossReferences) throws BBjAdminException
p_crossReferences
- BBjAdminException
BBjAdminList<BBjAdminIndex> getIndexes() throws BBjAdminException
getIndexesFromDataFile()
to return the indexes actually present on the table's data file.BBjAdminException
void setIndexes(BBjAdminList<BBjAdminIndex> p_indexes) throws BBjAdminException
p_indexes
- BBjAdminException
BBjAdminIndex createIndex() throws BBjAdminException
getIndexes()
.BBjAdminIndex
created. Make sure to add the returned object to the list returned in
getIndexes()
.BBjAdminException
BBjAdminColumn createColumn() throws BBjAdminException
getColumns()
.BBjAdminColumn
object created.BBjAdminException
BBjAdminCrossReference createCrossReference() throws BBjAdminException
getCrossReferences()
.BBjAdminCrossReference
.BBjAdminException
BBjAdminColumn getColumn(java.lang.String p_column) throws BBjAdminException
p_column
- Name of the column.BBjAdminException
int getMaxColumnValueLength(java.lang.String p_column) throws BBjAdminException
BBjAdminException
void startAnalysis() throws BBjAdminException
BBjAdminException
BBjAdminTriggers getTriggers() throws BBjAdminException
BBjAdminException
BBjAdminList<BBjAdminIndex> getIndexesFromDataFile() throws BBjAdminException
BBjAdminException
BBjAdminList<BBjAdminProperty> getDescriptiveProperties() throws BBjAdminException
BBjAdminException
void setDescriptiveProperties(BBjAdminList<BBjAdminProperty> p_descriptiveProps) throws BBjAdminException
BBjAdminException
void rebuildFullTextIndex() throws BBjAdminException
BBjAdminException