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