Skip Headers

# Using Historical Queries

Previous

Next

To make a query time-aware, you specify an `AsOfClause` that TopLink appends to the query. Use the `AsOfClause` class if your historical schema is based on time stamps or the `AsOfSCNClause` class if your historical schema is based on database system change numbers. You can specify an `AsOfClause` at the time you acquire a historical session so that TopLink appends the same clause to all queries, or you can specify an `AsOfClause` on a query-by-query basis.

Example: Using a Historical Session shows how to create a query that uses a particular `AsOfClause`. This query will read all `Employee` objects as of the time specified by `timestamp` using the appropriate history tables described by the `HistoryPolicy` set on the `Employee` descriptor.

Using a Historical Session

    ReadAllQuery historicalQuery = new ReadAllQuery(Employee.class);
    AsOfClause asOfClause = new AsOfClause(timestamp);
    historicalQuery.setAsOfClause(asOfClause);
    historicalQuery.dontMaintainCache();
    Vector pastEmployees = (Vector)historicalSession.executeQuery(historicalQuery);