|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.DbObject
org.tentackle.db.ModificationLog
public class ModificationLog
Logging for object modifications.
Modifications to DbObjects can be logged to a so-called modification log (aka: modlog).
Most applications will use the modlog for asynchroneous database coupling.
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)
| 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 | |
|---|---|
static String |
FIELD_ERRORCODE
database column name for errorCode |
static String |
FIELD_EXTRAID
database column name for extraId |
static String |
FIELD_MESSAGE
database column name for message |
static String |
FIELD_MODTYPE
database column name for modType |
static String |
FIELD_OBJECTCLASS
database column name for objectClass |
static String |
FIELD_OBJECTID
database column name for objectId |
static String |
FIELD_TXID
database column name for txId |
static String |
FIELD_TXNAME
database column name for txName |
static String |
FIELD_USER
database column name for user |
static String |
FIELD_WHEN
database column name for when |
protected DbObject |
lazyObject
The DbObject the log belongs to. |
static int |
LENGTH_OBJECTCLASS
maximum number of characters for objectClass |
static int |
LENGTH_TXNAME
maximum number of characters for txName |
static int |
LENGTH_USER
maximum number of characters for user |
static String |
modlogClassname
The classname of the global modlog. |
static String |
TABLENAME
database tablename |
| 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 | |
|---|---|
ModificationLog()
Creates an empty modlog. |
|
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(DbObject object,
char modType)
Creates a modification log from an object. |
|
ModificationLog(ModificationLog template,
char modType)
Creates a modlog from another modlog, but a different type. |
|
| Method Summary | |
|---|---|
void |
clearLazyObject()
Clears the lazyObject. |
DbObjectClassVariables |
getDbObjectClassVariables()
Gets the some attributes and variables common to all objects of the same class. |
int |
getErrorCode()
Gets the db attribute errorCode |
long |
getExtraId()
Gets the db attribute extraId |
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. |
String |
getMessage()
Gets the db attribute message |
char |
getModType()
Gets the db attribute modType |
DbObject |
getObject()
Gets the object referenced by this ModificationLog. |
DbObject |
getObject(Db db)
Gets the object referenced by this ModificationLog. The object is lazily cached if the given db equals the db of this modlog. |
String |
getObjectClass()
Gets the db attribute objectClass |
long |
getObjectId()
Gets the db attribute objectId |
long |
getTxId()
Gets the db attribute txId |
String |
getTxName()
Gets the db attribute txName |
String |
getUser()
Gets the db attribute user |
Timestamp |
getWhen()
Gets the db attribute when |
static ModificationLog |
instance()
Gets the global modification logger object. |
static boolean |
isReferencingObject(Db db,
String objectClass,
long objectId)
Checks if there are logs for a given object. |
boolean |
isReferencingObject(String objectClass,
long objectId)
Checks whether references exist. |
static boolean |
isReferencingUser(Db db,
String user)
Checks if there are logs for a given object. |
boolean |
isReferencingUser(String user)
Checks whether references exist. |
int |
prepareInsertStatement()
Prepares the insert statement. |
int |
prepareUpdateStatement()
Prepare the update statement. |
long |
replay(List<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. |
boolean |
replay(ModificationLog modlog,
Db toDb)
Applies a modification to another db. The method is not static to allow overriding (e.g. |
boolean |
save()
Saves this object. This is the standard method applications should use to insert or update objects. |
List<ModificationLog> |
selectByObject(String objectClass,
long objectId)
Gets the modlogs for a given object. |
ModificationLog |
selectFirst()
Selects the next record to process, i.e. |
void |
setDb(Db db)
Sets the logical db connection for this object. |
void |
setErrorCode(int errorCode)
Sets the db attribute errorCode |
void |
setExtraId(long extraId)
Sets the db attribute extraId |
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 db attribute message |
void |
setTxId(long txId)
Sets the db attribute txId |
void |
setTxName(String txName)
Sets the db attribute txName |
String |
toString()
Just for logging. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String TABLENAME
protected DbObject lazyObject
DbObject the log belongs to. null = unknown. Speeds up getObject(org.tentackle.db.Db)
in distributed applications (see the poolkeeper framework).
public static final String FIELD_OBJECTID
public static final String FIELD_OBJECTCLASS
public static final String FIELD_TXID
public static final String FIELD_TXNAME
public static final String FIELD_MODTYPE
public static final String FIELD_WHEN
public static final String FIELD_USER
public static final String FIELD_ERRORCODE
public static final String FIELD_MESSAGE
public static final String FIELD_EXTRAID
public static final int LENGTH_OBJECTCLASS
public static final int LENGTH_TXNAME
public static final int LENGTH_USER
public static String modlogClassname
| Constructor Detail |
|---|
public ModificationLog(Db db)
db - the database connection
public ModificationLog(Db db,
char modType)
db - the database connectionmodType - is the modification type (BEGIN or COMMIT)
public ModificationLog(DbObject object,
char modType)
object - 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().
| Method Detail |
|---|
public void setDb(Db db)
setDb in class DbObjectdb - the db connectionpublic void clearLazyObject()
public boolean save()
If the ID is 0, a new ID is obtained and this object inserted. Otherwise this object is updated. The modified attribute gets cleared if save() was successful.
Overridden to check for deferred logging.
save in class DbObjectpublic int setFields(PreparedStatementWrapper st)
DbObjectPreparedStatementWrapper from the object's attributes.
setFields in class DbObjectst - the statement
public boolean getFields(ResultSetWrapper rs)
DbObjectResultSetWrapper and stores them in the object's attributes.
getFields in class DbObjectrs - the result set
public int prepareInsertStatement()
DbObject
prepareInsertStatement in class DbObjectpublic int prepareUpdateStatement()
DbObject
prepareUpdateStatement in class DbObjectpublic String toString()
toString in class DbObject
public DbObject getObject(Db db)
throws ApplicationException
db - is the db-connection from which to load the object.
ApplicationException - if instantiation failed.
public DbObject getObject()
throws ApplicationException
ApplicationException - if instantiation failed.public ModificationLog selectFirst()
public List<ModificationLog> selectByObject(String objectClass,
long objectId)
objectClass - the object's class nameobjectId - the object's ID
public static boolean isReferencingUser(Db db,
String user)
db - the db connectionobjectClass - the object's classnameobjectId - the object's ID
public boolean isReferencingUser(String user)
user - name of user
public static boolean isReferencingObject(Db db,
String objectClass,
long objectId)
db - the db connectionobjectClass - the object's classnameobjectId - the object's ID
public boolean isReferencingObject(String objectClass,
long objectId)
objectClass - object classnameobjectId - object id
public DbObjectClassVariables getDbObjectClassVariables()
DbObjectDbObjectClassVariables.
getDbObjectClassVariables in class DbObjectpublic long getObjectId()
public String getObjectClass()
public 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 Timestamp getWhen()
public String getUser()
public int getErrorCode()
public void setErrorCode(int errorCode)
errorCode - error number (0=ok)public String getMessage()
public void setMessage(String message)
message - optional informational or error messagepublic long getExtraId()
public void setExtraId(long extraId)
extraId - some optional id for any purposepublic static ModificationLog instance()
public boolean replay(ModificationLog modlog,
Db toDb)
throws ApplicationException
modlog - the modification log to replaytoDb - the db the logs will be applied to
ApplicationException - if applied to BEGIN/COMMIT or object does not exist or integrity rules failed
public long replay(List<ModificationLog> modList,
boolean copyLog,
Db toDb)
throws ApplicationException
modList - the list of log objects from the source dbcopyLog - true to copy the logs as welltoDb - the db the logs will be applied to
ApplicationException - if replay failed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||