This commit is contained in:
lxy
2020-05-10 23:18:59 +08:00
parent 707e9ee680
commit 68eea7b27d
42 changed files with 5969 additions and 361 deletions

View File

@@ -1,7 +1,7 @@
package net.tccn.base.dbq.fbean;
import net.tccn.base.Kv;
import net.tccn.base.X;
import net.tccn.base.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +31,7 @@ public enum FilterType {
//不同的条件构建过滤语句
public static String buildSql(Filter filter) {
if (X.isEmpty(filter.getValue()) && X.isEmpty(filter.getValues())) {
if (Utils.isEmpty(filter.getValue()) && Utils.isEmpty(filter.getValues())) {
return "";
}
FilterType filterType = getFilterType(filter.getType());

View File

@@ -1,10 +1,13 @@
package net.tccn.base.dbq.fbean;
import lombok.Data;
import java.util.List;
/**
* Created by liangxianyou at 2018/12/14 15:36.
*/
@Data
public class Order {
private String col;
private int desc;//1 or -1

View File

@@ -1,6 +1,6 @@
package net.tccn.base.dbq.jdbc.api;
import net.tccn.base.X;
import net.tccn.base.Utils;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -31,7 +31,7 @@ public class DbKit implements DbSource{
this.catalog = catalog;
try {
DbSource dbSource = X.getDbSource(DbSource.class, dbAccount.getCate());
DbSource dbSource = Utils.getDbSource(DbSource.class, dbAccount.getCate());
dbSource.setDbAccount(dbAccount);
dbSource.setCatalog(catalog);

View File

@@ -60,10 +60,9 @@ public class DbSourceMysql implements DbSource {
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery()) {
List list = new ArrayList();
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount();
while (rs.next()) {
ResultSetMetaData metaData = rs.getMetaData();
int count = metaData.getColumnCount();
Map row = new HashMap();
for (int i = 1; i <= count; i++) {
String columnTypeName = metaData.getColumnTypeName(i);
@@ -87,6 +86,7 @@ public class DbSourceMysql implements DbSource {
return list;
} catch (SQLException e) {
System.out.println("sql :"+ sql);
e.printStackTrace();
return null;
} finally {

View File

@@ -6,7 +6,6 @@ import net.tccn.meta.MetaLink;
import net.tccn.meta.MetaService;
import net.tccn.meta.MetaTable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
@@ -64,20 +63,20 @@ public class ParseMysql implements Parser {
if (sameDbFun.test(tables) || true) {
// where 1=1 and xx=xx
StringBuffer bufWhere = new StringBuffer();
if (!X.isEmpty(filters)) {
if (!Utils.isEmpty(filters)) {
bufWhere.append(Filter.filter(filters, DbType.MYSQL));
}
//select a.x, b.y, c.z
StringBuffer bufSelect = new StringBuffer();
bufSelect.append("select ");
if ("export".equals(fBean.getType()) && !X.isEmpty(exports)) {
if ("export".equals(fBean.getType()) && !Utils.isEmpty(exports)) {
exports.forEach(x -> {
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
});
bufSelect.deleteCharAt(bufSelect.length() - 1);
}
else if ("list".equals(fBean.getType()) && !X.isEmpty(shows)) {
else if ("list".equals(fBean.getType()) && !Utils.isEmpty(shows)) {
shows.forEach(x -> {
bufSelect.append(x.get("col")).append(" as ").append("'").append(x.get("col")).append("',");
});
@@ -88,13 +87,13 @@ public class ParseMysql implements Parser {
//from
StringBuilder bufFrom = new StringBuilder();
bufFrom.append(" from ").append(metaTable.getCatalog()).append(".`").append(metaTable.getName()).append("` ").append(metaTable.getAlias());
bufFrom.append(" from ").append(metaTable.getCatalog()).append(".`").append(metaTable.getName()).append("` `").append(metaTable.getAlias()).append("`");
//left join
if (!X.isEmpty(links)) {
if (!Utils.isEmpty(links)) {
links.forEach(x -> {
MetaTable rightTable = tables.get(metaTable.getAlias().equals(x.getTables()[0]) ? x.getTables()[1] : x.getTables()[0]);
if (rightTable != null) {
bufFrom.append(" left join ").append(rightTable.getCatalog()).append(".").append(rightTable.getName()).append(" ").append(rightTable.getAlias()).append(" on ");
bufFrom.append(" left join ").append(rightTable.getCatalog()).append(".").append(rightTable.getName()).append(" `").append(rightTable.getAlias()).append("` on ");
int tag = bufFrom.length();
x.getLink().forEach((k, v) -> {
if (bufFrom.length() > tag) {
@@ -108,7 +107,7 @@ public class ParseMysql implements Parser {
StringBuffer bufOth = new StringBuffer();
//order by
if (!X.isEmpty(orders)) {
if (!Utils.isEmpty(orders)) {
bufOth.append(" ").append(Order.order(orders, DbType.MYSQL));
}
//limit
@@ -168,18 +167,18 @@ public class ParseMysql implements Parser {
List<String> keys = data.keySet()
.stream()
.filter(x ->
x.startsWith(alias + ".") || !X.isEmpty(data.get(alias + "." + x))
x.startsWith(alias + ".") || !Utils.isEmpty(data.get(alias + "." + x))
).collect(Collectors.toList());
if (pks.length == 0) {
throw new CfgException("保存数据失败,检查业务主表[%s-%S]主键配置", mainTable.getName(), mainTable.getComment());
} else if (keys.size() == 0) {
throw new CfgException("保存数据失败提交数据不能改空");
throw new CfgException("保存数据失败,提交数据不能改空");
}
//单主键
String pv = data.get(alias + "." + pks[0]);
if (X.isEmpty(pv)) { //新增
if (Utils.isEmpty(pv)) { //新增
String sqlTpl = "INSERT INTO `%s` (%s) VALUES %s;"; // para: table、 ks、 vs
StringBuffer ks = new StringBuffer();// `k1`,`k2`,`k3`, ...
StringBuffer vs = new StringBuffer();// `v1`,`v2`,`v3`, ...

View File

@@ -14,6 +14,7 @@ public class Field {
private String inType;
private String inExt;
private Boolean pk; // 是否主键
private Boolean notNull; // 是否主键
public Field() {}