001package io.ebean.config.dbplatform.postgres; 002 003import io.ebean.config.dbplatform.DbViewHistorySupport; 004 005/** 006 * Postgres support for history features. 007 */ 008public class PostgresHistorySupport extends DbViewHistorySupport { 009 010 /** 011 * Return 1 as we are using the postgres range type and hence don't need 2 bind variables. 012 */ 013 @Override 014 public int getBindCount() { 015 return 1; 016 } 017 018 /** 019 * Build and return the 'as of' predicate for a given table alias. 020 * <p> 021 * Each @History entity involved in the query has this predicate added using the related table alias. 022 * </p> 023 */ 024 @Override 025 public String getAsOfPredicate(String asOfTableAlias, String asOfSysPeriod) { 026 027 // for Postgres we are using the 'timestamp with timezone range' data type 028 // as our sys_period column so hence the predicate below 029 return asOfTableAlias + "." + asOfSysPeriod + " @> ?::timestamptz"; 030 } 031 032 @Override 033 public String getSysPeriodLower(String tableAlias, String sysPeriod) { 034 return "lower(" + tableAlias + "." + sysPeriod + ")"; 035 } 036 037 @Override 038 public String getSysPeriodUpper(String tableAlias, String sysPeriod) { 039 return "upper(" + tableAlias + "." + sysPeriod + ")"; 040 } 041}