|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Persistent
The object representing a single table row; this is the PO in POEM!
Instances are also used to represent selection criteria.
Method Summary | |
---|---|
void |
assertCanCreate()
|
void |
assertCanCreate(AccessToken token)
Check that you have create access to the object. |
void |
assertCanDelete()
|
void |
assertCanDelete(AccessToken token)
Check that you have delete access to the object. |
void |
assertCanRead()
|
void |
assertCanRead(AccessToken token)
Check that you have read access to the object. |
void |
assertCanWrite()
|
void |
assertCanWrite(AccessToken token)
Check that you have write access to the object. |
void |
delete_unsafe()
Delete without access checks. |
void |
delete()
Delete this persistent, with default integrity checks, ie disallow deletion if object referred to by others. |
void |
delete(Map<Column,IntegrityFix> integrityFixOfColumn)
Delete the object. |
void |
deleteAndCommit()
Convenience method with default integrity fix. |
void |
deleteAndCommit(Map<Column,IntegrityFix> integrityFixOfColumn)
Delete the object, with even more safety checks for referential integrity. |
String |
displayString()
|
String |
displayString(PoemLocale locale)
Defaults to DateFormat.MEDIUM. |
String |
displayString(PoemLocale locale,
int style)
A string describing the object for the purposes of rendering it in lists presented to the user. |
String |
dump()
|
void |
dump(PrintStream p)
Dump to a PrintStream. |
Persistent |
duplicated()
Create a new object like this one. |
Persistent |
duplicatedFloating()
Create a new persistent like this one, regardless of whether this Persistent has been written to the dbms yet. |
void |
existenceLock()
Lock without actually reading. |
Enumeration<Field> |
fieldsOfColumns(Enumeration<Column> columns)
Create Fields from Columns. |
Object |
getCooked(String name)
The `true value' of one of the object's fields. |
String |
getCookedString(String name,
PoemLocale locale,
int style)
A string representation of the `true value' of one of the object's fields. |
Database |
getDatabase()
|
Enumeration<Field> |
getDetailDisplayFields()
All fields at the detailed display level in display order. |
Field |
getField(String name)
The value of one of the object's fields, wrapped up with type information sufficient for rendering it. |
Enumeration<Field> |
getFields()
The values of all the object's fields, wrapped up with type information sufficient for rendering them. |
Field |
getPrimaryDisplayField()
|
Object |
getRaw(String name)
The `identifying value' of one of the object's fields. |
String |
getRawString(String name)
A string representation of the `identifying value' of one of the object's fields. |
boolean |
getReadable()
|
Enumeration<Field> |
getRecordDisplayFields()
The values of all the object's fields designated for inclusion in full record displays, wrapped up with type information sufficient for rendering them. |
Enumeration<Field> |
getSearchCriterionFields()
|
Enumeration<Field> |
getSummaryDisplayFields()
All fields at the summary display level in display order. |
Table |
getTable()
The Table from which the object comes, complete with metadata. |
boolean |
isDirty()
|
void |
makePersistent()
A convenience method to create this Persistent. |
void |
postEdit(boolean creating)
Optionally called after this instance is edited by a user. |
void |
postInsert()
Called after this persistent is written to the database for the first time. |
void |
postModify()
Called after this persistent is updated and written to the database replacing the existing record it represents. |
void |
postWrite()
Called after this persistent is written to the database on being inserted or modified. |
void |
preEdit()
Optionally called before an instance is edited by the user. |
void |
setCooked(String name,
Object cooked)
Set the `true value' of one of the record's fields. |
void |
setDirty(boolean dirty)
|
void |
setRaw(String name,
Object raw)
Set the `identifying value' of one of the record's fields. |
void |
setRawString(String name,
String string)
Set the `identifying value' of one of the record's fields from a string representation. |
boolean |
statusExistent()
|
boolean |
statusNonexistent()
|
Methods inherited from interface org.melati.poem.Persistable |
---|
getTroid, troid |
Methods inherited from interface org.melati.poem.Treeable |
---|
getChildren, getName |
Method Detail |
---|
boolean statusNonexistent()
boolean statusExistent()
void makePersistent()
Table getTable()
Database getDatabase()
void existenceLock()
void assertCanRead(AccessToken token) throws AccessPoemException
Although this check can in theory be quite time-consuming, in practice this isn't a problem, because the most recent access token for which the check succeeded is cached; repeat accesses from within the same transaction are therefore quick.
Application programmers can override this method to implement their own programmatic access policies. For instance, POEM's own TableInfo class overrides it with an empty method in order to disable all read protection on TableInfo objects. More interestingly, you could implement a check that depends on the values of the object's fields: for example, you could allow read access to an invoice record to its issuing and receiving parties.
token
- the access token on the basis of which readability is
being claimed
AccessPoemException
- if the check failsDatabase.inSession(org.melati.poem.AccessToken, org.melati.poem.PoemTask)
,
JdbcTable.getDefaultCanRead()
void assertCanRead() throws AccessPoemException
AccessPoemException
- if current accessToken does not grant read capabilityboolean getReadable()
assertCanRead()
void assertCanWrite(AccessToken token) throws AccessPoemException
AccessPoemException
assertCanRead()
,
JdbcTable.getDefaultCanWrite()
void assertCanWrite() throws AccessPoemException
AccessPoemException
- if current accessToken does not grant wraite capabilityvoid assertCanDelete(AccessToken token) throws AccessPoemException
AccessPoemException
assertCanRead()
,
JdbcTable.getDefaultCanDelete()
void assertCanDelete() throws AccessPoemException
AccessPoemException
- if current accessToken does not grant delete capabilityvoid assertCanCreate(AccessToken token)
Application programmers can override this method to implement their own programmatic access policies.
assertCanRead()
,
assertCanWrite()
,
JdbcTable.getCanCreate()
void assertCanCreate() throws AccessPoemException
AccessPoemException
- if current accessToken does not grant create capabilityObject getRaw(String name) throws NoSuchColumnPoemException, AccessPoemException
If the field baz is defined in the DSD as part of a table called foo, then the table's records will be represented by an application-specialised subclass of Persistent called Foo which provides a typed getBaz method. So the easiest way to be sure of your types is to predeclare any fields you use in the DSD, use the typed field-access methods, and let the compiler take the strain. When working with generic Persistents, you probably want to use getField.
The value returned is relative to the transaction associated with the calling thread, as set up by Database.inSession. This means that you never see the value of a field change in your transaction because of another transaction's activities, unless you do a PoemThread.commit() or a PoemThread.rollback(). If you need to, you can store a Persistent in a permanent data structure and access it in different sessions over time---or even from concurrently running sessions, though this may slow down access checking; each transaction will see the value it expects.
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have read access to the
object (see assertCanRead)getCooked(java.lang.String)
,
getRawString(java.lang.String)
,
getCookedString(java.lang.String, org.melati.poem.PoemLocale, int)
,
getField(java.lang.String)
,
Database.inSession(org.melati.poem.AccessToken, org.melati.poem.PoemTask)
,
PoemThread.commit()
,
PoemThread.rollback()
,
assertCanRead()
String getRawString(String name) throws AccessPoemException, NoSuchColumnPoemException
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have read access to the
object (see assertCanRead)getCookedString(java.lang.String, org.melati.poem.PoemLocale, int)
,
getRaw(java.lang.String)
,
getCooked(java.lang.String)
,
assertCanRead()
void setRaw(String name, Object raw) throws NoSuchColumnPoemException, AccessPoemException, ValidationPoemException
If the field baz is defined in the DSD as part of a table called foo, then the table's records will be represented by an application-specialised subclass of Persistent called Foo which provides a typed setBaz method. So the easiest way to be sure of your types is to predeclare any fields you use in the DSD, use the typed field-access methods, and let the compiler take the strain. When working with generic Persistents, you probably mean setRawString anyway.
The change you make to the field's value will only be visible to the calling thread, until it successfully completes the task started by Database.inSession, or does an explicit PoemThread.commit(). Up to that point the change can be undone by calling PoemThread.rollback(), and will be undone automatically if the task terminates with an uncaught exception.
In fact, your changes are not written down to the database, even relative to an uncommitted transaction, until it's actually necessary. So multiple calls to setRaw and relatives will not cause multiple SQL UPDATEs to be issued.
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)raw
- The new value for the field: a String,
Boolean, Integer, Double or
Date as appropriate. If the field is a
reference field: an Integer giving the troid
of the referee. If you want to pass referees as actual
Persistents, use setCooked. If you
want to set the field from a string representation
(e.g. typed in by the user), use
setRawString.
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have write access to the
object (see assertCanWrite)
ValidationPoemException
- if raw is not a valid value for the field
(e.g. a string is too long)setCooked(java.lang.String, java.lang.Object)
,
setRawString(java.lang.String, java.lang.String)
,
assertCanWrite()
,
Database.inSession(org.melati.poem.AccessToken, org.melati.poem.PoemTask)
,
PoemThread.commit()
,
PoemThread.rollback()
void setRawString(String name, String string) throws NoSuchColumnPoemException, AccessPoemException, ParsingPoemException, ValidationPoemException
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)string
- A string that will be parsed to obtain the new value
for the field. If it's a reference field, this should
be a decimal representation of the referee's troid. If
you want to set fields to values defined by appropriate
Java types, use setRaw or setCooked.
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have write access to the
object (see assertCanWrite)
ParsingPoemException
- if string doesn't parse as a value of the
appropriate type
ValidationPoemException
- if string parses to an invalid value for the field
(e.g. it's too wide)setRaw(java.lang.String, java.lang.Object)
,
setCooked(java.lang.String, java.lang.Object)
,
assertCanWrite()
Object getCooked(String name) throws NoSuchColumnPoemException, AccessPoemException
The value returned is relative to the transaction associated with the calling thread, as set up by Database.inSession: see the remarks made about getRaw.
The easiest way to be sure of your types is to predeclare any fields you use in the DSD, or use getField. Again, see the remarks made about getRaw.
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have read access to the
object (see assertCanRead)getRaw(java.lang.String)
,
getRawString(java.lang.String)
,
getCookedString(java.lang.String, org.melati.poem.PoemLocale, int)
,
getField(java.lang.String)
,
assertCanRead()
String getCookedString(String name, PoemLocale locale, int style) throws NoSuchColumnPoemException, AccessPoemException
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)locale
- A PoemLocale eg PoemLocale.HEREstyle
- A date format
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have read access to the
object (see assertCanRead)getRawString(java.lang.String)
,
getRaw(java.lang.String)
,
getCooked(java.lang.String)
,
assertCanRead()
,
displayString(org.melati.poem.PoemLocale, int)
void setCooked(String name, Object cooked) throws NoSuchColumnPoemException, ValidationPoemException, AccessPoemException
name
- the name of the field (i.e. the name of the
column in the RDBMS and DSD)cooked
- the new value for the field: a String,
Boolean, Integer, Double,
Date or, for a reference field, a
Persistent. If you want to pass referees as
troids, use setRaw. If you want to set the
field from a string representation (e.g. typed
in by the user), use setRawString.
NoSuchColumnPoemException
- if the field named doesn't exist
AccessPoemException
- if the calling thread doesn't have write access to the
object (see assertCanWrite)
ValidationPoemException
- if cooked is not a valid value for the field
(e.g. a string is too long)setRaw(java.lang.String, java.lang.Object)
,
setRawString(java.lang.String, java.lang.String)
,
assertCanWrite()
Field getField(String name) throws NoSuchColumnPoemException, AccessPoemException
If the field baz is defined in the DSD as part of a table called foo, then the table's records will be represented by an application-specialised subclass of Persistent called Foo which provides a getBazField method.
name
- column name
NoSuchColumnPoemException
- if there is no column of that name
AccessPoemException
- if the current AccessToken does not grant access capabilityEnumeration<Field> fieldsOfColumns(Enumeration<Column> columns)
columns
- an Enumeration of Columns
Enumeration<Field> getFields()
Enumeration<Field> getRecordDisplayFields()
DisplayLevel.record
Enumeration<Field> getDetailDisplayFields()
DisplayLevel.detail
Enumeration<Field> getSummaryDisplayFields()
DisplayLevel.summary
Enumeration<Field> getSearchCriterionFields()
Field getPrimaryDisplayField()
void delete(Map<Column,IntegrityFix> integrityFixOfColumn)
integrityFixOfColumn
- A map from Column
to IntegrityFix
which says
how referential integrity is to be maintained for each column
that can refer to the object being deleted. May be
null to mean `empty'. If a column isn't mentioned,
the default behaviour for the column is used. (The default
is StandardIntegrityFix.prevent
.)IntegrityFix
,
PoemThread.commit()
void delete_unsafe()
void delete()
void deleteAndCommit(Map<Column,IntegrityFix> integrityFixOfColumn) throws AccessPoemException, DeletionIntegrityPoemException
delete(java.util.Map)
, but waits for exclusive access to the
database before doing the delete, and commits the session immediately
afterwards.
This used to be the only deletion entry point allowed, but
now we ensure that the possible race condition involving new
pointers to the deleted object created during the deletion process is
covered. So it is recommended to use delete(java.util.Map)
unless you really want this functionality.
AccessPoemException
DeletionIntegrityPoemException
void deleteAndCommit() throws AccessPoemException, DeletionIntegrityPoemException
AccessPoemException
DeletionIntegrityPoemException
Persistent duplicated() throws AccessPoemException
AccessPoemException
Persistent duplicatedFloating() throws AccessPoemException
AccessPoemException
String displayString(PoemLocale locale, int style) throws AccessPoemException
locale
- our localestyle
- a DateFormat (only applicable to those rare objects whose summary column is a date)
AccessPoemException
- if current User does not have viewing Capability
String displayString(PoemLocale locale) throws AccessPoemException
AccessPoemException
- if current User does not have viewing Capability
String displayString() throws AccessPoemException
AccessPoemException
- if current User does not have viewing Capability
String dump()
void dump(PrintStream p)
p
- the PrintStream to dump tovoid postWrite()
This is called after postInsert() or postModify().
This is low level and there is a limit to what you can do here without causing infinitely recursive calls.
void postInsert()
This is low level and there is a limit to what you can do here without causing infinitely recursive calls.
void postModify()
Not called when it is written to the database for the first time.
This is low level and there is a limit to what you can do here without causing infinitely recursive calls.
void preEdit()
See postEdit(boolean)
for additional comments.
However, it is not called when a newly created row is
edited.
void postEdit(boolean creating)
Unlike postModify()
and postInsert()
this
is not called during write down but can be called by
applications after individual field edits by the user
have been reflected in the instance.
It can be be overridden to enforce data model constraints such as validity of columns relative to other columns. These will be enforced when the admin system is used.
This is a higher level method than postModify()
so is less likely to lead to infinite recursion or other
such problems.
Sorry for the lack of signature consistency with the lower level methods but I got tired of having to call my own application specific common method.
creating
- Are we in the process of creating a new record?boolean isDirty()
void setDirty(boolean dirty)
dirty
- the dirty to set
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |