Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Using Historical Queries

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 99-2 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.

Example 99-2 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);