|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.DbObject
org.tentackle.appworx.AppDbObject
org.tentackle.appworx.History
public abstract class History
Class to read and write history records for a given AppDbObject-class. There are two options to run history-based tables:
# usage: makeHistoryRules.shnewtable=h_"$1" echo ' CREATE TABLE' "$newtable" 'AS SELECT * FROM' "$1" 'WHERE ID=-1; ALTER TABLE' "$newtable" 'ADD h_time TIMESTAMP; ALTER TABLE' "$newtable" 'ADD h_user TEXT; ALTER TABLE' "$newtable" 'ADD h_type CHAR(1); CREATE INDEX' "$newtable"_id 'ON' "$newtable" '(id, serial, h_time); GRANT ALL ON' "$newtable" 'TO PUBLIC; CREATE RULE insert_'"$newtable" 'AS ON INSERT TO' "$1" 'DO INSERT INTO' "$newtable" 'VALUES (new.*,current_timestamp,current_user,'"'I'"'); CREATE RULE update_'"$newtable" 'AS ON UPDATE TO' "$1" 'DO INSERT INTO' "$newtable" 'VALUES (new.*,current_timestamp,current_user,'"'U'"'); CREATE RULE delete_'"$newtable" 'AS ON DELETE TO' "$1" 'DO INSERT INTO' "$newtable" 'VALUES (old.*,current_timestamp,current_user,'"'D'"');
public class BlaHistory extends History {
public BlaHistory(Blah blah) {
super(blah);
}
public BlaHistory() {
super();
}
public AppDbObjectClassVariables getAppDbObjectClassVariables() {
return classVariables;
}
private static AppDbObjectClassVariables classVariables =
new AppDbObjectClassVariables(BlaHistory.class, HISTORY_TABLENAME_PREFIX +
Bla.TABLENAME, "History Entry", "History Entries");
}
public boolean allowsHistory() {
return true;
}
public History getHistory() {
return new BlaHistory(this);
}
The wurblet "History" does all that automatically.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.tentackle.db.DbObject |
|---|
DbObject.CopyAllToDbLogger, DbObject.IdComparator<T extends DbObject>, DbObject.NameComparator<T extends DbObject>, DbObject.NameIdComparator<T extends DbObject> |
| Field Summary | |
|---|---|
protected AppDbObject |
appDbObject
|
static String |
FIELD_TIME
database column name for the timestamp when modification took place |
static String |
FIELD_TYPE
database column name for the modification type |
static String |
FIELD_USER
database column name for the user who did the modification |
static String |
HISTORY_TABLENAME_PREFIX
prefix prepended to the table name of history objects |
| Fields inherited from class org.tentackle.appworx.AppDbObject |
|---|
FIELD_EDITEDBY, FIELD_EDITEDEXPIRY, FIELD_EDITEDSINCE, FIELD_NORMTEXT, TX_DELETE_ALL_IN_CONTEXT, TX_SAVE_COPY_IN_CONTEXT, TX_TRANSFER_EDITEDBY, VERIFIED_DUPLICATE |
| Fields inherited from class org.tentackle.db.DbObject |
|---|
BEGIN, COMMIT, DELETE, DELETEALL, FIELD_ID, FIELD_SERIAL, FIELD_TABLESERIAL, idComparator, INSERT, lazyMethodInterval, nameComparator, nameIdComparator, TX_DELETE_LIST, TX_DELETE_MISSING_IN_LIST, TX_DELETE_OBJECT, TX_DUMMY_UPDATE, TX_INSERT_OBJECT, TX_INSERT_PLAIN, TX_SAVE, TX_SAVE_LIST, TX_UPDATE_OBJECT, TX_UPDATE_PLAIN, TX_UPDATE_SERIAL, TX_UPDATE_SERIAL_AND_TABLESERIAL, TX_UPDATE_TABLESERIAL, UPDATE |
| Constructor Summary | |
|---|---|
History()
Creates an empty history object. |
|
History(AppDbObject appDbObject)
Creates a history object. |
|
History(ContextDb db)
Creates an empty history object. |
|
| Method Summary | |
|---|---|
boolean |
createHistoryLog(char type)
Creates a history log for the current object and saves it to the database. The username is taken from the database UserInfo. |
AppDbObject |
getAppDbObject()
Gets the referenced object. |
boolean |
getFields(ResultSetWrapper rs)
Retrieves the values of all fields (all columns of the database table) in the given ResultSetWrapper and stores them in the object's attributes. |
FormTableEntry |
getFormTableEntry()
Gets the table entry for viewing lists of this object in a FormTable.The default implementation returns an AppDbObjectDefaultTableEntry. |
Timestamp |
getTime()
Gets the modification time. |
char |
getType()
Gets the modification type. |
String |
getUser()
Gets the username. |
AppDbObject |
newObject()
Creates an instance of the same class as this object, initialized in the same contextDb. |
int |
prepareDeleteStatement()
Prepares the delete statement (usually the same for all objects) |
int |
prepareInsertStatement()
Prepares the insert statement. |
int |
prepareUpdateStatement()
Prepare the update statement. |
boolean |
readFromResultSetWrapper(ResultSetWrapper rs,
boolean withLinkedObjects)
Reads the values from a result-set into this object. |
AppDbObject |
restoreObjectForSerial(long objectId,
long objectSerial)
Restores an object for a given revision, i.e. |
List<History> |
selectByObjectId(long objectId)
Selects all history objects for a given object id, sorted by time. In order not to confuse the user, suppresses changes on the data not visible to the user. |
int |
setFields(PreparedStatementWrapper st)
Sets the values of all fields (all columns of the database table) in the given PreparedStatementWrapper from the object's attributes. |
String |
toString()
Gets the default string value. The default implementation invokes DbObject.toGenericString(). |
static String |
typeToString(char type)
Converts a modification type to a localized string. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String HISTORY_TABLENAME_PREFIX
public static final String FIELD_TIME
public static final String FIELD_USER
public static final String FIELD_TYPE
protected AppDbObject appDbObject
| Constructor Detail |
|---|
public History(AppDbObject appDbObject)
appDbObject - the database objectpublic History(ContextDb db)
db - the database contextpublic History()
| Method Detail |
|---|
public static String typeToString(char type)
type - the modification type (INSERT, UPDATE or DELETE)
public Timestamp getTime()
public String getUser()
public char getType()
public AppDbObject getAppDbObject()
public AppDbObject newObject()
AppDbObject
newObject in class AppDbObjectpublic List<History> selectByObjectId(long objectId)
objectId - the object ID
public AppDbObject restoreObjectForSerial(long objectId,
long objectSerial)
DbObject.isTxObject()
and DbObject.isUpdatingSerialEvenIfNotModified() return true
as this will force all updated childs of the composite parent to get the serial of the parent.
Important: the method will not load the childs and has to be overwridden to do so (which
depends on the application's semantics).
objectId - the object's IDobjectSerial - the object's revision/serial
public boolean createHistoryLog(char type)
UserInfo.
The time is the current system time.
type - the modification type
public boolean getFields(ResultSetWrapper rs)
DbObjectResultSetWrapper and stores them in the object's attributes.
getFields in class DbObjectrs - the result set
public boolean readFromResultSetWrapper(ResultSetWrapper rs,
boolean withLinkedObjects)
AppDbObjectOverridden due to security check whether reading this object is allowed. If not, false is returned as if reading some values failed.
readFromResultSetWrapper in class AppDbObjectrs - is the result set (wrapper)withLinkedObjects - is true if load linked objects too
public int setFields(PreparedStatementWrapper st)
DbObjectPreparedStatementWrapper from the object's attributes.
setFields in class DbObjectst - the statement
public int prepareInsertStatement()
Overridden to take the sql-string from the AppDbObject and
modify it. This method relies on the special format
of an insert-statement! Make sure to let the insert-statement
be created by the insert-wurblet!!!
prepareInsertStatement in class DbObjectpublic int prepareUpdateStatement()
Invokes the errorhandler because History objects cannot be updated.
prepareUpdateStatement in class DbObjectpublic int prepareDeleteStatement()
Invokes the errorhandler because History objects cannot be deleted.
prepareDeleteStatement in class DbObjectpublic String toString()
DbObjectDbObject.toGenericString().
toString in class DbObjectpublic FormTableEntry getFormTableEntry()
FormTable.AppDbObjectDefaultTableEntry.
Should be overridden in subclasses.
Returns a HistoryTableEntry.
getFormTableEntry in class AppDbObjectAppDbObject.getFormTableName()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||