public interface Table<P extends Persistent>
| Modifier and Type | Method and Description |
|---|---|
Column<?> |
addColumnAndCommit(ColumnInfo infoP)
|
void |
addListener(TableListener listener)
Add a
TableListener to this Table. |
void |
appendWhereClause(StringBuffer clause,
Persistent persistent)
Append an SQL logical expression to the given buffer to match rows
according to criteria represented by the given object.
|
CachedCount |
cachedCount() |
CachedCount |
cachedCount(Persistent criteria) |
CachedCount |
cachedCount(Persistent criteria,
boolean includeDeleted,
boolean excludeUnselectable)
A mechanism for caching a record count.
|
CachedCount |
cachedCount(String whereClause)
A mechanism for caching a record count.
|
CachedCount |
cachedCount(String whereClause,
boolean includeDeleted)
A mechanism for caching a record count.
|
CachedCount |
cachedCount(String whereClause,
boolean includeDeleted,
boolean excludeUnselectable)
A mechanism for caching a record count.
|
CachedExists |
cachedExists(String whereClause)
A mechanism for caching an existance.
|
CachedSelection<P> |
cachedSelection(String whereClause,
String orderByClause)
A mechanism for caching a selection of records.
|
Field<?> |
cachedSelectionField(String whereClause,
String orderByClause,
boolean nullable,
Integer selectedTroid,
String nameP)
Make up a Field object whose possible values are a selected
subset of the records in the table.
|
RestrictedReferencePoemType<?> |
cachedSelectionType(String whereClause,
String orderByClause,
boolean nullable)
A mechanism for caching a record count.
|
Column<Capability> |
canDeleteColumn() |
Column<Capability> |
canReadColumn() |
Column<Capability> |
canSelectColumn() |
Column<Capability> |
canWriteColumn() |
void |
clearColumnInfoCaches()
Clear caches.
|
String |
cnfWhereClause(Enumeration<P> persistents) |
String |
cnfWhereClause(Enumeration<P> persistents,
boolean includeDeleted,
boolean excludeUnselectable)
Return a Conjunctive Normal Form (CNF) where clause.
|
Enumeration<Column<?>> |
columns()
All the table's columns.
|
Column<?> |
columnWithColumnInfoID(int columnInfoID) |
int |
count() |
int |
count(String whereClause)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
int |
count(String whereClause,
boolean includeDeleted)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
int |
count(String whereClause,
boolean includeDeleted,
boolean excludeUnselectable)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
String |
countSQL(String whereClause) |
String |
countSQL(String fromClause,
String whereClause,
boolean includeDeleted,
boolean excludeUnselectable)
Return an SQL statement to count rows put together from the arguments.
|
Persistent |
create(Initialiser initialiser)
Create a new object (record) in the table.
|
void |
create(Persistent p)
Write a new row containing the given object.
|
void |
createTableInfo()
Create the (possibly overridden) TableInfo if it has not yet been created.
|
void |
dbAddConstraints()
Constraints are not used in POEM, but you might want to use them if
exporting the db or using schema visualisation tools.
|
void |
dbModifyStructure(String sql)
Use this for DDL statements, ie those which alter the structure of the db.
|
Integer |
defaultCacheLimit() |
String |
defaultCategory() |
String |
defaultDescription() |
String |
defaultDisplayName() |
int |
defaultDisplayOrder() |
String |
defaultOrderByClause()
If the troidColumn has yet to be set then returns an empty string.
|
boolean |
defaultRememberAllTroids() |
void |
defineColumn(Column<?> column)
Don't call this in your application code.
|
void |
delete_unsafe(String whereClause)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
void |
delete(Integer troid,
PoemTransaction transaction)
The Transaction cannot be null, as this is trapped in
#deleteLock(SessionToken).
|
void |
deleteColumnAndCommit(ColumnInfo columnInfo) |
Column<Boolean> |
deletedColumn() |
Column<?> |
displayColumn()
The table's primary display column, the Troid column if not set.
|
Enumeration<Column<?>> |
displayColumns(DisplayLevel level)
Return columns at a display level in display order.
|
int |
displayColumnsCount(DisplayLevel level) |
void |
dump()
Print information about the structure of the table to stdout.
|
void |
dump(PrintStream ps)
Print information to PrintStream.
|
void |
dumpCacheAnalysis()
Print some diagnostic information about the contents and consistency of
POEM's cache for this table to stderr.
|
boolean |
exists(Persistent persistent) |
boolean |
exists(String whereClause)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
int |
extrasCount()
The number of `extra' (non-DSD-defined) columns in the table.
|
Persistent |
firstSelection(String whereClause)
Get an object satisfying the where clause.
|
Cache.Info |
getCacheInfo() |
Capability |
getCanCreate()
The capability required for creating records in the table.
|
TableCategory |
getCategory()
The category of this table.
|
Column<?> |
getColumn(String nameP)
The table's column with a given name.
|
List<Column<?>> |
getColumns()
A list of all the table's columns.
|
int |
getColumnsCount() |
Database |
getDatabase()
The database to which the table is attached.
|
String |
getDbmsTableType() |
Capability |
getDefaultCanDelete()
The capability required for deleting records in the table, unless
overridden in the record itself.
|
Capability |
getDefaultCanRead()
The capability required for reading records from the table, unless
overridden in the record itself.
|
Capability |
getDefaultCanWrite()
The capability required for updating records in the table, unless
overridden in the record itself.
|
String |
getDescription()
A brief description of the table's function.
|
Enumeration<Column<?>> |
getDetailDisplayColumns()
The table's columns for detailed display in display order.
|
int |
getDetailDisplayColumnsCount() |
String |
getDisplayName()
The human-readable name of the table.
|
TableInfo |
getInfo() |
int |
getMostRecentTroid() |
String |
getName()
The table's programmatic name.
|
int |
getNextExtrasIndex() |
Persistent |
getObject(int troid)
The object from the table with a given troid.
|
P |
getObject(Integer troid)
The object from the table with a given troid.
|
Enumeration<Column<?>> |
getRecordDisplayColumns()
The table's columns designated for display in a record, in display order.
|
int |
getRecordDisplayColumnsCount() |
Enumeration<Column<?>> |
getSearchCriterionColumns()
The table's columns designated for use as search criteria, in display
order.
|
int |
getSearchCriterionColumnsCount() |
Enumeration<Column<?>> |
getSummaryDisplayColumns()
The table's columns designated for display in a record summary, in display
order.
|
int |
getSummaryDisplayColumnsCount() |
TableInfo |
getTableInfo() |
void |
init()
Initialise the table.
|
void |
invalidateTransactionStuffs()
When deleting a table and used in tests.
|
void |
load(PoemTransaction transaction,
Persistent persistent) |
Persistent |
newPersistent() |
void |
notifyColumnInfo(ColumnInfo infoP)
Clears columnInfo caches, normally a no-op.
|
void |
notifyTouched(PoemTransaction transaction,
Persistent persistent)
Notify the table that one if its records is about to be changed in a
transaction.
|
void |
postInitialise()
Do stuff immediately after table initialisation.
|
Column<?> |
primaryCriterionColumn()
In a similar manner to the primary display column, each table can have
one primary criterion column.
|
String |
quotedName() |
void |
readLock()
Lock this record.
|
Enumeration<P> |
referencesTo(Persistent object)
All the objects in the table which refer to a given object.
|
Enumeration<Column<?>> |
referencesTo(Table<?> table)
All the columns in the table which refer to the given table.
|
void |
rememberAllTroids(boolean flag) |
Enumeration<P> |
selection()
All the objects in the table.
|
Enumeration<P> |
selection(Persistent criteria)
Return a selection of rows given an exemplar.
|
Enumeration<P> |
selection(Persistent criteria,
String orderByClause)
Return a selection of rows given arguments specifying a query.
|
Enumeration<P> |
selection(Persistent criteria,
String orderByClause,
boolean includeDeleted,
boolean excludeUnselectable)
Return a selection of rows given arguments specifying a query.
|
Enumeration<P> |
selection(String whereClause)
A SELECTion of objects from the table meeting given criteria.
|
Enumeration<P> |
selection(String whereClause,
String orderByClause,
boolean includeDeleted)
A SELECTion of objects from the table meeting given criteria,
possibly including those flagged as deleted.
|
String |
selectionSQL(String fromClause,
String whereClause,
String orderByClause,
boolean includeDeleted,
boolean excludeUnselectable)
The from clause has been added as an argument because it is
inextricably linked to the when clause, but the default is
quotedName(). |
long |
serial(PoemTransaction transaction) |
void |
setCacheLimit(Integer limit) |
void |
setDisplayColumn(Column<?> column) |
void |
setSearchColumn(Column<?> column) |
void |
setTableInfo(TableInfo tableInfo) |
Integer |
tableInfoID()
The troid (id) of the table's entry in the tableinfo
table.
|
String |
toString()
A concise string to stand in for the table.
|
void |
trimCache(int maxSize) |
Column<Integer> |
troidColumn()
The table's troid column.
|
Integer |
troidFor(Persistent persistent) |
Enumeration<Integer> |
troidSelection(Persistent criteria,
String orderByClause,
boolean includeDeleted,
boolean excludeUnselectable,
PoemTransaction transaction) |
Enumeration<Integer> |
troidSelection(String whereClause,
String orderByClause,
boolean includeDeleted)
A SELECTion of troids of objects from the table meeting given
criteria.
|
Enumeration<Integer> |
troidSelection(String whereClause,
String orderByClause,
boolean includeDeleted,
PoemTransaction transaction)
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.
|
void |
uncache()
Invalidate table cache.
|
void |
unifyWithColumnInfo()
Match columnInfo with this Table's columns.
|
void |
unifyWithDB(ResultSet colDescs,
String primaryKey)
Unify the JDBC description of this tables columns with the
meta data held in the
TableInfo |
void |
unifyWithMetadata(ResultSet tableDescriptions)
Unify SQL REMARKS with table.description.
|
String |
whereClause(Persistent criteria)
Return an SQL WHERE clause to select rows that match the non-null
fields of the given object.
|
String |
whereClause(Persistent criteria,
boolean includeDeleted,
boolean excludeUnselectable)
Return an SQL WHERE clause to select rows using the given object
as a selection criteria and optionally deleted rows or those
included rows the user is not capable of selecting.
|
void |
writeDown(PoemTransaction transaction,
Persistent p) |
Database getDatabase()
void init()
void postInitialise()
This base method clears the column info caches and adds a listener to the column info table to maintain the caches.
It may be overridden to perform other actions. For example to ensure required rows exist in tables that define numeric ID's for codes.
void createTableInfo()
String getName()
Dbms.melatiName(String)String quotedName()
String getDisplayName()
String getDescription()
TableCategory getCategory()
Integer tableInfoID()
Column<?> getColumn(String nameP) throws NoSuchColumnPoemException
nameP - name of column to getNoSuchColumnPoemException - if there is no column with that nameEnumeration<Column<?>> columns()
Columnint getColumnsCount()
Column<?> columnWithColumnInfoID(int columnInfoID)
columnInfoID - the Id for the Column tableColumn<Integer> troidColumn()
getObject(Integer)Column<?> displayColumn()
ReferencePoemType._stringOfCooked(java.lang.Object, org.melati.poem.PoemLocale, int),
DisplayLevel.primaryvoid setDisplayColumn(Column<?> column)
column - the display column to setColumn<?> primaryCriterionColumn()
The Primary Criterion is the main grouping field of the table, ie the most important non-unique type field.
For example the Primary Criterion for a User table might be Nationality.
Searchabilityvoid setSearchColumn(Column<?> column)
column - the search column to setString defaultOrderByClause()
void clearColumnInfoCaches()
void notifyColumnInfo(ColumnInfo infoP)
infoP - the possibly null ColumnInfo meta-data persistentEnumeration<Column<?>> displayColumns(DisplayLevel level)
level - the DisplayLevel to selectint displayColumnsCount(DisplayLevel level)
level - the DisplayLevel to selectEnumeration<Column<?>> getDetailDisplayColumns()
Column,
displayColumns(org.melati.poem.DisplayLevel),
DisplayLevel.detailint getDetailDisplayColumnsCount()
Enumeration<Column<?>> getRecordDisplayColumns()
Column,
displayColumns(org.melati.poem.DisplayLevel),
DisplayLevel.recordint getRecordDisplayColumnsCount()
Enumeration<Column<?>> getSummaryDisplayColumns()
Column,
displayColumns(org.melati.poem.DisplayLevel),
DisplayLevel.summaryint getSummaryDisplayColumnsCount()
Enumeration<Column<?>> getSearchCriterionColumns()
Columnint getSearchCriterionColumnsCount()
void dbModifyStructure(String sql) throws StructuralModificationFailedPoemException
sql - the SQL DDL statement to executeStructuralModificationFailedPoemExceptionvoid dbAddConstraints()
void invalidateTransactionStuffs()
void load(PoemTransaction transaction, Persistent persistent)
transaction - possibly null if working with the committed transactionpersistent - the Persistent to loadvoid delete(Integer troid, PoemTransaction transaction)
troid - id of row to deletetransaction - a non-null transactionvoid writeDown(PoemTransaction transaction, Persistent p)
transaction - our PoemTransactionp - the Persistent to writevoid uncache()
void trimCache(int maxSize)
maxSize - new maximum sizeCache.Info getCacheInfo()
void addListener(TableListener listener)
TableListener to this Table.void notifyTouched(PoemTransaction transaction, Persistent persistent)
transaction - the transaction in which the change will be madepersistent - the record to be changedlong serial(PoemTransaction transaction)
void readLock()
P getObject(Integer troid) throws NoSuchRowPoemException
troid - Every record (object) in a POEM database must have a
troid (table row ID, or table-unique non-nullable
integer primary key), often but not necessarily called
id, so that it can be conveniently `named' for
retrieval by this method.NoSuchRowPoemException - if there is no row in the table with the given troidPersistable.getTroid()Persistent getObject(int troid) throws NoSuchRowPoemException
troid - the table row idNoSuchRowPoemException - if not foundgetObject(Integer)String selectionSQL(String fromClause, String whereClause, String orderByClause, boolean includeDeleted, boolean excludeUnselectable)
quotedName().
It is the programmer's responsibility to ensure that the where clause
is suitable for the target DBMS.fromClause - Comma separated list of table names or null for default.whereClause - SQL fragmentorderByClause - Comma separated listincludeDeleted - Flag as to whether to include soft deleted recordsexcludeUnselectable - Whether to append unselectable exclusion SQL
TODO Should work within some kind of limitEnumeration<Integer> troidSelection(String whereClause, String orderByClause, boolean includeDeleted, PoemTransaction transaction)
Enumeration of Troids satisfying the criteria.Enumeration<Integer> troidSelection(Persistent criteria, String orderByClause, boolean includeDeleted, boolean excludeUnselectable, PoemTransaction transaction)
criteria - Represents selection criteria possibly on joined tablestransaction - A transaction or null for
PoemThread.transaction()troidSelection(String, String, boolean, org.melati.poem.PoemTransaction)void rememberAllTroids(boolean flag)
flag - whether to remember or forgetvoid setCacheLimit(Integer limit)
limit - the limit to setEnumeration<Integer> troidSelection(String whereClause, String orderByClause, boolean includeDeleted) throws SQLPoemException
whereClause - an SQL snippetorderByClause - an SQL snippetincludeDeleted - whether to include deleted records, if anySQLPoemExceptiongetObject(Integer),
selection(String, String, boolean)Enumeration<P> selection() throws SQLPoemException
SQLPoemExceptionSelectable.selection()Enumeration<P> selection(String whereClause) throws SQLPoemException
whereClause - SQL SELECTion criteria for the search:
the part that should appear after the
WHERE keywordSQLPoemExceptionColumn.selectionWhereEq(Object)Persistent firstSelection(String whereClause)
whereClause - SQL SELECTion criteria for the search:
the part that should appear after the
WHERE keywordEnumeration<P> selection(String whereClause, String orderByClause, boolean includeDeleted) throws SQLPoemException
includeDeleted - whether to return objects flagged as deleted
(ignored if the table doesn't have a
deleted column)SQLPoemExceptionselection(String)Enumeration<P> selection(Persistent criteria) throws SQLPoemException
criteria - Represents selection criteria possibly on joined tablesSQLPoemExceptionselection(String, String, boolean)Enumeration<P> selection(Persistent criteria, String orderByClause) throws SQLPoemException
criteria - Represents selection criteria possibly on joined tablesorderByClause - Comma separated listSQLPoemExceptionselection(String, String, boolean)Enumeration<P> selection(Persistent criteria, String orderByClause, boolean includeDeleted, boolean excludeUnselectable) throws SQLPoemException
criteria - Represents selection criteria possibly on joined tablesorderByClause - Comma separated listexcludeUnselectable - Whether to append unselectable exclusion SQLSQLPoemExceptionselection(String, String, boolean)String countSQL(String whereClause)
whereClause - the SQL fragment to count the results ofString countSQL(String fromClause, String whereClause, boolean includeDeleted, boolean excludeUnselectable)
fromClause - Comma separated list of table namesint count(String whereClause, boolean includeDeleted, boolean excludeUnselectable) throws SQLPoemException
SQLPoemExceptionint count(String whereClause, boolean includeDeleted) throws SQLPoemException
SQLPoemExceptionint count(String whereClause) throws SQLPoemException
SQLPoemExceptionint count() throws SQLPoemException
SQLPoemExceptionboolean exists(String whereClause) throws SQLPoemException
whereClause - the SQL criteriaSQLPoemExceptionboolean exists(Persistent persistent)
persistent - a Persistent with some fields filled invoid appendWhereClause(StringBuffer clause, Persistent persistent)
This default selects rows for which the non-null fields in the given object match, but subtypes may add other criteria.
The column names are now qualified with the table name so that subtypes can append elements of a join but there is no filtering by canselect columns. TODO Add mechanism for searching for Nulls (that would be query constructs as per SQL parse tree, but efferent not afferent)
String whereClause(Persistent criteria)
This does not filter out any rows with a capability the user does not have in a canselect column, nor did it ever filter out rows deleted according to a "deleted" column. But the caller usually gets a second chance to do both.
String whereClause(Persistent criteria, boolean includeDeleted, boolean excludeUnselectable)
This is currently implemented in terms of
appendWhereClause(StringBuffer, org.melati.poem.Persistent).
String cnfWhereClause(Enumeration<P> persistents)
cnfWhereClause(java.util.Enumeration, boolean, boolean),
whereClause(org.melati.poem.Persistent)String cnfWhereClause(Enumeration<P> persistents, boolean includeDeleted, boolean excludeUnselectable)
Enumeration<P> referencesTo(Persistent object)
It is not guaranteed to be quick to execute!
Enumeration<Column<?>> referencesTo(Table<?> table)
table - the table to count the references withinint getMostRecentTroid()
Integer troidFor(Persistent persistent)
persistent - unused parameter, but might be needed in another troid schemavoid create(Persistent p) throws AccessPoemException, ValidationPoemException, InitialisationPoemException
The given object will be assigned the next troid and its internal state will also be modified.
InitialisationPoemException - The object failed validation
(currently one of its field values failed).AccessPoemExceptionValidationPoemExceptionPersistent create(Initialiser initialiser) throws AccessPoemException, ValidationPoemException, InitialisationPoemException
initialiser - A piece of code for setting the new object's
initial values. You'll probably want to define
it as an anonymous class.AccessPoemException - if initialiser provokes one during its work (which
is unlikely, since POEM's standard checks are disabled
while it runs)ValidationPoemException - if initialiser provokes one during its workInitialisationPoemException - if the object is left by initialiser in a state in
which not all of its fields have legal values, or in which
the calling thread would not be allowed write access to the
object under its AccessToken---i.e. you
can't create objects you wouldn't be allowed to write to.Initialiser.init(Persistent),
PoemThread.accessToken(),
getCanCreate()Persistent newPersistent()
void delete_unsafe(String whereClause)
whereClause - the criteriaint extrasCount()
Capability getDefaultCanRead()
Capability getDefaultCanWrite()
Capability required to write a
Persistent, if anyCapability getDefaultCanDelete()
Capability required to delete a
Persistent, if anyCapability getCanCreate()
create(Initialiser)Column<Capability> canReadColumn()
Column<Capability> canSelectColumn()
Column<Capability> canWriteColumn()
Column<Capability> canDeleteColumn()
Column<?> addColumnAndCommit(ColumnInfo infoP) throws PoemException
infoP - the meta data about the ColumnPoemExceptionvoid deleteColumnAndCommit(ColumnInfo columnInfo) throws PoemException
columnInfo - metadata about the column to delete, which is itself deletedPoemExceptionString toString()
toString in class ObjectObject.toString()void dumpCacheAnalysis()
void dump()
void dump(PrintStream ps)
ps - PrintStream to dump toCachedSelection<P> cachedSelection(String whereClause, String orderByClause)
whereClause - raw SQL selection clause appropriate for this DBMSorderByClause - which field to order by or nullCachedCount cachedCount(String whereClause, boolean includeDeleted)
whereClause - raw SQL selection clause appropriate for this DBMSincludeDeleted - whether to include soft deleted recordsCachedCount cachedCount(String whereClause, boolean includeDeleted, boolean excludeUnselectable)
whereClause - raw SQL selection clause appropriate for this DBMSincludeDeleted - whether to include soft deleted recordsexcludeUnselectable - whether to exclude columns which cannot be selectedCachedCount cachedCount(Persistent criteria, boolean includeDeleted, boolean excludeUnselectable)
criteria - a Persistent with selection fields filledincludeDeleted - whether to include soft deleted recordsexcludeUnselectable - whether to exclude columns which cannot be selectedCachedCount cachedCount(Persistent criteria)
criteria - a Persistent to extract where clause fromCachedCount cachedCount(String whereClause)
whereClause - raw SQL selection clause appropriate for this DBMSCachedCount cachedCount()
CachedExists cachedExists(String whereClause)
whereClause - raw SQL selection clause appropriate for this DBMSRestrictedReferencePoemType<?> cachedSelectionType(String whereClause, String orderByClause, boolean nullable)
whereClause - raw SQL selection clause appropriate for this DBMSorderByClause - raw SQL order clause appropriate for this DBMSnullable - whether the ReferencePoemType is nullableRestrictedReferencePoemTypeField<?> cachedSelectionField(String whereClause, String orderByClause, boolean nullable, Integer selectedTroid, String nameP)
context.put("greens",
melati.getDatabase().getCustomerTable().cachedSelectionField(
"colour = 'green'", null, true, null, "greens"));
and this in your template
The list of member records is implicitly cached---permanently, and however big it turns out to be. So don't go mad with this. It is recomputed on demand if the contents of the table are changed. The whereClause and orderByClause you pass in are checked to see if you have asked for the same list before, so however many times you call this method, you should only trigger actual SELECTs when the table contents have changed. The list is also transaction-safe, in that it will always reflect the state of affairs within your transaction even if you haven't done a commit. It is the programmer's responsibility to ensure that the where clause is suitable for the target DBMS.Select a customer: $ml.input($greens)
whereClause - an SQL expression (the bit after the
SELECT ... WHERE) for picking
out the records you wantorderByClause - a comma-separated list of column names which
determine the order in which the records are
presented; if this is null, the
displayorderpriority attributes of the
table's columns determine the ordernullable - whether to allow a blank NULL option
as the first possibilityselectedTroid - the troid of the record to which the
SELECT field should initially be setnameP - the HTML name attribute of the field,
i.e.
<SELECT NAME=name>void defineColumn(Column<?> column) throws DuplicateColumnNamePoemException, DuplicateTroidColumnPoemException, DuplicateDeletedColumnPoemException
int getNextExtrasIndex()
void setTableInfo(TableInfo tableInfo)
tableInfo - the TableInfo to setString getDbmsTableType()
void unifyWithColumnInfo()
throws PoemException
PoemExceptionvoid unifyWithMetadata(ResultSet tableDescriptions) throws SQLException
tableDescriptions - a JDBC ResultSet with cursor at current rowSQLExceptionvoid unifyWithDB(ResultSet colDescs, String primaryKey) throws PoemException
TableInfocolDescs - a JDBC ResultSet describing the columns with cursor at current rowprimaryKey - name of primary key columnPoemExceptionString defaultDisplayName()
String defaultDescription()
int defaultDisplayOrder()
Integer defaultCacheLimit()
boolean defaultRememberAllTroids()
String defaultCategory()
Copyright © 2000–2021 PanEris. All rights reserved.