其它内容参见
ignite系列之19-数据源扩展Postgresql
public String loadCacheSelectRangeQuery(String fullTblName, Collection<String> keyCols) {标签:ignite,20,String,数据源,cols,public,fullTblName,return,col From: https://www.cnblogs.com/yangh2016/p/18348983
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);
}