This commit is contained in:
2019-04-03 18:08:46 +08:00
parent 853ed30ffb
commit fbd7b0afdd
16 changed files with 337 additions and 94 deletions

View File

@@ -0,0 +1,20 @@
package net.tccn.dbq;
import net.tccn.base.Kv;
import net.tccn.base.PageBean;
import net.tccn.dbq.fbean.FBean;
import net.tccn.dbq.parser.ParseMysql;
import net.tccn.dbq.parser.Parser;
import java.util.Arrays;
public class DbExecutors {
private final static Parser PARSER = new ParseMysql();
public static PageBean findPage(FBean fBean) {
String[] sqls = PARSER.parse(fBean);
return PageBean.by(Arrays.asList(Kv.of("findSql:", sqls[0]).set("countSql", sqls[1]) ), 0);
}
}

View File

@@ -8,7 +8,7 @@ import java.util.List;
*/
public class FBean {
private String name;
private String name;//service key
private List<Filter> filters;//[{f:xx, v: v, type:t}] -- t,
private List<Order> orders;//{f1: 1, f2: -1}
private Limit limit;//{pn: 1, ps: 10}

View File

@@ -38,13 +38,13 @@ public enum FilterType {
String _sql;
switch (filterType) {
case IN:
_sql = String.format(" AND `%s` IN (%s)", filter.getCol(), filter.getValue());
_sql = String.format(" AND %s IN (%s)", filter.getCol(), filter.getValue());
break;
case LIKE:
_sql = String.format(" AND `%s` LIKE '%s'", filter.getCol(), "%" + filter.getValue() + "%");
_sql = String.format(" AND %s LIKE '%s'", filter.getCol(), "%" + filter.getValue() + "%");
break;
default:
_sql = String.format(" AND `%s` %s '%s'", filter.getCol(), filterType.expre, filter.getValue());
_sql = String.format(" AND %s %s '%s'", filter.getCol(), filterType.expre, filter.getValue());
break;
}

View File

@@ -1,4 +1,6 @@
package net.tccn.dbq.fbean;
package net.tccn.dbq.parser;
import net.tccn.dbq.fbean.FBean;
/**
* Created by liangxianyou at 2018/12/24 15:49.

View File

@@ -1,4 +1,6 @@
package net.tccn.dbq.fbean;
package net.tccn.dbq.parser;
import net.tccn.dbq.fbean.FBean;
/**
* Created by liangxianyou at 2018/12/24 15:49.

View File

@@ -1,6 +1,7 @@
package net.tccn.dbq.fbean;
package net.tccn.dbq.parser;
import net.tccn.base.Kv;
import net.tccn.dbq.fbean.*;
import net.tccn.meta.MetaKit;
import net.tccn.meta.MetaLink;
import net.tccn.meta.MetaService;
@@ -105,7 +106,7 @@ public class ParseMysql implements Parser {
public String[] parse(FBean fBean) {
MetaService metaService = MetaKit.getMetaService(fBean.getName());
Kv<String, MetaTable> tables = MetaKit.getMetaTables(metaService);//所有的关联表信息
Kv<String, MetaTable> tables = MetaKit.getMetaTables(metaService, false);//所有的关联表信息
MetaTable metaTable = tables.get(metaService.getTable());//基础元数据
List<String> shows = metaService.getShows();//查询的属性
@@ -120,7 +121,7 @@ public class ParseMysql implements Parser {
//判断是否为同库
if (sameDbFun.test(tables)) {
if (sameDbFun.test(tables) || true) {
// where 1=1 and xx=xx
StringBuffer bufWhere = new StringBuffer();
if (!isEmpty.test(filters)) {

View File

@@ -1,4 +1,6 @@
package net.tccn.dbq.fbean;
package net.tccn.dbq.parser;
import net.tccn.dbq.fbean.FBean;
/**
* Created by liangxianyou at 2018/12/24 15:47.