|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Table
A table.
Method Summary | |
---|---|
Column |
addColumnAndCommit(ColumnInfo infoP)
Add a Column to the database and the TableInfo table. |
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(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 |
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 |
canDeleteColumn()
|
Column |
canReadColumn()
|
Column |
canSelectColumn()
|
Column |
canWriteColumn()
|
void |
clearColumnInfoCaches()
Clear caches. |
String |
cnfWhereClause(Enumeration<Persistent> persistents)
|
String |
cnfWhereClause(Enumeration<Persistent> 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. |
String |
defaultOrderByClause()
If the troidColumn has yet to be set then returns an empty string. |
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 |
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. |
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. |
String |
getDsdName()
Public method used in DSD.wm. |
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. |
Persistent |
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<Persistent> |
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<Persistent> |
selection()
All the objects in the table. |
Enumeration<Persistent> |
selection(Persistent criteria)
Return a selection of rows given an exemplar. |
Enumeration<Persistent> |
selection(Persistent criteria,
String orderByClause)
Return a selection of rows given arguments specifying a query. |
Enumeration<Persistent> |
selection(Persistent criteria,
String orderByClause,
boolean includeDeleted,
boolean excludeUnselectable)
Return a selection of rows given arguments specifying a query. |
Enumeration<Persistent> |
selection(String whereClause)
A SELECTion of objects from the table meeting given criteria. |
Enumeration<Persistent> |
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 |
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)
Unify the JDBC description of this table with the meta data held in the TableInfo |
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)
|
Method Detail |
---|
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.
notifyColumnInfo(ColumnInfo)
,
clearColumnInfoCaches()
void createTableInfo()
String getName()
Dbms.melatiName(String)
String quotedName()
String getDisplayName()
String getDescription()
TableCategory getCategory()
TableInfo getInfo()
TableInfo
for this tableInteger tableInfoID()
Column getColumn(String nameP) throws NoSuchColumnPoemException
nameP
- name of column to get
NoSuchColumnPoemException
- if there is no column with that nameEnumeration<Column> columns()
Column
int getColumnsCount()
Column columnWithColumnInfoID(int columnInfoID)
columnInfoID
-
Column troidColumn()
getObject(Integer)
Column deletedColumn()
Column displayColumn()
ReferencePoemType._stringOfCooked(java.lang.Object, org.melati.poem.PoemLocale, int)
,
DisplayLevel.primary
void 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.
Searchability
void 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 select
int displayColumnsCount(DisplayLevel level)
level
- the DisplayLevel
to select
Enumeration<Column> getDetailDisplayColumns()
Column
,
displayColumns(org.melati.poem.DisplayLevel)
,
DisplayLevel.detail
int getDetailDisplayColumnsCount()
Enumeration<Column> getRecordDisplayColumns()
Column
,
displayColumns(org.melati.poem.DisplayLevel)
,
DisplayLevel.record
int getRecordDisplayColumnsCount()
Enumeration<Column> getSummaryDisplayColumns()
Column
,
displayColumns(org.melati.poem.DisplayLevel)
,
DisplayLevel.summary
int getSummaryDisplayColumnsCount()
Enumeration<Column> getSearchCriterionColumns()
Column
int getSearchCriterionColumnsCount()
void dbModifyStructure(String sql) throws StructuralModificationFailedPoemException
sql
- the SQL DDL statement to execute
StructuralModificationFailedPoemException
void 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()
Persistent 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 id
NoSuchRowPoemException
- 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 limit
Enumeration<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 any
SQLPoemException
getObject(Integer)
,
selection(String, String, boolean)
Enumeration<Persistent> selection() throws SQLPoemException
SQLPoemException
Selectable.selection()
Enumeration<Persistent> selection(String whereClause) throws SQLPoemException
whereClause
- SQL SELECTion criteria for the search:
the part that should appear after the
WHERE keyword
SQLPoemException
Column.selectionWhereEq(Object)
Persistent firstSelection(String whereClause)
whereClause
- SQL SELECTion criteria for the search:
the part that should appear after the
WHERE keyword
Enumeration<Persistent> 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)
SQLPoemException
selection(String)
Enumeration<Persistent> selection(Persistent criteria) throws SQLPoemException
criteria
- Represents selection criteria possibly on joined tables
SQLPoemException
selection(String, String, boolean)
Enumeration<Persistent> selection(Persistent criteria, String orderByClause) throws SQLPoemException
criteria
- Represents selection criteria possibly on joined tablesorderByClause
- Comma separated list
SQLPoemException
selection(String, String, boolean)
Enumeration<Persistent> 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 SQL
SQLPoemException
selection(String, String, boolean)
String countSQL(String whereClause)
whereClause
-
String countSQL(String fromClause, String whereClause, boolean includeDeleted, boolean excludeUnselectable)
fromClause
- Comma separated list of table names
int count(String whereClause, boolean includeDeleted, boolean excludeUnselectable) throws SQLPoemException
SQLPoemException
int count(String whereClause, boolean includeDeleted) throws SQLPoemException
SQLPoemException
int count(String whereClause) throws SQLPoemException
SQLPoemException
int count() throws SQLPoemException
SQLPoemException
boolean exists(String whereClause) throws SQLPoemException
whereClause
- the SQL criteria
SQLPoemException
boolean exists(Persistent persistent)
persistent
- a Persistent
with some fields filled in
void 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.
notifyColumnInfo(org.melati.poem.ColumnInfo)
,
clearColumnInfoCaches()
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<Persistent> persistents)
cnfWhereClause(java.util.Enumeration, boolean, boolean)
,
whereClause(org.melati.poem.Persistent)
String cnfWhereClause(Enumeration<Persistent> persistents, boolean includeDeleted, boolean excludeUnselectable)
Enumeration<Persistent> referencesTo(Persistent object)
It is not guaranteed to be quick to execute!
Enumeration<Column> referencesTo(Table table)
table
-
int getMostRecentTroid()
Integer troidFor(Persistent persistent)
persistent
- unused parameter, but might be needed in another troid schema
void 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).
AccessPoemException
ValidationPoemException
Persistent 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 work
InitialisationPoemException
- 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 canReadColumn()
Column canSelectColumn()
Column canWriteColumn()
Column canDeleteColumn()
Column addColumnAndCommit(ColumnInfo infoP) throws PoemException
Column
to the database and the TableInfo
table.
infoP
- the meta data about the Column
PoemException
void deleteColumnAndCommit(ColumnInfo columnInfo) throws PoemException
columnInfo
- metadata about the column to delete, which is itself deleted
PoemException
String toString()
toString
in class Object
Object.toString()
void dumpCacheAnalysis()
void dump()
void dump(PrintStream ps)
ps
- PrintStream to dump toCachedSelection cachedSelection(String whereClause, String orderByClause)
whereClause
- raw SQL selection clause appropriate for this DBMSorderByClause
- which field to order by or null
CachedCount cachedCount(String whereClause, boolean includeDeleted)
whereClause
- raw SQL selection clause appropriate for this DBMSincludeDeleted
- whether to include soft deleted records
CachedCount 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 selected
CachedCount 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 selected
CachedCount cachedCount(Persistent criteria)
criteria
- a Persistent to extract where clause from
CachedCount cachedCount(String whereClause)
whereClause
- raw SQL selection clause appropriate for this DBMS
CachedExists cachedExists(String whereClause)
whereClause
- raw SQL selection clause appropriate for this DBMS
RestrictedReferencePoemType 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 nullable
RestrictedReferencePoemType
Field cachedSelectionField(String whereClause, String orderByClause, boolean nullable, Integer selectedTroid, String nameP)
and this in your templatecontext.put("greens", melati.getDatabase().getCustomerTable().cachedSelectionField( "colour = 'green'", null, true, null, "greens"));
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
DuplicateColumnNamePoemException
DuplicateTroidColumnPoemException
DuplicateDeletedColumnPoemException
int getNextExtrasIndex()
void setTableInfo(TableInfo tableInfo)
tableInfo
- the TableInfo to setTableInfo getTableInfo()
TableInfo
for this table.String getDbmsTableType()
String getDsdName()
defaultDisplayName()
above is overwritten.
void unifyWithColumnInfo() throws PoemException
PoemException
void unifyWithDB(ResultSet colDescs) throws PoemException
TableInfo
colDescs
- a JDBC ResultSet
describing the columns
PoemException
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |