Class DbModification
- All Implemented Interfaces:
Serializable, Comparable<DbModification>, org.tentackle.misc.Identifiable, org.tentackle.misc.Immutable, org.tentackle.misc.SerialNumbered, SessionDependable, SessionProvider
Each tracked name (usually a table name) gets a row in the modification table holding its modification
serial. The row with ID 0 holds the master serial, which is incremented with every modification.
Its tracked name holds the generation of the table, which changes whenever the table is re-initialized,
see initializeModificationTable(Db).
- Author:
- harald
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe master serial and the generation of the modification table. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DbObjectClassVariables<DbModification> Variables common to all instances ofDbModification.static final Stringdatabase column name for 'trackedName'.static final longThe generation of a modification table initialized by a former version, i.e., without a generation.Fields inherited from class AbstractDbObject
AN_CLASSID, AN_ID, AN_SERIAL, AN_TABLESERIAL, CN_CLASSID, CN_ID, CN_SERIAL, CN_TABLESERIAL, 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 Summary
ConstructorsConstructorDescriptionCreates an empty modification object.DbModification(Db db) Creates an empty modification object.DbModification(Db db, String trackedName) Creates a modification object for a given tablename. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToModificationTable(boolean tableExists, String tableSerialTableName) Adds an entry for this counter (== database object class) to the modification table.
If the referenced table provides a tableserial column, the initial serial is derived from the highest tableserial of all objects in that table.intcountModification(long count) Counts modifications.
Adds the count to the table's entry and the master entry.createInsertSql(Backend backend) Creates the SQL code for the insert statement.createUpdateSql(Backend backend) Creates the SQL code for the update statement.Gets some attributes and variables common to all objects of the same class.voidRetrieves the values of all fields from the result set.
The default implementation does nothing.Gets the attribute trackedName.static longInitializes the modification table.longrefresh()Refreshes the contents of this modification entry by its name.org.tentackle.misc.IdSerialTupleselectIdSerial(String tableName) Selects the id and serial by tablename.Reads the master-serial and the generation of the modification table.longReads the master-serial.selectTableNameForId(long id) Selects the tablename for a given ID.intSets the values of all fields (all columns of the database table) in the givenPreparedStatementWrapperfrom the object's attributes.voidsetTrackedName(String trackedName) Sets the attribute trackedName.toString()Gets the default string value.
The default implementation invokesAbstractDbObject.toGenericString().Methods inherited from class AbstractDbObject
acceptPersistenceVisitor, addPropertyListener, addPropertyListener, alignComponents, applyDbObjectResult, assertMutable, assertNew, assertNotNew, assertNotOverloaded, assertNotRemote, assertNumberOfRowsAffected, assertPersistable, assertRemote, assertThisRowAffected, attributesModified, clearFromThisJVM, clearOnRemoteSave, compareTo, countModification, createDeleteAllSql, createDeleteSql, createDummyUpdateSql, createPreparedStatement, createPreparedStatement, createPropertySupport, createSelectAllByIdInnerSql, createSelectAllIdSerialInnerSql, createSelectAllInnerSql, createSelectExpiredTableSerials1Sql, createSelectExpiredTableSerials2Sql, createSelectIdInnerSql, createSelectMaxIdSql, createSelectMaxTableSerialSql, createSelectObjectsWithExpiredTableSerialsSql, createSelectSerialSql, createSelectSql, createSqlUpdate, createStatementKey, createUpdateAndSetSerialSql, createUpdateSerialAndTableSerialSql, createUpdateSerialSql, deleteImpl, deleteObject, deletePlain, deleteReferencedRelations, deleteReferencingRelations, differsPersisted, dummyUpdate, equals, finishModification, finishNotUpdated, firePropertyChange, getBackend, getClassBaseName, getClassId, getColumnCount, getExpiredTableSerials, getId, getIdSource, getImmutableLoggingLevel, getModificationCount, getPreparedStatement, getPreparedStatement, getPropertySupport, getRemoteDelegate, getSerial, getSession, getSessionHolder, getTableName, getTableSerial, hashCode, initModification, insertImpl, insertObject, insertPlain, isCopy, isCountingModification, isDeleted, isEntity, isFinallyImmutable, isForcedModified, isFromThisJVM, isIdValid, isImmutable, isLoggingModification, isModified, isNew, isOverloadable, isPersistable, isReferenced, isRemovable, isReplayedLeniently, isSessionImmutable, isStatementAlwaysPrepared, isTableSerialProvided, isTracked, isUpdateNecessary, isUpdatingSerialEvenIfNotModified, isVirgin, loadLazyReferences, logModification, markDeleted, newId, newInstance, newInstance, newInstance, persistObject, prepareDelete, prepareSave, prepareSetFields, readFromResultSetWrapper, reloadObject, reloadObjectForUpdate, removeAllPropertyListeners, removePropertyListener, removePropertyListener, reserveId, reserveId, resultAllIdSerial, resultAllObjects, resultObjectsWithExpiredTableSerials, revertAttributesToSnapshot, saveObject, saveReferencedRelations, saveReferencingRelations, selectAllIdSerial, selectAllObjects, selectExpiredTableSerials, selectExpiredTableSerials, selectMaxId, selectMaxTableSerial, selectNextObject, selectObject, selectObjectForUpdate, selectObjectsWithExpiredTableSerials, selectSerial, setClassId, setFinallyImmutable, setId, setImmutable, setImmutableLoggingLevel, setModified, setOverloadable, setSerial, setSession, setSessionHolder, setSessionImmutable, setStatementAlwaysPrepared, setTableSerial, toGenericString, toIdString, unmarkDeleted, updateImpl, updateObject, updatePlain, updateSerial, updateSerial, updateSerialAndTableSerial
-
Field Details
-
CLASSVARIABLES
Variables common to all instances ofDbModification. -
LEGACY_GENERATION
public static final long LEGACY_GENERATIONThe generation of a modification table initialized by a former version, i.e., without a generation.- See Also:
-
CN_TRACKEDNAME
-
-
Constructor Details
-
DbModification
-
DbModification
-
DbModification
public DbModification()Creates an empty modification object.
-
-
Method Details
-
initializeModificationTable
Initializes the modification table.All rows are deleted, and the master row is re-created with a new random generation. The ids of the tracked names change, since the rows are re-created on demand. Other trackers using the table detect the re-initialization by the changed generation. The master serial alone is not sufficient: it is reset to 1 but may have been counted beyond the serial known to another tracker before its next poll.
- Parameters:
db- the session- Returns:
- the new generation
-
getClassVariables
Description copied from class:AbstractDbObjectGets some attributes and variables common to all objects of the same class. Class variables for classes derived from AbstractDbObject are kept in an instance ofDbObjectClassVariables.- Overrides:
getClassVariablesin classAbstractDbObject<DbModification>- Returns:
- the class variables
-
toString
Description copied from class:AbstractDbObjectGets the default string value.
The default implementation invokesAbstractDbObject.toGenericString().- Overrides:
toStringin classAbstractDbObject<DbModification>- Returns:
- the string value of this AbstractDbObject
-
getFields
Description copied from class:AbstractDbObjectRetrieves the values of all fields from the result set.
The default implementation does nothing.- Overrides:
getFieldsin classAbstractDbObject<DbModification>- Parameters:
rs- the result set
-
setFields
Description copied from class:AbstractDbObjectSets the values of all fields (all columns of the database table) in the givenPreparedStatementWrapperfrom the object's attributes.- Overrides:
setFieldsin classAbstractDbObject<DbModification>- Parameters:
st- the statement- Returns:
- the number of fields set
-
createInsertSql
Description copied from class:AbstractDbObjectCreates the SQL code for the insert statement.- Overrides:
createInsertSqlin classAbstractDbObject<DbModification>- Parameters:
backend- the backend- Returns:
- the SQL code
-
createUpdateSql
Description copied from class:AbstractDbObjectCreates the SQL code for the update statement.- Overrides:
createUpdateSqlin classAbstractDbObject<DbModification>- Parameters:
backend- the backend- Returns:
- the SQL code
-
getTrackedName
Gets the attribute trackedName.- Returns:
- the tablename
-
setTrackedName
Sets the attribute trackedName.- Parameters:
trackedName- the tablename
-
countModification
public int countModification(long count) Counts modifications.
Adds the count to the table's entry and the master entry.- Parameters:
count- the number of modifications to add- Returns:
- the number of modification rows updated (should be 2)
-
addToModificationTable
Adds an entry for this counter (== database object class) to the modification table.
If the referenced table provides a tableserial column, the initial serial is derived from the highest tableserial of all objects in that table.The new id is the highest id plus one. Another session adding a row concurrently, for example, another tracker re-creating its rows after a re-initialization of the table, may get the same id. The insert is then retried, unless the other session added the row for the same name.
- Parameters:
tableExists- true if related to a PDO, false if just a nametableSerialTableName- the table to scan for max tableserial if PDO manages a tableserial
-
refresh
public long refresh()Refreshes the contents of this modification entry by its name.- Returns:
- the modification count
-
selectIdSerial
Selects the id and serial by tablename.- Parameters:
tableName- the database tablename- Returns:
- the id/serial tuple, null if no such table registered so far
-
selectTableNameForId
Selects the tablename for a given ID.- Parameters:
id- the table ID- Returns:
- the tablename, null if such an ID does not exist
-
selectMasterSerial
public long selectMasterSerial()Reads the master-serial.- Returns:
- the master serial
-
selectMaster
Reads the master-serial and the generation of the modification table.- Returns:
- the master serial and generation
-