Skip to content

Commit

Permalink
Add sql exportor for test (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Jul 28, 2021
1 parent 31ddf30 commit 13f7f51
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions sqli-builder/src/main/java/io/xream/sqli/test/SqlExportor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
*/
package io.xream.sqli.test;

import io.xream.sqli.builder.Criteria;
import io.xream.sqli.builder.CriteriaToSql;
import io.xream.sqli.builder.SqlBuildingAttached;
import io.xream.sqli.builder.SqlBuilt;
import io.xream.sqli.builder.*;
import io.xream.sqli.builder.internal.DefaultCriteriaToSql;
import io.xream.sqli.parser.Parser;
import javafx.util.Pair;

import java.io.File;
import java.nio.file.Files;
Expand All @@ -40,7 +36,7 @@ public class SqlExportor {
private static SqlExportor instance;
private static CriteriaToSql criteriaToSql;

private static List<Pair<String,Criteria.ResultMapCriteria>> resultMapCriteriaList = new ArrayList<>();
private static List<KV> resultMapCriteriaList = new ArrayList<>();


private SqlExportor(){}
Expand All @@ -59,16 +55,16 @@ public SqlExportor source(Class<?> clzz) {
}

public SqlExportor build(String traceKey, Criteria.ResultMapCriteria resultMapCriteria){
Pair<String,Criteria.ResultMapCriteria> pair = new Pair<>(traceKey,resultMapCriteria);
resultMapCriteriaList.add(pair);
KV kv = new KV(traceKey,resultMapCriteria);
resultMapCriteriaList.add(kv);
return instance;
}

public void export(String fileName){

StringBuilder sb = new StringBuilder();

for (Pair<String,Criteria.ResultMapCriteria> pair : resultMapCriteriaList) {
for (KV kv : resultMapCriteriaList) {

SqlBuilt sqlBuilt = new SqlBuilt();

Expand All @@ -86,9 +82,9 @@ public List<SqlBuilt> getSubList() {
return sqlBuiltList;
}
};
criteriaToSql.toSql(false,pair.getValue(),sqlBuilt,sqlBuildingAttached);
criteriaToSql.toSql(false,(Criteria.ResultMapCriteria) kv.getV(),sqlBuilt,sqlBuildingAttached);

sb.append("-- Test trace: " + pair.getKey()).append("\r\n");
sb.append("-- Test trace: " + kv.getK()).append("\r\n");
sb.append("-- Test value: " + valueList).append("\r\n");
sb.append(sqlBuilt.getSql()).append("\r\n");
sb.append("-- -------------------------------------------").append("\r\n").append("\r\n");
Expand Down

0 comments on commit 13f7f51

Please sign in to comment.