其它內容參見
ignite系列之19-資料來源擴充套件Postgresql
public String loadCacheSelectRangeQuery(String fullTblName, Collection<String> keyCols) {
String cols = mkString(keyCols, ",");
String condition = DataSourceUtils.getCondition(fullTblName);
return StringUtils.isBlank(condition) ? String.format("SELECT %s FROM (SELECT %s, row_number() over(order by %s) AS rn FROM %s ) as temp WHERE mod(rn, ?) = 0", cols, cols, cols, fullTblName) : String.format("SELECT %s FROM (SELECT %s, row_number() over(order by %s) AS rn FROM %s where %s) as temp WHERE mod(rn, ?) = 0", cols, cols, cols, fullTblName, condition);
}
public boolean hasMerge() {
return true;
}
public String mergeQuery(String fullTblName, Collection<String> keyCols, Collection<String> uniqCols) {
Collection<String> cols = F.concat(false, keyCols, uniqCols);
String onPart = mkString(keyCols, new C1<String, String>() {
public String apply(String col) {
return String.format("T.%s = S.%s", col, col);
}
}, "", " AND ", "");
String updatePart = mkString(uniqCols, new C1<String, String>() {
public String apply(String col) {
return String.format("T.%s = S.%s", col, col);
}
}, "", ", ", "");
String insertPart = mkString(cols, new C1<String, String>() {
public String apply(String col) {
return String.format("S.%s", col);
}
}, "", ", ", "");
return String.format("MERGE INTO %s AS T USING (SELECT * FROM (VALUES (%s)) AS V (%s)) AS S ON %s WHEN MATCHED THEN UPDATE SET %s WHEN NOT MATCHED THEN INSERT (%s) VALUES (%s)", fullTblName, repeat("?", cols.size(), "", ",", ""), mkString(cols, ", "), onPart, updatePart, mkString(cols, ", "), insertPart);
}