public class ModificationLog extends AbstractDbObject<ModificationLog>
AbstractDbObjects can be logged to a so-called modification log (aka: modlog).
Note: the txId is only valid (> 0) if the db-connection has Db.isLogModificationTxEnabled(),
i.e. begin and commit records are logged as well. If the IdSource of the modlog is
transaction-based, transactions will not overlap in the modlog because obtaining
the id for the modlog is part of the transaction. However, if the idsource is
remote (poolkeeper rmi-client, for example), transactions may overlap!
In such cases the txid is necessary to separate the modlog sequences into
discrete transactions. (see the PoolKeeper project)
| Modifier and Type | Class and Description |
|---|---|
static class |
ModificationLog.ReplayState
Replay state shared between consecutive invocations of
replay(org.tentackle.persist.ModificationLog, org.tentackle.persist.Db). |
| Modifier and Type | Field and Description |
|---|---|
static char |
BEGIN
modification type: begin transaction
|
static String |
CN_MESSAGE
database column name for 'message'.
|
static String |
CN_MODTYPE
database column name for 'modType'.
|
static String |
CN_OBJECTCLASSID
database column name for 'objectClassId'.
|
static String |
CN_OBJECTID
database column name for 'objectId'.
|
static String |
CN_PROCESSED
database column name for 'processed'.
|
static String |
CN_TXID
database column name for 'txId'.
|
static String |
CN_TXNAME
database column name for 'txName'.
|
static String |
CN_USER
database column name for 'user'.
|
static String |
CN_WHEN
database column name for 'when'.
|
static char |
COMMIT
modification type: commit transaction
|
static char |
DELETE
modification type: object deleted
|
static char |
INSERT
modification type: object inserted
|
protected AbstractDbObject<?> |
lazyObject
The
AbstractDbObject the log belongs to. |
protected ParameterString |
messageParameters
Message parameters (lazy)
|
static String |
TABLENAME
the database tablename.
|
static char |
UPDATE
modification type: object updated
|
AN_CLASSID, AN_ID, AN_SERIAL, AN_TABLESERIAL, CN_CLASSID, CN_ID, CN_SERIAL, CN_TABLESERIAL, idComparator, nameComparator, nameIdComparator, preparePending, 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_SYNC, TX_UPDATE_OBJECT, TX_UPDATE_PLAIN, TX_UPDATE_SERIAL, TX_UPDATE_SERIAL_AND_TABLESERIAL, TX_UPDATE_TABLESERIAL| Constructor and Description |
|---|
ModificationLog()
Creates an empty modlog.
|
ModificationLog(AbstractDbObject<P> object,
char modType)
Creates a modification log from an object.
|
ModificationLog(Db db)
Creates an empty modification log for a given db.
|
ModificationLog(Db db,
char modType)
Creates a modification log for a given db and modification type.
|
ModificationLog(ModificationLog template,
char modType)
Creates a modlog from another modlog, but a different type.
|
| Modifier and Type | Method and Description |
|---|---|
void |
canonicalize(Canonicalizer<String> stringCanonicalizer,
Canonicalizer<AbstractDbObject<?>> objectCanonicalizer)
Canonicalize the strings in this modlog.
Used to reduce communication bandwidth when sending larger collections of modlogs via RMI. |
void |
clearLazyObject()
Clears the lazyObject.
|
String |
createInsertSql()
Creates the SQL code for the insert statement.
|
String |
createUpdateSql()
Creates the SQL code for the update statement.
|
int |
deleteByObjectTypeSerial(int objectClassId,
long objectId,
char modType,
long serial)
Deletes by objectclass + objectid + serial less or equal than some value.
Used to remove modlogs already processed for a given object. |
int |
deleteByTxId(long txId)
Deletes a transaction from the modlogs.
|
int |
deleteProcessed(org.tentackle.common.Timestamp processed)
Deletes processed modlogs.
Used to limit the backlog for recovery. |
DbObjectClassVariables<ModificationLog> |
getClassVariables()
Gets the some attributes and variables common to all objects of the same class.
|
AbstractDbObject<?> |
getDbObject()
Gets the object referenced by this ModificationLog.
|
AbstractDbObject<?> |
getDbObject(Db db)
Gets the db object referenced by this ModificationLog.
The object is lazily cached if the given db equals the db of this modlog. |
void |
getFields(ResultSetWrapper rs)
Retrieves the values of all fields.
|
String |
getMessage()
Gets the message.
|
String |
getMessageParameter(String name)
Gets a message parameter.
|
ParameterString |
getMessageParameters()
Gets the message parameters.
|
char |
getModType()
Gets the attribute modType.
|
int |
getObjectClassId()
Gets the attribute objectClassId.
|
long |
getObjectId()
Gets the attribute objectId.
|
org.tentackle.common.Timestamp |
getProcessed()
Gets the attribute processed.
|
long |
getTxId()
Gets the attribute txId.
|
String |
getTxName()
Gets the attribute txName.
|
String |
getUser()
Gets the attribute user.
|
org.tentackle.common.Timestamp |
getWhen()
Gets the attribute when.
|
protected void |
handleMissingObject(ModificationLog modlog,
Db toDb)
Handles the case when an object to replay is not found.
|
boolean |
isDestinationReferringLog()
Returns whether the modlog refers to the PDO at the destination side during replay.
|
boolean |
isLogOfTransaction()
Returns whether this modlog belongs to a transaction.
|
boolean |
isModifyingData()
Check whether this modlog is modifying data.
|
boolean |
isReferencingObject(int objectClassId,
long objectId)
Checks if there are logs for a given object.
|
boolean |
isReferencingUser(String user)
Checks if there are logs for a given user.
|
ModificationLog |
readFromResultSetWrapper(ResultSetWrapper rs)
Reads the values from a result-set into this object.
|
ModificationLog.ReplayState |
replay(ModificationLog.ReplayState state,
List<? extends ModificationLog> modList,
boolean copyLog,
Db toDb)
Replays a list of modlogs within a single transaction.
It will also create new txId if the modlogs are copied. |
void |
replay(ModificationLog modlog,
Db toDb)
Applies a modification to another db.
The method is not static to allow overriding (e.g. |
void |
replayDelete(ModificationLog modlog,
AbstractDbObject<?> object)
Replay a delete.
|
void |
replayFinishModification(ModificationLog modlog,
AbstractDbObject<?> object)
Perform postprocessing for replay.
|
void |
replayInitModification(ModificationLog modlog,
AbstractDbObject<?> object)
Perform preprocessing for replay.
|
void |
replayInsert(ModificationLog modlog,
AbstractDbObject<?> object)
Replay an insert.
|
void |
replayUpdate(ModificationLog modlog,
AbstractDbObject<?> object)
Replay an update.
|
ResultSetWrapper |
resultSetGreaterId(long id)
Selects the first modlog with an ID greater than given ID.
|
ResultSetWrapper |
resultSetSince(org.tentackle.common.Timestamp when)
Selects the first modlog since a given modification time.
|
ResultSetWrapper |
resultSetUnprocessed()
Selects the unprocessed modlogs as a result set.
|
void |
saveObject()
Saves this object.
This is the standard method applications should use to insert or update objects. If the ID is 0, a new ID is obtained and this object inserted. |
List<ModificationLog> |
selectByObject(int objectClassId,
long objectId)
Gets the modlogs for a given object.
|
List<? extends ModificationLog> |
selectByTxId(long txId)
Selects the transaction.
|
List<ModificationLog> |
selectByUserAndType(String user,
char modType)
Selects all logs for a given user and type.
|
ModificationLog |
selectFirstUnprocessed()
Selects the next record to process.
This is the first unprocessed modlog with the lowest ID. |
ModificationLog |
selectFirstUnprocessedGreater(long id)
Selects the next record to process greater than a given id.
|
ModificationLog |
selectGreaterId(long id)
Selects the first modlog with an ID greater than given ID.
|
ModificationLog |
selectLastProcessed()
Selects the last processed modlog.
This is the last processed modlog with the highest ID. |
List<ModificationLog> |
selectUpTo(org.tentackle.common.Timestamp processed)
Selects all modlogs that are unprocessed or modified up to a given timestamp.
Used to replay modlogs after a crash. |
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. |
void |
setMessage(String message)
Sets the message.
|
void |
setMessageParameter(String name,
String value)
Sets a message parameter.
|
void |
setMessageParameters(ParameterString messageParameters)
Sets the message parameters.
|
void |
setModType(char modType)
Sets the attribute modType.
|
void |
setObjectClassId(int objectClassId)
Sets the attribute objectClassId.
|
void |
setObjectId(long objectId)
Sets the attribute objectId.
|
void |
setProcessed(org.tentackle.common.Timestamp processed)
Sets the attribute processed.
|
void |
setSession(Session session)
Sets the logical db connection for this object.
|
void |
setTxId(long txId)
Sets the attribute txId.
|
void |
setTxName(String txName)
Sets the attribute txName.
|
void |
setUser(String user)
Sets the attribute user.
|
void |
setWhen(org.tentackle.common.Timestamp when)
Sets the attribute when.
|
String |
toString()
Gets the default string value.
The default implementation invokes AbstractDbObject.toGenericString(). |
int |
updateByObjectTypeSerial(org.tentackle.common.Timestamp processed,
int objectClassId,
long objectId,
char modType,
long serial)
Updates the processing timestamp by objectclass + objectid + serial less or equal than some value.
Used to mark modlogs already processed for a given object. |
void |
updateDiagnostics(org.tentackle.common.Timestamp processed,
String comment)
Updates the processing timestamp and adds a comment to the message field.
|
void |
updateProcessed(org.tentackle.common.Timestamp processed)
Updates the processing timestamp.
|
int |
updateUnprocessedByTxId(org.tentackle.common.Timestamp processed,
long txId)
Updates the processing timestamp of a transaction for all unprocessed modlogs.
|
acceptPersistenceVisitor, addPropertyChangeListener, addPropertyChangeListener, assertMutable, assertNotNew, assertNotOverloaded, assertNotRemote, assertNumberOfRowsAffected, assertPersistable, assertRemote, assertThisRowAffected, attributesModified, beginTx, clearOnRemoteSave, clone, compareTo, copyToDb, countModification, createAttributesInSnapshot, createDeleteAllSql, createDeleteSql, createDummyUpdateSql, createModificationLog, createPreparedStatement, createPreparedStatement, createSelectAllByIdInnerSql, createSelectAllIdSerialInnerSql, createSelectAllInnerSql, createSelectExpiredTableSerials1Sql, createSelectExpiredTableSerials2Sql, createSelectIdInnerSql, createSelectMaxIdSql, createSelectMaxTableSerialSql, createSelectSerialSql, createSelectSql, createSqlUpdate, createUpdateSerialAndTableSerialSql, createUpdateSerialSql, deleteImpl, deleteObject, deletePlain, deleteReferencedRelations, deleteReferencingRelations, differsPersisted, dummyUpdate, equals, finishModification, finishNotUpdated, firePropertyChange, getBackend, getClassBaseName, getClassId, getColumnCount, getExpirationBacklog, getExpiredTableSerials, getId, getIdSource, getImmutableLoggingLevel, getModificationCount, getModificationLog, getPreparedStatement, getPreparedStatement, getPropertyChangeListeners, getPropertyChangeListeners, getRemoteDelegate, getSerial, getSession, getSessionHolder, getTableName, getTableSerial, hashCode, initModification, insertImpl, insertObject, insertPlain, isCountingModification, isDeleted, isEntity, isIdValid, isImmutable, isLoggingModification, isModified, isNew, isOverloadable, isPersistable, isReferenced, isRemovable, isSessionImmutable, isStatementAlwaysPrepared, isTableSerialProvided, isTracked, isUpdateNecessary, isUpdatingSerialEvenIfNotModified, isVirgin, loadLazyReferences, logModification, markDeleted, newId, newInstance, newInstance, newInstance, persistObject, prepareDelete, prepareSave, prepareSetFields, reloadLockedObject, reloadObject, removeAllPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener, reserveId, resultAllIdSerial, resultAllObjects, revertAttributesToSnapshot, saveReferencedRelations, saveReferencingRelations, selectAllIdSerial, selectAllObjects, selectExpiredTableSerials, selectExpiredTableSerials, selectLockedObject, selectMaxId, selectMaxTableSerial, selectNextObject, selectObject, selectSerial, setClassId, setId, setImmutable, setImmutableLoggingLevel, setModificationLog, setModified, setOverloadable, setSerial, setSessionHolder, setSessionImmutable, setStatementAlwaysPrepared, setTableSerial, toGenericString, toIdString, unmarkDeleted, updateImpl, updateObject, updatePlain, updateSerial, updateSerialAndTableSerialpublic static final String TABLENAME
public static final char BEGIN
public static final char COMMIT
public static final char INSERT
public static final char UPDATE
public static final char DELETE
public static final String CN_OBJECTID
public static final String CN_OBJECTCLASSID
public static final String CN_TXID
public static final String CN_TXNAME
public static final String CN_MODTYPE
public static final String CN_WHEN
public static final String CN_USER
public static final String CN_MESSAGE
public static final String CN_PROCESSED
protected AbstractDbObject<?> lazyObject
AbstractDbObject the log belongs to. null = unknown. Speeds up getDbObject(org.tentackle.persist.Db)
in distributed applications (see the poolkeeper framework).
If the lazyObject is a PersistentObject, it's getPdo() method will hold the PDO.
protected ParameterString messageParameters
public ModificationLog(Db db)
db - the database connectionpublic ModificationLog(Db db, char modType)
db - the database connectionmodType - is the modification type (BEGIN or COMMIT)public ModificationLog(AbstractDbObject<P> object, char modType)
P - the logged object typeobject - is the logged objectmodType - is the modification type (INSERT, UPDATE...)public ModificationLog(ModificationLog template, char modType)
template - the modlog templatemodType - is the modification type (INSERT, UPDATE...)public ModificationLog()
Class.newInstance().public void getFields(ResultSetWrapper rs)
AbstractDbObjectgetFields in class AbstractDbObject<ModificationLog>rs - the result setpublic int setFields(PreparedStatementWrapper st)
AbstractDbObjectPreparedStatementWrapper from the object's attributes.setFields in class AbstractDbObject<ModificationLog>st - the statementpublic String createInsertSql()
AbstractDbObjectcreateInsertSql in class AbstractDbObject<ModificationLog>public String createUpdateSql()
AbstractDbObjectcreateUpdateSql in class AbstractDbObject<ModificationLog>public long getObjectId()
public void setObjectId(long objectId)
objectId - object idpublic int getObjectClassId()
public void setObjectClassId(int objectClassId)
objectClassId - object class idpublic long getTxId()
public void setTxId(long txId)
txId - transaction id (optional)public String getTxName()
public void setTxName(String txName)
txName - transaction name (optional)public char getModType()
public void setModType(char modType)
modType - modification typepublic org.tentackle.common.Timestamp getWhen()
public void setWhen(org.tentackle.common.Timestamp when)
when - time of eventpublic String getUser()
public void setUser(String user)
user - name of userpublic org.tentackle.common.Timestamp getProcessed()
public void setProcessed(org.tentackle.common.Timestamp processed)
processed - processing timepublic void canonicalize(Canonicalizer<String> stringCanonicalizer, Canonicalizer<AbstractDbObject<?>> objectCanonicalizer)
stringCanonicalizer - the canonicalizer for the strings, null if noneobjectCanonicalizer - the canonicalizer for the lazy object, null if nonepublic void setSession(Session session)
setSession in interface SessionDependablesetSession in class AbstractDbObject<ModificationLog>session - the db sessionpublic void clearLazyObject()
public ModificationLog readFromResultSetWrapper(ResultSetWrapper rs)
AbstractDbObjectreadFromResultSetWrapper in class AbstractDbObject<ModificationLog>rs - is the result set (wrapper)public boolean isModifyingData()
public boolean isLogOfTransaction()
public boolean isDestinationReferringLog()
public void saveObject()
Overridden to check for deferred logging.
saveObject in class AbstractDbObject<ModificationLog>public ParameterString getMessageParameters() throws ParseException
ParseException - if paramaters are malformedpublic void setMessageParameters(ParameterString messageParameters)
Updates the message field as well.
messageParameters - the message paramaterspublic String getMessageParameter(String name) throws ParseException
name - the parameter's nameParseException - if parsing the message failedpublic void setMessageParameter(String name, String value) throws ParseException
Updates the message field as well.
name - the parameter's namevalue - the parameter's valueParseException - if parsing the message failedpublic String toString()
AbstractDbObjectAbstractDbObject.toGenericString().toString in class AbstractDbObject<ModificationLog>public AbstractDbObject<?> getDbObject(Db db)
If the returned object is a PersistentObject,
it's getPdo() (or pdo()) method will point to the PDO.
Otherwise it's a low level AbstractDbObject.
db - is the db-connection from which to load the object.public AbstractDbObject<?> getDbObject()
If the returned object is a PersistentObject,
it's getPdo() (or pdo()) method will point to the PDO.
Otherwise it's a low level AbstractDbObject.
public ModificationLog selectFirstUnprocessed()
public ResultSetWrapper resultSetUnprocessed()
public ModificationLog selectFirstUnprocessedGreater(long id)
id - the modlog idpublic ResultSetWrapper resultSetSince(org.tentackle.common.Timestamp when)
when - the starting modification timepublic ModificationLog selectGreaterId(long id)
id - the given IDpublic ResultSetWrapper resultSetGreaterId(long id)
id - the given IDpublic ModificationLog selectLastProcessed()
public List<ModificationLog> selectByObject(int objectClassId, long objectId)
objectClassId - the object's class IDobjectId - the object's IDpublic List<ModificationLog> selectByUserAndType(String user, char modType)
user - the usernamemodType - the modlog typepublic boolean isReferencingUser(String user)
user - the user namepublic boolean isReferencingObject(int objectClassId,
long objectId)
objectClassId - the object's class IDobjectId - the object's IDpublic int updateByObjectTypeSerial(org.tentackle.common.Timestamp processed,
int objectClassId,
long objectId,
char modType,
long serial)
processed - the new processing timestampobjectClassId - the object class IDobjectId - the object idmodType - the modification typeserial - the object serialpublic int deleteByObjectTypeSerial(int objectClassId,
long objectId,
char modType,
long serial)
objectClassId - the object class IDobjectId - the object idmodType - the modification typeserial - the object serialpublic List<? extends ModificationLog> selectByTxId(long txId)
txId - the transaction idpublic int updateUnprocessedByTxId(org.tentackle.common.Timestamp processed,
long txId)
processed - the new processing timestamp, null to set unprocessedtxId - the transaction idpublic int deleteByTxId(long txId)
txId - the transaction idpublic int deleteProcessed(org.tentackle.common.Timestamp processed)
Note: does not honour any transaction boundaries, so the first already processed transaction may be incomplete.
processed - the maximum processing datepublic List<ModificationLog> selectUpTo(org.tentackle.common.Timestamp processed)
processed - the minimum processing date, null = allpublic void updateProcessed(org.tentackle.common.Timestamp processed)
processed - the processing timestamp, null to mark unprocessedpublic void updateDiagnostics(org.tentackle.common.Timestamp processed,
String comment)
throws ParseException
processed - the processing timestamp, null to mark unprocessedcomment - the comment to add to the message, null if noneParseException - if message does not contain a valid parameter stringpublic DbObjectClassVariables<ModificationLog> getClassVariables()
AbstractDbObjectDbObjectClassVariables.getClassVariables in class AbstractDbObject<ModificationLog>@Persistent(value="optional informational or error message") public String getMessage()
@Persistent(value="optional informational or error message") public void setMessage(String message)
The lazy messageParameters are cleared.
message - optional informational or error messagepublic void replay(ModificationLog modlog, Db toDb)
The modlog to replay is passed as an argument because the replaying modlog is used to replay a list of modlogs and may perform some housekeeping and maintain state.
modlog - the modification log to replaytoDb - the db the logs will be applied topublic void replayInitModification(ModificationLog modlog, AbstractDbObject<?> object)
modlog - the modification logobject - the object to insertpublic void replayFinishModification(ModificationLog modlog, AbstractDbObject<?> object)
modlog - the modification logobject - the object to insertpublic void replayInsert(ModificationLog modlog, AbstractDbObject<?> object)
modlog - the modification logobject - the object to insertpublic void replayUpdate(ModificationLog modlog, AbstractDbObject<?> object)
modlog - the modification logobject - the object to updatepublic void replayDelete(ModificationLog modlog, AbstractDbObject<?> object)
modlog - the modification logobject - the object to deletepublic ModificationLog.ReplayState replay(ModificationLog.ReplayState state, List<? extends ModificationLog> modList, boolean copyLog, Db toDb)
There may be several consecutive invocations within the same transaction. This allows some feedback during long running large modlog-lists.
state - the state of the preceeding invocation, never nullmodList - the list of log objects from the source dbcopyLog - true to copy the logs as welltoDb - the db the logs will be applied toPersistenceException - if replay failed and transacation rolled backprotected void handleMissingObject(ModificationLog modlog, Db toDb)
modlog - the original modlogtoDb - the destination dbCopyright © 2016 Krake Softwaretechnik. All rights reserved.