Skip to content

Commit

Permalink
SourceScriptBuilder.checkSourceAndAlia throw ParsingException (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Dec 28, 2021
1 parent 8f0c69c commit 3420a9b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import io.xream.sqli.exception.NotSupportedException;
import io.xream.sqli.exception.ParsingException;
import io.xream.sqli.parser.Parser;
import io.xream.sqli.util.SqliStringUtil;

Expand Down Expand Up @@ -49,9 +50,21 @@ public interface SourceScriptBuilder {

ConditionBuilder more();

static void checkAlia(List<SourceScript> list) {

static void checkSourceAndAlia(List<SourceScript> list) {
for (SourceScript sourceScript : list) {
String source = sourceScript.getSource();
final String source = sourceScript.getSource();
if (SqliStringUtil.isNotNull(source) && !Parser.contains(source)) {
String tip = "";
if (sourceScript.getJoinType() != null) {
tip += sourceScript.getJoinType().name().replace("_"," ");
}else if(SqliStringUtil.isNotNull(sourceScript.getJoinStr())){
tip += sourceScript.getJoinStr();
}else {
tip += SqlScript.FROM;
}
throw new ParsingException(tip + SqlScript.SPACE + source);
}
String alia = sourceScript.getAlia();
if (source !=null && alia !=null && !alia.equals(source) && Parser.contains(alia)) {
throw new NotSupportedException("not support table alia = firstLetterLower(parsedEntityName), name+alia: " + source + " " + alia);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ private void parseAliaFromRefresh(RefreshCondition refreshCondition) {
String script = refreshCondition.getSourceScript();//string -> list<>
List<String> list = SourceScriptBuilder.split(script);
List<SourceScript> sourceScripts = SourceScriptBuilder.parse(list);
SourceScriptBuilder.checkAlia(sourceScripts);
SourceScriptBuilder.checkSourceAndAlia(sourceScripts);
for (SourceScript sc : sourceScripts) {
refreshCondition.getAliaMap().put(sc.alia(), sc.getSource());
}
Expand All @@ -659,7 +659,7 @@ private void parseAlia(Criteria criteria, SqlSth sqlSth) {
rmc.getSourceScripts().addAll(sourceScripts);
}

SourceScriptBuilder.checkAlia(rmc.getSourceScripts());
SourceScriptBuilder.checkSourceAndAlia(rmc.getSourceScripts());
supportSingleSource(rmc);

Map<String, String> aliaMap = rmc.getAliaMap();
Expand Down
16 changes: 10 additions & 6 deletions sqli-builder/src/main/java/io/xream/sqli/mapping/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package io.xream.sqli.mapping;

import io.xream.sqli.exception.ParsingException;
import io.xream.sqli.parser.Parsed;
import io.xream.sqli.parser.Parser;
import io.xream.sqli.util.ParserUtil;
Expand Down Expand Up @@ -60,12 +61,15 @@ default String mapping(String key, Mappable mappable) {
if (parsed == null)
return key;

String p = parsed.getMapper(property);
if (SqliStringUtil.isNullOrEmpty(p)) {
return mappable.getResultKeyAliaMap().get(key);
String m = parsed.getMapper(property);
if (SqliStringUtil.isNullOrEmpty(m)) {
String s = mappable.getResultKeyAliaMap().get(key);
if (SqliStringUtil.isNullOrEmpty(s))
throw new ParsingException(key);
return s;
}

return parsed.getTableName(alia) + Script.DOT + p;
return parsed.getTableName(alia) + Script.DOT + m;
}

/*
Expand Down Expand Up @@ -105,9 +109,9 @@ default Class mapClzz(String key, Mappable mappable) {
String clzName = ParserUtil.getClzName(alia, mappable.getAliaMap());

Parsed parsed = Parser.get(clzName);
if (parsed != null){
if (parsed != null) {
return parsed.getElement(property).getClz();
}else {
} else {
return String.class;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public void setNoCache(boolean isNoCache) {
this.isNoCache = isNoCache;
}


public String getMapper(String property) {
return propertyMapperMap.get(property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ public static String getProperty(String methodName) {
return getByFirstLower(str);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private static void parseFilterListOfElementList(List<BeanElement> filterList, S
be.setSetter(setter);
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
public interface ResultMapRepository {

Page<Map<String, Object>> find(Criteria.ResultMapCriteria resultMapBuilder);
Page<Map<String, Object>> find(Criteria.ResultMapCriteria resultMapCriteria);

List<Map<String, Object>> list(Criteria.ResultMapCriteria resultMapBuilder);
List<Map<String, Object>> list(Criteria.ResultMapCriteria resultMapCriteria);

<K> List<K> listPlainValue(Class<K> clzz, Criteria.ResultMapCriteria resultMapBuilder);
<K> List<K> listPlainValue(Class<K> clzz, Criteria.ResultMapCriteria resultMapCriteria);

/**
* like stream, fetchSize=50, the api not fast, to avoid OOM when scheduling
Expand Down

0 comments on commit 3420a9b

Please sign in to comment.