Top Description Fields Constructors Methods
org.eclipse.persistence.history

public Class HistoryPolicy

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Imports
java.io.Serializable, java.util.ArrayList, .Enumeration, .List, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.expressions.Expression, .ExpressionBuilder, org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform, org.eclipse.persistence.internal.expressions.ConstantExpression, .ObjectExpression, .SQLDeleteStatement, .SQLInsertStatement, .SQLUpdateStatement, .TableExpression, org.eclipse.persistence.internal.helper.ClassConstants, .ConversionManager, .DatabaseField, .DatabaseTable, .Helper, org.eclipse.persistence.internal.history.HistoricalDatabaseTable, org.eclipse.persistence.internal.queries.StatementQueryMechanism, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, org.eclipse.persistence.mappings.DatabaseMapping, .DatabaseMapping.WriteType, .DirectCollectionMapping, .ManyToManyMapping, org.eclipse.persistence.queries.DataModifyQuery, .DeleteAllQuery, .ModifyQuery, .ObjectLevelModifyQuery, org.eclipse.persistence.sessions.DatabaseRecord

Purpose:Expresses how historical data is saved on the data store.

This information is used to both maintain a history of all objects modified through TopLink and to enable point in time querying.

If Oracle 9R2 or later Flashback is used this policy is not required, as the preservation of history is automatic.

Descriptors, ManyToManyMappings, DirectCollectionMappings, and DirectMapMappings only can have a history policy, as only they have associated database tables.

Author
Stephen McRitchie
Since
10

Field Summary

Modifier and TypeField and Description
protected ClassDescriptor
protected List<DatabaseField>
protected List<DatabaseTable>
protected DatabaseMapping
protected boolean
protected List<DatabaseField>
protected boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addEndFieldName(String endFieldName)

PUBLIC:

public void
addHistoryTableName(String name)

PUBLIC: Use to specify the names of the mirroring historical tables.

public void
addHistoryTableName(String sourceTableName, String historyTableName)

PUBLIC: Use to specify the names of the mirroring historical tables.

public Expression
additionalHistoryExpression(Expression context, Expression base)

INTERNAL: Add any temporal querying conditions to this object expression.

public Expression
additionalHistoryExpression(Expression context, Expression base, Integer
not null indicates that only expression for a single table should be returned.
tableIndex
)

INTERNAL: Add any temporal querying conditions to this object expression.

public void
addStartFieldName(String startFieldName)

PUBLIC: Sets the name of the start field.

protected boolean
checkWastedVersioning(AbstractRecord modifyRow, DatabaseTable table)

INTERNAL: Checks for the case where an object has multiple tables but only some are part of a minimal update.

public Object
clone()

Overrides java.lang.Object.clone.

PUBLIC: Performs a sufficiently deep clone.
public Object
getCurrentTime(AbstractSession session)

PUBLIC: Whenever a historical record is logically deleted (updated) or inserted, the end and start fields respectively will be set to this value.

public ClassDescriptor
getDescriptor()

PUBLIC: Return the descriptor of the policy.

protected DatabaseField
getEnd()

INTERNAL:

protected DatabaseField
getEnd(int i)

INTERNAL:

public String
getEndFieldName()

PUBLIC:

public List<DatabaseField>
getEndFields()

INTERNAL:

public final List<DatabaseTable>
public List<String>
public DatabaseMapping
getMapping()

PUBLIC:

public long
getMinimumTimeIncrement(AbstractSession session)

INTERNAL: Return a minimal time increment supported by the platform.

protected DatabaseField
getStart()

INTERNAL:

protected DatabaseField
getStart(int i)

INTERNAL:

public String
getStartFieldName()

PUBLIC: Answers the name of the start field.

public List<DatabaseField>
getStartFields()

INTERNAL:

public void
initialize(AbstractSession session)

INTERNAL: Initialize a HistoryPolicy.

public void
logicalDelete(ModifyQuery writeQuery, boolean isUpdate)

INTERNAL: Performs a logical delete (update) on the historical schema.

public void
logicalDelete(ModifyQuery writeQuery, boolean isUpdate, boolean isShallow)

INTERNAL: Performs a logical delete (update) on the historical schema.

public void
logicalInsert(ObjectLevelModifyQuery writeQuery, boolean isUpdate)

INTERNAL: Perform a logical insert into the historical schema, creating a new version of an object.

public void
mappingLogicalDelete(ModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session)

INTERNAL: Performs a logical delete (update) on the historical schema.

public void
mappingLogicalInsert(DataModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session)

INTERNAL: Performs a logical insert into the historical schema.

public void
postDelete(ModifyQuery deleteQuery)

INTERNAL:

public void
postInsert(ObjectLevelModifyQuery writeQuery)

INTERNAL:

public void
postUpdate(ObjectLevelModifyQuery writeQuery)

INTERNAL:

public void
postUpdate(ObjectLevelModifyQuery writeQuery, boolean isShallow)

INTERNAL:

public void
setDescriptor(ClassDescriptor descriptor)

PUBLIC:

protected void
setEndFields(List<DatabaseField> endFields)

