001package com.avaje.ebean.config.dbplatform;
002
003/**
004 * History support for the database platform.
005 */
006public interface DbHistorySupport {
007
008  /**
009   * Return true if the 'As of' predicate is part of the from clause
010   * (more standard sql2011). So true for Oracle total recall and false
011   * for Postgres and MySql (where we use views and history tables).
012   */
013  boolean isBindWithFromClause();
014
015  /**
016   * Return the number of columns bound in a 'As Of' predicate.
017   * <p>
018   * This is 1 for more standard sql2011 style and Postgres which has the
019   * special range type and 2 for view based solutions with 2 columns such as
020   * MySql.
021   * </p>
022   */
023  int getBindCount();
024
025  /**
026   * For sql2011 style this ignores the passed in view suffix and returns something
027   * like the ' as of timestamp ?' clause to be appended after the base table name.
028   *
029   * @param asOfViewSuffix the configured view suffix (typically "_with_history").
030   * @return The suffix appended after the base table name in the from and join clauses.
031   */
032  String getAsOfViewSuffix(String asOfViewSuffix);
033
034  /**
035   * Return the 'versions between timestamp' suffix.
036   */
037  String getVersionsBetweenSuffix(String asOfViewSuffix);
038
039  /**
040   * Return the 'as of' predicate added for the given table alias.
041   *
042   * @param tableAlias The table alias this predicate is added for
043   * @param sysPeriod  The name of the 'sys_period' column used for effective date time range.
044   * @return The predicate containing a single ? bind parameter which will be bound to the 'as at' timestamp value
045   */
046  String getAsOfPredicate(String tableAlias, String sysPeriod);
047
048  /**
049   * Return the column for the system period lower bound that will be included in findVersions() queries.
050   *
051   * @param tableAlias the table alias which will typically be 't0'
052   * @param sysPeriod  the name of the sys_period column
053   */
054  String getSysPeriodLower(String tableAlias, String sysPeriod);
055
056  /**
057   * Return the column for the system period upper bound that will be included in findVersions() queries.
058   *
059   * @param tableAlias the table alias which will typically be 't0'
060   * @param sysPeriod  the name of the sys_period column
061   */
062  String getSysPeriodUpper(String tableAlias, String sysPeriod);
063
064}