public final class HubTable
extends Object
Table and column names are not case sensitive and are limited to NAME_MAX characters in length. Subscription names are case sensitive and are not limited in length.
Table data selections are sorted according to the key column values. When you use integer values as key values, the sorting is text value based so values such as 1, 11, and 111 come before 2, 22, 222, etc. The sorted order is a natural aspect of how the data is organized in the table data structures and not the result of an additional sorting step. There is a boolean option, setSortFlag(boolean) which can be set to have the data sorted properly in selection results. The flag is only relevant if one or more of the key columns is a numeric data type.
Accepting the default ordering of numeric key column data without additional sorting is appropriate when wanting to conserve processing for tables with thousands of data rows. Here are some suggestions to work with the default ordering of data:
Modifier and Type | Field and Description |
---|---|
Object |
clientData
for public client use - a reference to anything you want associated with the table
|
static int |
NAME_MAX
A very long name can be used but
only the first 31 chars of the name are significant.
|
Constructor and Description |
---|
HubTable(String name,
HubTableRow tr)
Construct a HubTable instance and add it to the Datahub.
|
Modifier and Type | Method and Description |
---|---|
String |
createStatement()
Return an SQL create statement for the table schema
|
boolean |
deleteRow(HubTableRow row)
Delete a row from the table.
|
String |
deleteStatement(HubTableRow row)
Build an SQL delete statement for deleting a row.
|
int |
deleteWhere(String whereClause)
Delete all table rows matching an SQL selection clause.
|
boolean |
drop()
Delete the table.
|
String |
dropStatement()
Obtain an SQL drop statement for deleting the table.
|
static String |
errMsg(int e)
Obtain an error message string for an error code returned by
the HubTable methods insert(), update(), and delete().
|
HubTableColumn |
getColumn(String Name)
Lookup a table column by name.
|
int |
getColumnCount()
Obtain the count of table columns.
|
String |
getColumnNameList()
Obtain a whitespace separated list of all the column names.
|
String[] |
getColumnNames()
Obtain the column names as an array
|
String |
getKeyNameList()
Obtain a whitespace separated list of the key column names.
|
String[] |
getKeyNames()
Obtain the key column names as an array
|
String |
getName()
Obtain the table name which is possibly truncated to the maximum length, NAME_MAX,
but preserves the original case passed to the constructor.
|
int |
getRowCount()
Obtain the count of table rows.
|
TableRowSchema[] |
getSchema()
Obtain the table schema as data rows
|
String |
getSchemaList()
Obtain the table schema formatted as an SQL selection statement result
select {table schema} {{Column Name} Key Type} {{Column Name}} colCount {} data
|
String |
getSchemaList(boolean addEmptyDescriptionColumn)
Obtain the table schema formatted as an SQL selection statement result
optionally with an empty Description column added.
|
Boolean |
getSortFlag()
The sortFlag controls whether additional sorting is performed on selection results
to sequence numeric data in numeric order.
|
int |
getSubscriptionCount()
Obtain the count of subscriptions to the table.
|
TableRowSub[] |
getSubscriptions()
Obtain an array of the current table subscriptions.
|
String |
getSubscriptionsList()
Obtain the current subscriptions as an SQL selection list.
|
int |
insert(HubTableRow tr)
Add a new row to the table.
|
String |
insertStatement(HubTableRow row,
HubTableColumn[] col)
Provide an insert statement encompassing some or all of the column
values in the provided row.
|
static HubTable |
load(String tablename)
A counterpart to save() - load a table that was saved on the file system.
|
static void |
main(String[] args)
Create java files for the table row types used internally by the com.hume.datahub
package.
|
static String |
nameID(String Name)
Return the case-insensitive, length-limited name used for lookup.
|
int |
put(HubTableRow tr)
The put method combines the action of an insert of a new row or an update if a
row with the same primary composite key value already exists.
|
String |
save()
Save the table as sql statements using tablename.tab in the working directory
|
HubTableRow[] |
select(String whereClause)
Find all table rows matching a search condition.
|
HubTableRow[] |
selectAll()
Select all rows from the table.
|
HubTableRow |
selectPCK(String key)
Direct lookup of a single row using the primary composite key value.
|
Boolean |
setDefaultSorting()
A call to set the default sorting behavior.
|
Boolean |
setSortFlag(boolean wantSorting)
The sortFlag controls whether additional sorting is performed on selection results
to sequence numeric data in numeric order.
|
HubTableWin |
showDataWin()
Show the Datahub GUI table data window for the table.
|
HubTableWin |
showSchemaWin()
Show the Datahub GUI table schema window.
|
HubTableWin |
showSubsWin()
Show the Datahub GUI table subscription window.
|
void |
subscriptionAddJava(SubscriberItf receiver,
String subname,
String[] subcols,
boolean wantInsert,
boolean wantUpdate,
boolean wantDelete,
boolean wantDrop,
boolean wantSync,
String whereClause,
Object argdata)
Open a table subscription that provides notifications as Java instance data.
|
boolean |
subscriptionAddJavaSync(SubscriberItf receiver,
String subname)
Open a table subscription that provides all current and future data as Java instance data.
|
void |
subscriptionAddSql(SubscriberSqlItf sqlReceiver,
String subname,
String[] subcols,
boolean wantCreate,
boolean wantInsert,
boolean wantUpdate,
boolean wantSelect,
boolean wantDelete,
boolean wantDrop,
boolean wantSync,
String whereClause,
Object argdata)
Open a table subscription that provides SQL statement notifications
|
boolean |
subscriptionAddSqlSync(SubscriberSqlItf sqlReceiver,
String subname)
Open a table subscription that provides the table create statement, and all current
and future data.
|
boolean |
subscriptionClose(String name)
Close a subscription to the table.
|
int |
update(HubTableRow tr)
Update a single table row where the key is not changing.
|
int |
update(HubTableRow oldRow,
HubTableRow newRow)
Update a table row where the key may be changing.
|
int |
update(String key,
HubTableRow tr)
Update the single row identified by the key.
|
void |
usageJavaWhereClause(StringBuilder sb)
Return an example Java code where clause with the key column names and concatenating
java variable names for their values
|
void |
usageSqlWhereClause(StringBuilder sb)
Provide an example where clause with the key column names and concatenating
constants for their values
|
boolean |
usesSortFlag()
If the table uses numeric keys, sorting may be desirable to sequence numeric
data in numeric order instead of text sort order which is the default that does
not require additional processing.
|
String |
write(String pathname,
boolean overWrite)
Write the table data to a file as SQL statements.
|
String |
writeCsv(String pathname)
Export the table as comma separated value data.
|
public Object clientData
public static final int NAME_MAX
public HubTable(String name, HubTableRow tr)
The table name is not case sensitive and is limited to 31 characters in length. It must begin with a letter and include only letters, digits, and the underscore. If the name contains improper characters, the table will be given the literal name invalidName.
name
- table nametr
- a model table row used for class information and cloningSqlException
public String createStatement()
public boolean deleteRow(HubTableRow row)
row
- the key value of the input row specifies which row is deletedpublic String deleteStatement(HubTableRow row)
row
- public int deleteWhere(String whereClause) throws SqlException
whereClause
- an SQL selection expressionSqlException
- if the where clause syntax is improperpublic boolean drop()
public String dropStatement()
public static String errMsg(int e)
e
- public HubTableColumn getColumn(String Name)
Name
- public int getColumnCount()
public String getColumnNameList()
public String[] getColumnNames()
public String getKeyNameList()
public String[] getKeyNames()
public String getName()
public int getRowCount()
public TableRowSchema[] getSchema()
public String getSchemaList()
public String getSchemaList(boolean addEmptyDescriptionColumn)
public Boolean getSortFlag()
public int getSubscriptionCount()
public TableRowSub[] getSubscriptions()
public String getSubscriptionsList()
public int insert(HubTableRow tr)
tr
- a tablerow that is an instance of the row class passed to the
table constructor.public String insertStatement(HubTableRow row, HubTableColumn[] col)
row
- input table rowcol
- an array of the desired columns or null for all columnspublic static HubTable load(String tablename) throws SqlException
tablename
- SqlException
public static void main(String[] args)
args
- ignoredpublic static String nameID(String Name)
Name
- table or column name identifierpublic int put(HubTableRow tr)
tr
- input table rowpublic String save() throws SqlException
SqlException
public HubTableRow[] select(String whereClause) throws SqlException
whereClause
- SqlException
public HubTableRow[] selectAll()
public HubTableRow selectPCK(String key)
key
- value is computed from row.getKey() or from
TableRowClass.keyOf(key value arguments);
Our example application creates convenience methods that use this method and cast the result to a specific table row class.
public static HubTable abcd = new HubTable("abcd", new TableRowAbcd()); public static TableRowAbcd getAbcdRow(String a) { String keyValue = TableRowAbcd.keyOf(a); return (TableRowAbcd) abcd.selectPCK(keyValue); }The keyOf() method takes the key column values in their sequence order.
public Boolean setDefaultSorting()
public Boolean setSortFlag(boolean wantSorting)
wantSorting
- whether to perform additional sorting of selection resultspublic HubTableWin showDataWin()
public HubTableWin showSchemaWin()
public HubTableWin showSubsWin()
public void subscriptionAddJava(SubscriberItf receiver, String subname, String[] subcols, boolean wantInsert, boolean wantUpdate, boolean wantDelete, boolean wantDrop, boolean wantSync, String whereClause, Object argdata) throws SqlException
receiver
- the receiving objectsubname
- a name for the subscription which is unique for subscriptions to this table.subcols
- null for all columns else an array of column names for the desired table columnswantInsert
- include new rowswantUpdate
- include changed rowswantDelete
- include deleted rowswantDrop
- include deletion of the tablewantSync
- include existing data when the sub is openedwhereClause
- optionally match only selected table changes.argdata
- optional client data passed to the notification callbackSqlException
public boolean subscriptionAddJavaSync(SubscriberItf receiver, String subname)
receiver
- the receiving objectsubname
- a name for the subscription which is unique for subscriptions to this table.public void subscriptionAddSql(SubscriberSqlItf sqlReceiver, String subname, String[] subcols, boolean wantCreate, boolean wantInsert, boolean wantUpdate, boolean wantSelect, boolean wantDelete, boolean wantDrop, boolean wantSync, String whereClause, Object argdata) throws SqlException
sqlReceiver
- the receiving objectsubname
- a name for the subscription which is unique for subscriptions to this table.subcols
- null for all columns else an array of column names for the desired table columnswantCreate
- include table create statementwantInsert
- include new rowswantUpdate
- include changed rowswantSelect
- include unchanged column values in row update notificationswantDelete
- include deleted rowswantDrop
- include deletion of the tablewantSync
- include existing data when the sub is openedwhereClause
- optionally match only selected table changes.argdata
- optional client data passed to the notification callbackSqlException
public boolean subscriptionAddSqlSync(SubscriberSqlItf sqlReceiver, String subname)
sqlReceiver
- the receiving objectsubname
- a name for the subscription which is unique for subscriptions to this table.public boolean subscriptionClose(String name)
public int update(HubTableRow tr)
public int update(HubTableRow oldRow, HubTableRow newRow)
public int update(String key, HubTableRow tr)
key
- row.getKey() value from before the updatetr
- revised table rowpublic void usageJavaWhereClause(StringBuilder sb)
sb
- output text is appended to the passed in StringBuilderpublic void usageSqlWhereClause(StringBuilder sb)
sb
- output text is appended to the bufferpublic boolean usesSortFlag()
public String write(String pathname, boolean overWrite) throws SqlException
pathname
- relative or absolute output file pathnameoverWrite
- whether to allow overwriting an existing output fileSqlException
public String writeCsv(String pathname) throws SqlException
pathname
- relative or absolute output file pathnameSqlException