INTERNAL:

public void
setEndFieldType(String fieldName, Class<?> type)

ADVANCED:

public void
setHistoricalTables(List<DatabaseTable> historicalTables)

INTERNAL:

public void
setMapping(DatabaseMapping mapping)

INTERNAL:

public void
setShouldHandleWrites(boolean value)

Sets if TopLink is responsible for writing history.

public void
setShouldUseDatabaseTime(boolean
if false uses localTime (default) instead
value
)

Sets if the Timestamp used in maintainaing history should be the current time according to the database.

protected void
setStartFields(List<DatabaseField> startFields)

INTERNAL:

public void
setStartFieldType(Class<?> type)

ADVANCED: Sets the type of all start fields.

public boolean

Returns:

true by default
shouldHandleWrites
()

Answers if TopLink is responsible for writing history.

public boolean

Returns:

false by default
shouldUseDatabaseTime
()

Answers if the Timestamp used in maintaining history should be the current time according to the database.

public boolean

Returns:

true by default
shouldUseLocalTime
()

Answers if the Timestamp used in maintaining history should be System.currentTimeMillis();

public void
useDatabaseTime()

Answers if the Timestamp used in maintaining history should be the current time according to the database.

public void
useLocalTime()

Answers if the Timestamp used in maintaining history should be System.currentTimeMillis();

protected void
verifyTableQualifiers(DatasourcePlatform platform)

INTERNAL: Check that the qualifiers on the historical tables are properly set.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

descriptorback to summary
protected ClassDescriptor descriptor
endFieldsback to summary
protected List<DatabaseField> endFields
historicalTablesback to summary
protected List<DatabaseTable> historicalTables
mappingback to summary
protected DatabaseMapping mapping
shouldHandleWritesback to summary
protected boolean shouldHandleWrites
startFieldsback to summary
protected List<DatabaseField> startFields
usesLocalTimeback to summary
protected boolean usesLocalTime

Constructor Detail

HistoryPolicyback to summary
public HistoryPolicy()

Method Detail

addEndFieldNameback to summary
public void addEndFieldName(String endFieldName)

PUBLIC:

See Also
addStartFieldName
addHistoryTableNameback to summary
public void addHistoryTableName(String name)

PUBLIC: Use to specify the names of the mirroring historical tables.

Assumes that the order in which tables are added with descriptor.addTableName() matches the order in which mirroring historical tables are added with descriptor.addHistoryTableName().

addHistoryTableNameback to summary
public void addHistoryTableName(String sourceTableName, String historyTableName)

PUBLIC: Use to specify the names of the mirroring historical tables.

Explicitly states that sourceTableName is mirrored by history table historyTableName. The order in which tables are added with descriptor.addTableName() should still match the order in which mirroring historical tables are added with descriptor.addMirroringHistoryTableName().

additionalHistoryExpressionback to summary
public Expression additionalHistoryExpression(Expression context, Expression base)

INTERNAL: Add any temporal querying conditions to this object expression.

additionalHistoryExpressionback to summary
public Expression additionalHistoryExpression(Expression context, Expression base, Integer tableIndex)

INTERNAL: Add any temporal querying conditions to this object expression.

Parameters
tableIndex:Integer

not null indicates that only expression for a single table should be returned.

addStartFieldNameback to summary
public void addStartFieldName(String startFieldName)

PUBLIC: Sets the name of the start field.

By default all tables belonging to a descriptor have the same primary key field names, and so the same start field names also.

However, if startFieldName is qualified, i.e. of the form "EMPLOYEE_HIST.EMP_START", then this call will only set the start field name for a single historical table.

checkWastedVersioningback to summary
protected boolean checkWastedVersioning(AbstractRecord modifyRow, DatabaseTable table)

INTERNAL: Checks for the case where an object has multiple tables but only some are part of a minimal update.

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

PUBLIC: Performs a sufficiently deep clone. Use to quickly setup standard policies on multiple descriptors.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
getCurrentTimeback to summary
public Object getCurrentTime(AbstractSession session)

PUBLIC: Whenever a historical record is logically deleted (updated) or inserted, the end and start fields respectively will be set to this value.

getDescriptorback to summary
public ClassDescriptor getDescriptor()

PUBLIC: Return the descriptor of the policy.

getEndback to summary
protected DatabaseField getEnd()

INTERNAL:

getEndback to summary
protected DatabaseField getEnd(int i)

INTERNAL:

getEndFieldNameback to summary
public String getEndFieldName()

PUBLIC:

getEndFieldsback to summary
public List<DatabaseField> getEndFields()

INTERNAL:

getHistoricalTablesback to summary
public final List<DatabaseTable> getHistoricalTables()

INTERNAL:

getHistoryTableNamesback to summary
public List<String> getHistoryTableNames()

PUBLIC:

getMappingback to summary
public DatabaseMapping getMapping()

PUBLIC:

getMinimumTimeIncrementback to summary
public long getMinimumTimeIncrement(AbstractSession session)

INTERNAL: Return a minimal time increment supported by the platform.

getStartback to summary
protected DatabaseField getStart()

INTERNAL:

