.
This commit is contained in:
20
src/main/java/net/tccn/dbq/DbExecutors.java
Normal file
20
src/main/java/net/tccn/dbq/DbExecutors.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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)) {
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user