#382 - ENH: Add support for @History using Oracle Total Recall ... for 'as of' queries

This commit is contained in:
Robin Bygrave committed 2015-08-18 22:19:55 +12:00
1 parent 18aeedc153
commit 10937de24b
13 files changed
+234 -52

No files matched your search

@@ -403,9 +403,10 @@ public class CQueryBuilder {
}
List<String> asOfTableAlias = query.getAsOfTableAlias();
if (asOfTableAlias != null) {
if (asOfTableAlias != null && !historySupport.isBindAtFromClause()) {
// append the effective date predicates for each table alias
// that maps to a @History entity involved in this query
// Do this when history using separate tables/views (PG, MySql etc)
if (!hasWhere) {
sb.append(" where ");
} else {
@@ -30,22 +30,42 @@ public class CQueryHistorySupport {
this.sysPeriod = sysPeriod;
}
/**
* Return true if the bind of 'as of' timestamp occurs with the from clause
* rather than at the end.
*/
public boolean isBindAtFromClause() {
return dbHistorySupport.isBindWithFromClause();
}
/**
* Return the 'as of' history view for the given base table.
*/
public String getAsOfView(String table) {
return asOfTableMap.get(table);
}
/**
* Return the lower bound column.
*/
public String getSysPeriodLower(String tableAlias) {
return dbHistorySupport.getSysPeriodLower(tableAlias, sysPeriod);
}
/**
* Return the upper bound column.
*/
public String getSysPeriodUpper(String tableAlias) {
return dbHistorySupport.getSysPeriodUpper(tableAlias, sysPeriod);
}
/**
* Return the predicate appended to the end of the query.
*
* Note used for Oracle total recall etc with the more standard approach.
*/
public String getAsOfPredicate(String tableAlias) {
return dbHistorySupport.getAsOfPredicate(tableAlias, sysPeriod);
}
}
@@ -131,6 +131,18 @@ public class CQueryPredicates {
StringBuilder bindLog = new StringBuilder();
List<String> historyTableAlias = query.getAsOfTableAlias();
if (historyTableAlias != null && binder.isBindAsOfWithFromClause()) {
// bind the asOf value for each table alias as part of the from/join clauses
// there is one effective date predicate per table alias
Timestamp asOf = query.getAsOf();
bindLog.append("asOf ").append(asOf);
for (int i = 0; i < historyTableAlias.size() * binder.getAsOfBindCount(); i++) {
binder.bindObject(dataBind, asOf);
}
bindLog.append(", ");
}
if (idValue != null) {
// this is a find by id type query...
request.getBeanDescriptor().bindId(dataBind, idValue);
@@ -143,7 +155,6 @@ public class CQueryPredicates {
}
if (whereExprBindValues != null) {
for (int i = 0; i < whereExprBindValues.size(); i++) {
Object bindValue = whereExprBindValues.get(i);
bindValue = binder.bindObject(dataBind, bindValue);
@@ -155,7 +166,6 @@ public class CQueryPredicates {
}
if (filterManyExprBindValues != null) {
for (int i = 0; i < filterManyExprBindValues.size(); i++) {
Object bindValue = filterManyExprBindValues.get(i);
bindValue = binder.bindObject(dataBind, bindValue);
@@ -166,9 +176,8 @@ public class CQueryPredicates {
}
}
List<String> historyTableAlias = query.getAsOfTableAlias();
if (historyTableAlias != null) {
// bind the asAt value for each table alias
if (historyTableAlias != null && !binder.isBindAsOfWithFromClause()) {
// bind the asOf value for each table alias after all the normal predicates
// there is one effective date predicate per table alias
Timestamp asOf = query.getAsOf();
bindLog.append(" asOf ").append(asOf);