getStartback to summary
protected DatabaseField getStart(int i)

INTERNAL:

getStartFieldNameback to summary
public String getStartFieldName()

PUBLIC: Answers the name of the start field. Assumes that multiple tables for a descriptor have the same field names.

getStartFieldsback to summary
public List<DatabaseField> getStartFields()

INTERNAL:

initializeback to summary
public void initialize(AbstractSession session)

INTERNAL: Initialize a HistoryPolicy.

logicalDeleteback to summary
public void logicalDelete(ModifyQuery writeQuery, boolean isUpdate)

INTERNAL: Performs a logical delete (update) on the historical schema.

logicalDeleteback to summary
public void logicalDelete(ModifyQuery writeQuery, boolean isUpdate, boolean isShallow)

INTERNAL: Performs a logical delete (update) on the historical schema.

logicalInsertback to summary
public void logicalInsert(ObjectLevelModifyQuery writeQuery, boolean isUpdate)

INTERNAL: Perform a logical insert into the historical schema, creating a new version of an object.

Called by postInsert() and also postUpdate() (which first does a logicalDelete of the previous version).

mappingLogicalDeleteback to summary
public void mappingLogicalDelete(ModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session)

INTERNAL: Performs a logical delete (update) on the historical schema. Direct collections and many to many mappings are maintained through the session events.

mappingLogicalInsertback to summary
public void mappingLogicalInsert(DataModifyQuery originalQuery, AbstractRecord arguments, AbstractSession session)

INTERNAL: Performs a logical insert into the historical schema. Direct collections and many to many mappings are maintained through the session events.

postDeleteback to summary
public void postDelete(ModifyQuery deleteQuery)

INTERNAL:

postInsertback to summary
public void postInsert(ObjectLevelModifyQuery writeQuery)

INTERNAL:

postUpdateback to summary
public void postUpdate(ObjectLevelModifyQuery writeQuery)

INTERNAL:

postUpdateback to summary
public void postUpdate(ObjectLevelModifyQuery writeQuery, boolean isShallow)

INTERNAL:

setDescriptorback to summary
public void setDescriptor(ClassDescriptor descriptor)

PUBLIC:

setEndFieldsback to summary
protected void setEndFields(List<DatabaseField> endFields)

INTERNAL:

setEndFieldTypeback to summary
public void setEndFieldType(String fieldName, Class<?> type)

ADVANCED:

See Also
setStartFieldType
setHistoricalTablesback to summary
public void setHistoricalTables(List<DatabaseTable> historicalTables)

INTERNAL:

setMappingback to summary
public void setMapping(DatabaseMapping mapping)

INTERNAL:

setShouldHandleWritesback to summary
public void setShouldHandleWrites(boolean value)

Sets if TopLink is responsible for writing history.

If history is maintained via low level database triggers or application logic a policy is still needed for point in time querying.

If Oracle flashback is used no HistoryPolicy is needed.

Setting this to false lets you use History for many other applications. For instance a table that tracks available flights or hotel deals may benefit from a HistoryPolicy just to simplify temporal querying.

If all hotel discounts have a start and end date, you could query on all discounts available at a certain date.

setShouldUseDatabaseTimeback to summary
public void setShouldUseDatabaseTime(boolean value)

Sets if the Timestamp used in maintainaing history should be the current time according to the database.

Parameters
value:boolean

if false uses localTime (default) instead

setStartFieldsback to summary
protected void setStartFields(List<DatabaseField> startFields)

INTERNAL:

setStartFieldTypeback to summary
public void setStartFieldType(Class<?> type)

ADVANCED: Sets the type of all start fields. Not required to be set as the default of Timestamp is assumed.

shouldHandleWritesback to summary
public boolean shouldHandleWrites()

Answers if TopLink is responsible for writing history.

If history is maintained via low level database triggers or application logic a policy is still usefull for point in time querying.

If Oracle flashback is used no HistoryPolicy is needed.

Returns:boolean

true by default

See Also
setShouldHandleWrites
shouldUseDatabaseTimeback to summary
public boolean shouldUseDatabaseTime()

Answers if the Timestamp used in maintaining history should be the current time according to the database.

Returns:boolean

false by default

See Also
shouldUseLocalTime, useDatabaseTime
shouldUseLocalTimeback to summary
public boolean shouldUseLocalTime()

Answers if the Timestamp used in maintaining history should be System.currentTimeMillis();

Returns:boolean

true by default

See Also
shouldUseDatabaseTime, useLocalTime
useDatabaseTimeback to summary
public void useDatabaseTime()

Answers if the Timestamp used in maintaining history should be the current time according to the database.

See Also
useLocalTime, shouldUseDatabaseTime
useLocalTimeback to summary
public void useLocalTime()

Answers if the Timestamp used in maintaining history should be System.currentTimeMillis();

See Also
useDatabaseTime, shouldUseLocalTime
verifyTableQualifiersback to summary
protected void verifyTableQualifiers(DatasourcePlatform platform)

INTERNAL: Check that the qualifiers on the historical tables are properly set.

A similar method exists on ClassDescriptor.