|
@@ -0,0 +1,1135 @@
|
|
|
|
+//
|
|
|
|
+// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
|
+// (powered by FernFlower decompiler)
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+package kd.bos.newdevportal.table;
|
|
|
|
+
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import kd.bos.algo.DataSet;
|
|
|
|
+import kd.bos.algo.Row;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.entity.ILocaleString;
|
|
|
|
+import kd.bos.dataentity.entity.LocaleString;
|
|
|
|
+import kd.bos.dataentity.utils.StringUtils;
|
|
|
|
+import kd.bos.db.DB;
|
|
|
|
+import kd.bos.db.DBRoute;
|
|
|
|
+import kd.bos.db.DBType;
|
|
|
|
+import kd.bos.db.FieldInfo;
|
|
|
|
+import kd.bos.db.IndexInfo;
|
|
|
|
+import kd.bos.db.SqlBuilder;
|
|
|
|
+import kd.bos.db.SqlParameter;
|
|
|
|
+import kd.bos.db.tx.TX;
|
|
|
|
+import kd.bos.exception.ErrorCode;
|
|
|
|
+import kd.bos.exception.KDException;
|
|
|
|
+import kd.bos.logging.Log;
|
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
|
+import org.apache.commons.collections.map.CaseInsensitiveMap;
|
|
|
|
+
|
|
|
|
+class DBTableProviderNew extends TableInfoProvider {
|
|
|
|
+ private static Log log = LogFactory.getLog(DBTableProviderNew.class);
|
|
|
|
+ private static boolean distinct = Boolean.parseBoolean(System.getProperty("bos.dev.tableprovider.distinct", "true"));
|
|
|
|
+ protected IGetTableHandler handler;
|
|
|
|
+
|
|
|
|
+ DBTableProviderNew() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String,DesignerTable> getTableInfo_youhua(List<String> tableNames,List<String> entityNumList) {
|
|
|
|
+ Map<String, List<DesignerColumn>> column_map = this.handler.batchLoadColumns(this.route,tableNames);
|
|
|
|
+ Map<String,DesignerTable> returnmap = new HashMap<>();
|
|
|
|
+ for (int i = 0; i < tableNames.size(); i++) {
|
|
|
|
+ DesignerTable table = this.buildTableInfo_youhua(column_map.get(tableNames.get(i)), tableNames.get(i),entityNumList.get(i));
|
|
|
|
+ returnmap.put(tableNames.get(i), table);
|
|
|
|
+ }
|
|
|
|
+ return returnmap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DesignerTable getTableInfo(String tableName, String entityNum) {
|
|
|
|
+ String lowerTableName = tableName.toLowerCase();
|
|
|
|
+ List<DesignerColumn> cols = this.handler.getColumns(this.route, lowerTableName);
|
|
|
|
+ List<DesignerIndex> idxs = this.handler.getIndexs(this.route, lowerTableName);
|
|
|
|
+ List<DesignerConstaint> constraints = this.handler.getConstraints(this.route, lowerTableName);
|
|
|
|
+ return this.buildTableInfo(cols, constraints, idxs, lowerTableName, entityNum, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private DesignerTable buildTableInfo_youhua(List<DesignerColumn> cols, String tableName,String entityNum) {
|
|
|
|
+ DesignerTable tableInfo = new DesignerTable();
|
|
|
|
+ tableInfo.setId(this.getRoute() + "#" + tableName);
|
|
|
|
+ tableInfo.setComment(new LocaleString(""));
|
|
|
|
+ tableInfo.setCode(tableName);
|
|
|
|
+ tableInfo.setName(tableName);
|
|
|
|
+ Iterator var8;
|
|
|
|
+ if (cols != null) {
|
|
|
|
+ var8 = cols.iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ DesignerColumn column = (DesignerColumn)var8.next();
|
|
|
|
+ tableInfo.getCols().add(DesignerColumn.copy(column));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tableInfo.bindEntityMeta(entityNum, true);
|
|
|
|
+ return tableInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private DesignerTable buildTableInfo(List<DesignerColumn> cols, List<DesignerConstaint> constraints, List<DesignerIndex> idxs, String tableName, String entityNum, boolean fastMode) {
|
|
|
|
+ DesignerTable tableInfo = new DesignerTable();
|
|
|
|
+ tableInfo.setId(this.getRoute() + "#" + tableName);
|
|
|
|
+ tableInfo.setComment(new LocaleString(""));
|
|
|
|
+ tableInfo.setCode(tableName);
|
|
|
|
+ tableInfo.setName(tableName);
|
|
|
|
+ Iterator var8;
|
|
|
|
+ if (cols != null) {
|
|
|
|
+ var8 = cols.iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ DesignerColumn column = (DesignerColumn)var8.next();
|
|
|
|
+ tableInfo.getCols().add(DesignerColumn.copy(column));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (constraints != null) {
|
|
|
|
+ var8 = constraints.iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ DesignerConstaint constaint = (DesignerConstaint)var8.next();
|
|
|
|
+ tableInfo.getConstaints().add(DesignerConstaint.copy(constaint));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (idxs != null) {
|
|
|
|
+ var8 = idxs.iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ DesignerIndex index = (DesignerIndex)var8.next();
|
|
|
|
+ tableInfo.getIdxs().add(DesignerIndex.copy(index));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (distinct) {
|
|
|
|
+ List<DesignerColumn> distinctCons = new ArrayList();
|
|
|
|
+ if (!tableInfo.getCols().isEmpty()) {
|
|
|
|
+ distinctCons = new ArrayList();
|
|
|
|
+ List<DesignerColumn> colList = tableInfo.getCols();
|
|
|
|
+ for (DesignerColumn col:colList) {
|
|
|
|
+ if (!distinctCons.contains(col)) {
|
|
|
|
+ distinctCons.add(col);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tableInfo.setCols(distinctCons);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!tableInfo.getIdxs().isEmpty()) {
|
|
|
|
+ ArrayList distinctCons_index = new ArrayList();
|
|
|
|
+ List<DesignerIndex> colList = tableInfo.getIdxs();
|
|
|
|
+ for (DesignerIndex col:colList) {
|
|
|
|
+ if (!distinctCons_index.contains(col)) {
|
|
|
|
+ distinctCons_index.add(col);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tableInfo.setIdxs(distinctCons_index);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!tableInfo.getConstaints().isEmpty()) {
|
|
|
|
+ ArrayList distinctCons_Constaint = new ArrayList();
|
|
|
|
+ List<DesignerConstaint> colList = tableInfo.getConstaints();
|
|
|
|
+ for (DesignerConstaint col:colList) {
|
|
|
|
+ if (!distinctCons_Constaint.contains(col)) {
|
|
|
|
+ distinctCons_Constaint.add(col);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ tableInfo.setConstaints(distinctCons_Constaint);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tableInfo.bindEntityMeta(entityNum, fastMode);
|
|
|
|
+ return tableInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<DesignerTable> getTableInfoByAppId(List<String> appIds) {
|
|
|
|
+ QFilter[] filter = new QFilter[]{new QFilter("entryentity.mainentity.bizapp.id", "in", appIds.toArray())};
|
|
|
|
+ Map<String, Map<String, Set<String>>> routeTables = new CaseInsensitiveMap(appIds.size());
|
|
|
|
+ Map<String, Map<String, EntityTableUtil.TableInfo>> entityTableMapping = new HashMap(appIds.size());
|
|
|
|
+ String entityId;
|
|
|
|
+ Iterator var38;
|
|
|
|
+ Map.Entry it;
|
|
|
|
+ if (Boolean.getBoolean("entitytable.export.fastmode")) {
|
|
|
|
+ DynamicObjectCollection cols = QueryServiceHelper.query("bos_devp_tablediction", "entity.bizapp.dbroute,entity.bizapp.number,tablename,entity.number", filter);
|
|
|
|
+ Iterator var6 = cols.iterator();
|
|
|
|
+
|
|
|
|
+ while(var6.hasNext()) {
|
|
|
|
+ DynamicObject row = (DynamicObject)var6.next();
|
|
|
|
+ String dbroute = row.getString("entity.bizapp.dbroute");
|
|
|
|
+ String tableName = row.getString("tablename");
|
|
|
|
+ entityId = row.getString("entity.number");
|
|
|
|
+ routeTables.putIfAbsent(dbroute, new HashMap());
|
|
|
|
+ ((Map)routeTables.get(dbroute)).putIfAbsent(tableName, new HashSet());
|
|
|
|
+ ((Set)((Map)routeTables.get(dbroute)).get(tableName)).add(entityId);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ Map<String, Map<String, String>> entityRouteMap = new HashMap(16);
|
|
|
|
+ builder.append("select t1.fid as entityid,t1.fnumber as entitynum,t2.fdbroute as route from t_meta_formdesign t1 inner join t_meta_bizapp t2 on t1.fbizappid = t2.fid where t1.ftype != '2' and ", new Object[0]).appendIn("t2.fid", appIds.toArray());
|
|
|
|
+ DataSet dataSet = DB.queryDataSet("entitytable", DBRoute.meta, builder);
|
|
|
|
+ Throwable var39 = null;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ while(dataSet.hasNext()) {
|
|
|
|
+ Row row = dataSet.next();
|
|
|
|
+ entityId = row.getString("entityid");
|
|
|
|
+ String dbroute = row.getString("route");
|
|
|
|
+ String num = row.getString("entitynum");
|
|
|
|
+ if (!StringUtils.isBlank(entityId) && !StringUtils.isBlank(dbroute) && !StringUtils.isBlank(num)) {
|
|
|
|
+ Map<String, String> entityIds = (Map)entityRouteMap.getOrDefault(dbroute, new HashMap(30));
|
|
|
|
+ entityIds.put(entityId, num);
|
|
|
|
+ entityRouteMap.put(dbroute, entityIds);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Throwable var31) {
|
|
|
|
+ var39 = var31;
|
|
|
|
+ throw var31;
|
|
|
|
+ } finally {
|
|
|
|
+ if (dataSet != null) {
|
|
|
|
+ if (var39 != null) {
|
|
|
|
+ try {
|
|
|
|
+ dataSet.close();
|
|
|
|
+ } catch (Throwable var28) {
|
|
|
|
+ var39.addSuppressed(var28);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ dataSet.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var38 = entityRouteMap.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var38.hasNext()) {
|
|
|
|
+ it = (Map.Entry)var38.next();
|
|
|
|
+ routeTables.put((String)it.getKey(), new HashMap(50));
|
|
|
|
+ Iterator var42 = ((Map)it.getValue()).entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var42.hasNext()) {
|
|
|
|
+ Map.Entry<String, String> idNumEntry = (Map.Entry)var42.next();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Map<String, EntityTableUtil.TableInfo> tableRef = EntityTableUtil.getTableRef((String)idNumEntry.getKey());
|
|
|
|
+ entityTableMapping.put(idNumEntry.getValue(), tableRef);
|
|
|
|
+ Iterator var48 = tableRef.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var48.hasNext()) {
|
|
|
|
+ Map.Entry<String, EntityTableUtil.TableInfo> tables = (Map.Entry)var48.next();
|
|
|
|
+ ((Map)routeTables.get(it.getKey())).putIfAbsent(tables.getKey(), new HashSet());
|
|
|
|
+ ((Set)((Map)routeTables.get(it.getKey())).get(tables.getKey())).add(idNumEntry.getValue());
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception var30) {
|
|
|
|
+ log.error("导出数据表解析元数据报错:" + var30.getMessage(), var30);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int batchSize = Integer.getInteger("devp.tableprovider.batchsize", 1000);
|
|
|
|
+ List<DesignerTable> result = new ArrayList(10);
|
|
|
|
+ var38 = routeTables.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var38.hasNext()) {
|
|
|
|
+ it = (Map.Entry)var38.next();
|
|
|
|
+ DBRoute route = DBRoute.of((String)it.getKey());
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ DB.getDBType(route);
|
|
|
|
+ } catch (Exception var29) {
|
|
|
|
+ this.getLog().error(var29);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> tables = new ArrayList(((Map)it.getValue()).keySet());
|
|
|
|
+ int max = tables.size();
|
|
|
|
+ int i = 0;
|
|
|
|
+ Map<String, List<DesignerColumn>> colMap = new CaseInsensitiveMap();
|
|
|
|
+ Map<String, List<DesignerIndex>> indexMap = new CaseInsensitiveMap();
|
|
|
|
+
|
|
|
|
+ CaseInsensitiveMap constraintMap;
|
|
|
|
+ for(constraintMap = new CaseInsensitiveMap(); i <= max; i += batchSize) {
|
|
|
|
+ int off = i + batchSize > max ? max : i + batchSize;
|
|
|
|
+ colMap.putAll(this.handler.batchLoadColumns(route, tables.subList(i, off)));
|
|
|
|
+ indexMap.putAll(this.handler.batchLoadIndexs(route, tables.subList(i, off)));
|
|
|
|
+ constraintMap.putAll(this.handler.batchLoadConstraints(route, tables.subList(i, off)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Iterator var52 = ((Map)it.getValue()).entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var52.hasNext()) {
|
|
|
|
+ Map.Entry<String, Set<String>> items = (Map.Entry)var52.next();
|
|
|
|
+
|
|
|
|
+ DesignerTable designerTable;
|
|
|
|
+ for(Iterator var18 = ((Set)items.getValue()).iterator(); var18.hasNext(); result.add(designerTable)) {
|
|
|
|
+ String entityNum = (String)var18.next();
|
|
|
|
+ designerTable = this.buildTableInfo((List)colMap.get(items.getKey()), (List)constraintMap.get(items.getKey()), (List)indexMap.get(items.getKey()), (String)items.getKey(), entityNum, true);
|
|
|
|
+ Object extCaption = ((EntityTableUtil.TableInfo)((Map)entityTableMapping.getOrDefault(entityNum, new HashMap(0))).getOrDefault(items.getKey(), new EntityTableUtil.TableInfo())).getExtInfo().get("caption");
|
|
|
|
+ if (extCaption instanceof ILocaleString) {
|
|
|
|
+ designerTable.setName(extCaption.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void setRoute(DBRoute route) {
|
|
|
|
+ super.setRoute(route);
|
|
|
|
+ this.initHandler(route);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected void initHandler(DBRoute route) {
|
|
|
|
+ this.handler = new DefaultTableHandler();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ interface IGetTableHandler {
|
|
|
|
+ default List<DesignerColumn> getColumns(DBRoute route, String tablename) {
|
|
|
|
+ List<String> list = new ArrayList(1);
|
|
|
|
+ list.add(tablename);
|
|
|
|
+ return (List)this.batchLoadColumns(route, list).get(tablename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ default List<DesignerIndex> getIndexs(DBRoute route, String tablename) {
|
|
|
|
+ List<String> list = new ArrayList(1);
|
|
|
|
+ list.add(tablename);
|
|
|
|
+ return (List)this.batchLoadIndexs(route, list).get(tablename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ default List<DesignerConstaint> getConstraints(DBRoute route, String tablename) {
|
|
|
|
+ List<String> list = new ArrayList(1);
|
|
|
|
+ list.add(tablename);
|
|
|
|
+ return (List)this.batchLoadConstraints(route, list).get(tablename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ default Map<String, Object> getTableExtInfo(DBRoute route, String tablename) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute var1, List<String> var2);
|
|
|
|
+
|
|
|
|
+ Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute var1, List<String> var2);
|
|
|
|
+
|
|
|
|
+ Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute var1, List<String> var2);
|
|
|
|
+
|
|
|
|
+ default Map<String, Map<String, Object>> batchLoadTableExtInfo(DBRoute route, List<String> tableNames) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ default Map<String, List<String>> getPrimaryKeys(DBType dbType, DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ List<String> upCaseTables = (List)tableNames.stream().map(String::toUpperCase).collect(Collectors.toList());
|
|
|
|
+ if (DBType.Oracle != dbType && DBType.DM != dbType) {
|
|
|
|
+ if (DBType.MySQL == dbType) {
|
|
|
|
+ builder.append("/*dialect*/select column_name,table_name from information_schema.key_column_usage where TABLE_SCHEMA = schema() and constraint_name= 'PRIMARY' ", new Object[0]).append(" and ", new Object[0]).appendIn("table_name", tableNames.toArray());
|
|
|
|
+ } else if (DBType.PostgreSQL == dbType) {
|
|
|
|
+ builder.append("/*dialect*/select kcu.column_name,kcu.table_name as key_column from information_schema.table_constraints tco join information_schema.key_column_usage kcu on kcu.constraint_name = tco.constraint_name and kcu.constraint_schema = tco.constraint_schema and kcu.constraint_name = tco.constraint_name where tco.constraint_type = 'PRIMARY KEY' ", new Object[0]).append(" and ", new Object[0]).appendIn("kcu.table_name", lowerCaseTables.toArray()).append(" order by kcu.ordinal_position", new Object[0]);
|
|
|
|
+ } else {
|
|
|
|
+ if (DBType.SQLServer != dbType) {
|
|
|
|
+ throw new RuntimeException("dbType " + dbType.name() + " not supported yet!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ builder.append("/*dialect*/select c.name,o.name from sysindexes i join sysindexkeys k on i.id = k.id and i.indid = k.indid join sysobjects o on i.id = o.id join syscolumns c on i.id=c.id and k.colid = c.colid where o.xtype = 'U' and exists(select 1 from sysobjects where xtype = 'PK' and name = i.name) ", new Object[0]).append(" and ", new Object[0]).appendIn("o.name", upCaseTables.toArray());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ builder.append("/*dialect*/select col.column_name,col.table_name from user_constraints con, user_cons_columns col where con.constraint_name = col.constraint_name and con.constraint_type='P'", new Object[0]).append(" and ", new Object[0]).appendIn("col.table_name", upCaseTables.toArray()).append(" order by position", new Object[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<String>> cols = new HashMap(16);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String table = rs.getString(2);
|
|
|
|
+ cols.put(table, new ArrayList());
|
|
|
|
+ List<String> list = (List)cols.get(table);
|
|
|
|
+ list.add(rs.getString(1));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cols;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class DefaultTableHandler implements IGetTableHandler {
|
|
|
|
+ DefaultTableHandler() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ Map<String, Map<String, DesignerColumn>> res = new HashMap(tableNames.size());
|
|
|
|
+ Iterator var5 = lowerCaseTables.iterator();
|
|
|
|
+
|
|
|
|
+ while(var5.hasNext()) {
|
|
|
|
+ String lowerTable = (String)var5.next();
|
|
|
|
+ res.putIfAbsent(lowerTable, new HashMap());
|
|
|
|
+ List<FieldInfo> fields = DB.getFieldInfo(route, lowerTable);
|
|
|
|
+ Iterator var8 = fields.iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ FieldInfo field = (FieldInfo)var8.next();
|
|
|
|
+ DesignerColumn col = new DesignerColumn();
|
|
|
|
+ String name = field.getFieldName();
|
|
|
|
+ col.setCode(String.valueOf(name));
|
|
|
|
+ col.setName(name);
|
|
|
|
+ col.setType(field.getDataType());
|
|
|
|
+ col.setFullType(field.getDataType());
|
|
|
|
+ String desc = "";
|
|
|
|
+ col.setComment(new LocaleString(desc));
|
|
|
|
+ Object defaultValue = field.getDataDefault();
|
|
|
|
+ col.setDefValue(defaultValue == null ? null : String.valueOf(defaultValue));
|
|
|
|
+ long fieldLenth = field.getDataLength();
|
|
|
|
+ if (fieldLenth == 0L) {
|
|
|
|
+ fieldLenth = (long)field.getDataPrecision();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ col.setLength(fieldLenth);
|
|
|
|
+ col.setPrecision((long)field.getDataPrecision());
|
|
|
|
+ col.setScale(field.getDataScale());
|
|
|
|
+ col.setNotnull(!field.isNullable());
|
|
|
|
+ ((Map)res.get(lowerTable)).put(name, col);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, List<DesignerColumn>> resultData = new HashMap(16);
|
|
|
|
+ Iterator var17 = res.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var17.hasNext()) {
|
|
|
|
+ Map.Entry<String, Map<String, DesignerColumn>> item = (Map.Entry)var17.next();
|
|
|
|
+ resultData.put(item.getKey(), new ArrayList(((Map)item.getValue()).values()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute route, List<String> tableNames) {
|
|
|
|
+ Map<String, List<DesignerIndex>> datas = new HashMap(tableNames.size());
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return datas;
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ Map<String, List<DesignerIndex>> res = new HashMap(tableNames.size());
|
|
|
|
+ Iterator var6 = lowerCaseTables.iterator();
|
|
|
|
+
|
|
|
|
+ while(var6.hasNext()) {
|
|
|
|
+ String lowTable = (String)var6.next();
|
|
|
|
+ res.putIfAbsent(lowTable, new ArrayList());
|
|
|
|
+ List<IndexInfo> indexInfos = DB.getIndexInfo(route, lowTable);
|
|
|
|
+ Iterator var9 = indexInfos.iterator();
|
|
|
|
+
|
|
|
|
+ while(var9.hasNext()) {
|
|
|
|
+ IndexInfo indexInfo = (IndexInfo)var9.next();
|
|
|
|
+ List<DesignerIndex> idxs = (List)res.get(lowTable);
|
|
|
|
+ DesignerIndex idx = new DesignerIndex();
|
|
|
|
+ String indexName = indexInfo.getIndexName();
|
|
|
|
+ idx.setName(indexName);
|
|
|
|
+ idx.setCode(indexName);
|
|
|
|
+ idx.setIndexdef(IndexType.Common.typeValue);
|
|
|
|
+ idx.setIndexType(IndexType.Common);
|
|
|
|
+ List<IndexInfo.IndexFieldInfo> indexfieldInfos = indexInfo.getIndexFieldInfo();
|
|
|
|
+ List<String> fieldNames = new ArrayList(10);
|
|
|
|
+ Iterator var16 = indexfieldInfos.iterator();
|
|
|
|
+
|
|
|
|
+ while(var16.hasNext()) {
|
|
|
|
+ IndexInfo.IndexFieldInfo indexfieldInfo = (IndexInfo.IndexFieldInfo)var16.next();
|
|
|
|
+ fieldNames.add(indexfieldInfo.getFieldName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ idx.setRefCols(fieldNames);
|
|
|
|
+ idxs.add(idx);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ datas.putAll(res);
|
|
|
|
+ } catch (Exception var18) {
|
|
|
|
+ DBTableProviderNew.log.error("数据表查询索引失败:" + var18.getMessage(), var18);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ Map<String, List<DesignerConstaint>> res = new HashMap(10);
|
|
|
|
+ Iterator var5 = lowerCaseTables.iterator();
|
|
|
|
+
|
|
|
|
+ while(var5.hasNext()) {
|
|
|
|
+ String lowerTable = (String)var5.next();
|
|
|
|
+ res.putIfAbsent(lowerTable, new ArrayList());
|
|
|
|
+ List<DesignerConstaint> constaints = (List)res.get(lowerTable);
|
|
|
|
+ List<String> primaryKeys = DB.getPrimaryKeys(route, lowerTable);
|
|
|
|
+ Iterator var9 = primaryKeys.iterator();
|
|
|
|
+
|
|
|
|
+ while(var9.hasNext()) {
|
|
|
|
+ String primaryKey = (String)var9.next();
|
|
|
|
+ DesignerConstaint constaint = new DesignerConstaint();
|
|
|
|
+ constaints.add(constaint);
|
|
|
|
+ constaint.setName(primaryKey);
|
|
|
|
+ constaint.setCode(primaryKey);
|
|
|
|
+ constaint.setRefCols(primaryKeys);
|
|
|
|
+ constaint.setConstaintType(ConstaintType.Primary);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class KSQLTableHandler implements IGetTableHandler {
|
|
|
|
+ KSQLTableHandler() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("SELECT TABLE_NAME,COLUMN_DEFAULT,IS_NULLABLE", new Object[0]).append(",NUMERIC_SCALE,COLUMN_NAME,CHARACTER_MAXIMUM_LENGTH ", new Object[0]).append(",DATA_TYPE ", new Object[0]).append(",NUMERIC_PRECISION ", new Object[0]).append(" ", new Object[0]).append(" FROM KSQL_USERCOLUMNS WHERE ", new Object[0]).appendIn("KSQL_TABNAME", lowerCaseTables.toArray());
|
|
|
|
+ Map<String, Map<String, DesignerColumn>> data = (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, Map<String, DesignerColumn>> result = new HashMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLE_NAME");
|
|
|
|
+ String name = rs.getString("COLUMN_NAME");
|
|
|
|
+ result.putIfAbsent(tableName, new HashMap());
|
|
|
|
+ DesignerColumn col = new DesignerColumn();
|
|
|
|
+ Object defvalue = rs.getObject("COLUMN_DEFAULT");
|
|
|
|
+ Object nullable = rs.getObject("IS_NULLABLE");
|
|
|
|
+ String type = rs.getString("DATA_TYPE");
|
|
|
|
+ Object length = rs.getObject("CHARACTER_MAXIMUM_LENGTH");
|
|
|
|
+ Object precision = rs.getObject("NUMERIC_PRECISION");
|
|
|
|
+ Object scale = rs.getObject("NUMERIC_SCALE");
|
|
|
|
+ String desc = "";
|
|
|
|
+ col.setCode(name);
|
|
|
|
+ col.setName(name);
|
|
|
|
+ col.setType(type);
|
|
|
|
+ col.setFullType(type);
|
|
|
|
+ col.setComment(new LocaleString(desc));
|
|
|
|
+ String defstr = defvalue == null ? null : String.valueOf(defvalue);
|
|
|
|
+ col.setDefValue(defstr == null ? null : defstr.split("::")[0]);
|
|
|
|
+ col.setLength(length == null ? (long)Integer.parseInt(String.valueOf(precision == null ? "-1" : precision)) : (long)Integer.parseInt(String.valueOf(length)));
|
|
|
|
+ col.setScale(scale == null ? 0 : Integer.parseInt(String.valueOf(scale)));
|
|
|
|
+ col.setNotnull("NO".equalsIgnoreCase(String.valueOf(nullable)));
|
|
|
|
+ ((Map)result.get(tableName)).put(name, col);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ SqlBuilder typeBuild = new SqlBuilder();
|
|
|
|
+ typeBuild.append("/*dialect*/", new Object[0]).append(" select c.relname as ftablename, a.attname as fname, format_type(a.atttypid, a.atttypmod) as ffulltype, t.typname as ftype from pg_class c inner join pg_attribute a on a.attrelid = c.oid\n inner join pg_type t on a.atttypid = t.oid where a.attnum > 0 and", new Object[0]).appendIn("c.relname", lowerCaseTables.toArray());
|
|
|
|
+ DB.query(route, typeBuild, (rs) -> {
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String table = rs.getString(1);
|
|
|
|
+ String column = rs.getString(2);
|
|
|
|
+ if (table != null && column != null) {
|
|
|
|
+ String fullType = rs.getString(3);
|
|
|
|
+ String type = rs.getString(4);
|
|
|
|
+ Map<String, DesignerColumn> items = (Map)data.get(table);
|
|
|
|
+ if (items != null) {
|
|
|
|
+ DesignerColumn item = (DesignerColumn)items.get(column);
|
|
|
|
+ if (item != null) {
|
|
|
|
+ item.setType(type);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ });
|
|
|
|
+ Map<String, List<DesignerColumn>> resultData = new HashMap(16);
|
|
|
|
+ Iterator var8 = data.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var8.hasNext()) {
|
|
|
|
+ Map.Entry<String, Map<String, DesignerColumn>> item = (Map.Entry)var8.next();
|
|
|
|
+ resultData.put(item.getKey(), new ArrayList(((Map)item.getValue()).values()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute route, List<String> tableNames) {
|
|
|
|
+ Map<String, List<DesignerIndex>> datas = new HashMap(tableNames.size());
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return datas;
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append(" SELECT ", new Object[0]).append(" INDEXNAME,INDEXDEF,TABLENAME ", new Object[0]).append(" FROM KSQL_INDEXES ", new Object[0]).append(" ", new Object[0]).append(" WHERE ", new Object[0]).appendIn("KSQL_TABNAME", lowerCaseTables.toArray());
|
|
|
|
+ datas.putAll((Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerIndex>> result = new HashMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLENAME");
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerIndex> idxs = (List)result.get(tableName);
|
|
|
|
+ DesignerIndex idx = new DesignerIndex();
|
|
|
|
+ String name = rs.getString("INDEXNAME");
|
|
|
|
+ String indexof = rs.getString("INDEXDEF");
|
|
|
|
+ idx.setName(name);
|
|
|
|
+ idx.setCode(name);
|
|
|
|
+ idx.setIndexdef(indexof);
|
|
|
|
+ idx.setIndexType(IndexType.of(this.exprIndexType(indexof, name)));
|
|
|
|
+ idx.setRefCols(this.exprIndexRef(indexof));
|
|
|
|
+ idxs.add(idx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }));
|
|
|
|
+ } catch (Exception var10) {
|
|
|
|
+ DBType type = DB.getDBType(route);
|
|
|
|
+ if (DBType.MySQL == type) {
|
|
|
|
+ Iterator var6 = tableNames.iterator();
|
|
|
|
+
|
|
|
|
+ while(var6.hasNext()) {
|
|
|
|
+ String tablename = (String)var6.next();
|
|
|
|
+ StringBuilder sbuilder = new StringBuilder();
|
|
|
|
+ sbuilder.append("/*dialect*/").append(" show index from ").append(tablename);
|
|
|
|
+ datas.putIfAbsent(tablename, new ArrayList());
|
|
|
|
+ Map<String, DesignerIndex> tableIndexs = (Map)DB.query(route, sbuilder.toString(), (rs) -> {
|
|
|
|
+ Map<String, DesignerIndex> indexMap = new HashMap(5);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String indexName = rs.getString("Key_name");
|
|
|
|
+ String column = rs.getString("Column_name");
|
|
|
|
+ indexMap.putIfAbsent(indexName, new DesignerIndex());
|
|
|
|
+ DesignerIndex index = (DesignerIndex)indexMap.get(indexName);
|
|
|
|
+ index.setCode(indexName);
|
|
|
|
+ index.setName(indexName);
|
|
|
|
+ index.setComment(new LocaleString(indexName));
|
|
|
|
+ index.getRefCols().add(column);
|
|
|
|
+ index.setTablename(tablename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return indexMap;
|
|
|
|
+ });
|
|
|
|
+ ((List)datas.get(tablename)).addAll(tableIndexs.values());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DBTableProviderNew.log.error("数据表查询索引失败:" + var10.getMessage(), var10);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<String> exprIndexRef(String createStr) {
|
|
|
|
+ int start = createStr.indexOf(40) + 1;
|
|
|
|
+ int end = createStr.indexOf(41);
|
|
|
|
+ String data = createStr.substring(start, end);
|
|
|
|
+ return Arrays.asList(data.split(","));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String exprIndexType(String createStr, String idxNum) {
|
|
|
|
+ String[] parts = createStr.split(idxNum);
|
|
|
|
+ int index = parts[0].indexOf(" ") + 1;
|
|
|
|
+ return parts[0].substring(index);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("SELECT * FROM KSQL_CONSTRAINTS ", new Object[0]).append(" WHERE ", new Object[0]).appendIn("TABLE_NAME", lowerCaseTables.toArray()).append(" and CONSTRAINT_TYPE = 'PRIMARY KEY'", new Object[0]);
|
|
|
|
+ Map<String, List<String>> pkInfos = this.getPrimaryKeys(DB.getDBType(route), route, lowerCaseTables);
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerConstaint>> result = new HashMap(10);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLE_NAME");
|
|
|
|
+ List<String> cols = (List)pkInfos.get(tableName);
|
|
|
|
+ if (cols != null && !cols.isEmpty()) {
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerConstaint> constaints = (List)result.get(tableName);
|
|
|
|
+ String name = rs.getString("CONSTRAINT_NAME");
|
|
|
|
+ DesignerConstaint constaint = new DesignerConstaint();
|
|
|
|
+ constaints.add(constaint);
|
|
|
|
+ constaint.setName(name);
|
|
|
|
+ constaint.setCode(name);
|
|
|
|
+ constaint.getRefCols().addAll(cols);
|
|
|
|
+ constaint.setConstaintType(ConstaintType.of(rs.getString("CONSTRAINT_TYPE")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class PostgreSQLHandler implements IGetTableHandler {
|
|
|
|
+ PostgreSQLHandler() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean isNumricType(String type) {
|
|
|
|
+ return "numeric".equalsIgnoreCase(type);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<String> exprIndexRef(String createStr) {
|
|
|
|
+ int start = createStr.indexOf(40) + 1;
|
|
|
|
+ int end = createStr.indexOf(41);
|
|
|
|
+ String data = createStr.substring(start, end);
|
|
|
|
+ return Arrays.asList(data.split(","));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String exprIndexType(String createStr, String idxNum) {
|
|
|
|
+ String[] parts = createStr.split(idxNum);
|
|
|
|
+ int index = parts[0].indexOf(" ") + 1;
|
|
|
|
+ return parts[0].substring(index);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/ select distinct c.relname as ftablename,\n", new Object[0]).append("a.attname as fname,\n", new Object[0]).append("format_type(a.atttypid, a.atttypmod) as ffulltype,\n", new Object[0]).append("(case when a.attlen > 0 then a.attlen else a.atttypmod - 4 end) as flength,\n", new Object[0]).append(" a.attnotnull as fnullable,\n", new Object[0]).append(" pg_get_expr(d.adbin,d.adrelid) as fdefvalue,\n", new Object[0]).append(" col_description(a.attrelid, a.attnum) as fdesc,\n", new Object[0]).append(" a.attlen as fattlen, a.atttypmod as fatttypmod ,t.typname as ftype", new Object[0]).append(" from pg_class c,\n", new Object[0]).append(" pg_attribute a\n", new Object[0]).append(" inner join (select distinct a.attname, ad.adbin,ad.adrelid\n", new Object[0]).append(" from pg_class c,\n", new Object[0]).append(" pg_attribute a,\n", new Object[0]).append(" pg_attrdef ad,\n", new Object[0]).append(" pg_type t", new Object[0]).append(" where ", new Object[0]).appendIn("relname", lowerCaseTables.toArray()).append(" and ad.adrelid = c.oid\n", new Object[0]).append(" and adnum = a.attnum\n", new Object[0]).append(" and attrelid = c.oid) as d on a.attname = d.attname\n", new Object[0]).append(" , pg_type t ", new Object[0]).append("where ", new Object[0]).appendIn("c.relname", lowerCaseTables.toArray()).append(" and a.attrelid = c.oid\n", new Object[0]).append(" and a.attnum > 0 and a.atttypid = t.oid;", new Object[0]);
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ HashMap result;
|
|
|
|
+ List cols;
|
|
|
|
+ DesignerColumn col;
|
|
|
|
+ for(result = new HashMap(16); rs.next(); cols.add(col)) {
|
|
|
|
+ String tableName = rs.getString("ftablename");
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ cols = (List)result.get(tableName);
|
|
|
|
+ col = new DesignerColumn();
|
|
|
|
+ String name = rs.getString("fname");
|
|
|
|
+ String type = rs.getString("ftype");
|
|
|
|
+ int lenght = rs.getInt("flength");
|
|
|
|
+ boolean nullable = rs.getBoolean("fnullable");
|
|
|
|
+ Object defvalue = rs.getObject("fdefvalue");
|
|
|
|
+ String desc = rs.getString("fdesc");
|
|
|
|
+ col.setCode(name);
|
|
|
|
+ col.setName(name);
|
|
|
|
+ col.setType(type);
|
|
|
|
+ col.setFullType(rs.getString("ffulltype"));
|
|
|
|
+ Integer atttypmod = rs.getInt("fatttypmod");
|
|
|
|
+ col.setLength((long)lenght);
|
|
|
|
+ if (this.isNumricType(type)) {
|
|
|
|
+ int precision = atttypmod - 4 >> 16 & '\uffff';
|
|
|
|
+ int scale = atttypmod - 4 & '\uffff';
|
|
|
|
+ col.setLength((long)precision);
|
|
|
|
+ col.setPrecision((long)precision);
|
|
|
|
+ col.setScale(scale);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ col.setNotnull(!nullable);
|
|
|
|
+ String defstr = defvalue == null ? null : String.valueOf(defvalue);
|
|
|
|
+ col.setDefValue(defstr == null ? null : defstr.split("::")[0]);
|
|
|
|
+ if (StringUtils.isNotBlank(desc)) {
|
|
|
|
+ col.setComment(new LocaleString(desc));
|
|
|
|
+ } else {
|
|
|
|
+ col.setComment(new LocaleString(name));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append(" SELECT TABLENAME,INDEXNAME,INDEXDEF ", new Object[0]).append(" FROM PG_INDEXES ", new Object[0]).append(" WHERE ", new Object[0]).appendIn("TABLENAME", lowerCaseTables.toArray());
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerIndex>> result = new HashMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString(1);
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerIndex> idxs = (List)result.get(tableName);
|
|
|
|
+ DesignerIndex idx = new DesignerIndex();
|
|
|
|
+ String name = rs.getString(2);
|
|
|
|
+ String indexof = rs.getString(3);
|
|
|
|
+ idx.setName(name);
|
|
|
|
+ idx.setCode(name);
|
|
|
|
+ idx.setIndexdef(indexof);
|
|
|
|
+ idx.setIndexType(IndexType.of(this.exprIndexType(indexof, name)));
|
|
|
|
+ idx.setRefCols(this.exprIndexRef(indexof));
|
|
|
|
+ idxs.add(idx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append(" SELECT TC.TABLE_NAME,TC.CONSTRAINT_NAME, KCU.COLUMN_NAME,", new Object[0]).append(" TC.CONSTRAINT_TYPE ", new Object[0]).append(" FROM ", new Object[0]).append(" INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC \n", new Object[0]).append(" JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU ON TC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME ", new Object[0]).append(" JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS CCU ON CCU.CONSTRAINT_NAME = TC.CONSTRAINT_NAME ", new Object[0]).append(" WHERE ", new Object[0]).appendIn("TC.TABLE_NAME", lowerCaseTables.toArray());
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerConstaint>> result = new HashMap(10);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString(1);
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerConstaint> constaints = (List)result.get(tableName);
|
|
|
|
+ String name = rs.getString(2);
|
|
|
|
+ DesignerConstaint constaint = new DesignerConstaint();
|
|
|
|
+ constaints.add(constaint);
|
|
|
|
+ constaint.setName(name);
|
|
|
|
+ constaint.setCode(name);
|
|
|
|
+ constaint.setComment(new LocaleString(""));
|
|
|
|
+ constaint.getRefCols().add(rs.getString(3));
|
|
|
|
+ constaint.setConstaintType(ConstaintType.of(rs.getString(4)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class OracleHandler implements IGetTableHandler {
|
|
|
|
+ OracleHandler() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> upperTables = (List)tableNames.stream().map(String::toUpperCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append("select ", new Object[0]).append("T.TABLE_NAME AS TABLENAME,T.COLUMN_NAME AS COLUMNNAME, T.DATA_TYPE AS COLTYPE, T.DATA_LENGTH LENGTH,T.DATA_PRECISION AS COLPRECISION,T.DATA_SCALE AS COLSCALE,T.NULLABLE AS NULLABLE,C.COMMENTS AS COMMENTS ,T.DATA_DEFAULT AS COLDEFAULT ", new Object[0]).append(" FROM USER_TAB_COLUMNS T, USER_COL_COMMENTS C WHERE T.TABLE_NAME = C.TABLE_NAME AND T.COLUMN_NAME = C.COLUMN_NAME AND ", new Object[0]).appendIn("T.TABLE_NAME", upperTables.toArray());
|
|
|
|
+ return (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerColumn>> result = new CaseInsensitiveMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLENAME");
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerColumn> dbcols = (List)result.get(tableName);
|
|
|
|
+ DesignerColumn col = new DesignerColumn();
|
|
|
|
+ String name = rs.getString("COLUMNNAME");
|
|
|
|
+ Object nullable = rs.getObject("NULLABLE");
|
|
|
|
+ String type = rs.getString("COLTYPE");
|
|
|
|
+ Object length = rs.getObject("LENGTH");
|
|
|
|
+ Object precision = rs.getObject("COLPRECISION");
|
|
|
|
+ Object scale = rs.getObject("COLSCALE");
|
|
|
|
+ Object comment = rs.getObject("COMMENTS");
|
|
|
|
+ Object defvalue = rs.getObject("COLDEFAULT");
|
|
|
|
+ String desc = comment == null ? "" : comment.toString();
|
|
|
|
+ col.setCode(name);
|
|
|
|
+ col.setName(name);
|
|
|
|
+ col.setType(type);
|
|
|
|
+ col.setFullType(type);
|
|
|
|
+ col.setComment(new LocaleString(desc));
|
|
|
|
+ col.setDefValue(defvalue == null ? null : String.valueOf(defvalue));
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ col.setLength(precision == null ? (long)Integer.parseInt(String.valueOf(length)) : (long)Integer.parseInt(String.valueOf(precision)));
|
|
|
|
+ } catch (Exception var16) {
|
|
|
|
+ col.setLength(-1L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ col.setScale(scale == null ? 0 : Integer.parseInt(String.valueOf(scale)));
|
|
|
|
+ col.setNotnull("N".equalsIgnoreCase(String.valueOf(nullable)));
|
|
|
|
+ dbcols.add(col);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> upperTables = (List)tableNames.stream().map(String::toUpperCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append("SELECT T1.INDEX_NAME , T1.INDEX_TYPE, T1.UNIQUENESS,T1.TABLE_NAME, T2.COLUMN_NAME FROM USER_INDEXES T1 ", new Object[0]).append("INNER JOIN USER_IND_COLUMNS T2 ON T1.INDEX_NAME = T2.INDEX_NAME WHERE ", new Object[0]).appendIn("T1.TABLE_NAME", upperTables.toArray());
|
|
|
|
+ Map<String, Map<String, DesignerIndex>> queryResult = (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, Map<String, DesignerIndex>> result = new CaseInsensitiveMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLE_NAME");
|
|
|
|
+ result.putIfAbsent(tableName, new CaseInsensitiveMap());
|
|
|
|
+ Map<String, DesignerIndex> idxs = (Map)result.get(tableName);
|
|
|
|
+ String name = rs.getString("INDEX_NAME");
|
|
|
|
+ Object unique = rs.getObject("UNIQUENESS");
|
|
|
|
+ DesignerIndex idx = (DesignerIndex)idxs.getOrDefault(name, new DesignerIndex());
|
|
|
|
+ idxs.put(name, idx);
|
|
|
|
+ idx.setName(name);
|
|
|
|
+ idx.setTablename(tableName);
|
|
|
|
+ idx.setCode(name);
|
|
|
|
+ idx.getRefCols().add(rs.getString("COLUMN_NAME"));
|
|
|
|
+ if ("unique".equalsIgnoreCase(String.valueOf(unique))) {
|
|
|
|
+ idx.setIndexType(IndexType.Unique);
|
|
|
|
+ } else {
|
|
|
|
+ String type = rs.getString("INDEX_TYPE");
|
|
|
|
+ idx.setIndexType(IndexType.of(type));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ Map<String, List<DesignerIndex>> resultData = new CaseInsensitiveMap(16);
|
|
|
|
+ Iterator var7 = queryResult.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var7.hasNext()) {
|
|
|
|
+ Map.Entry<String, Map<String, DesignerIndex>> item = (Map.Entry)var7.next();
|
|
|
|
+ resultData.put(item.getKey(), new ArrayList(((Map)item.getValue()).values()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> upperTables = (List)tableNames.stream().map(String::toUpperCase).collect(Collectors.toList());
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append("SELECT ", new Object[0]).append(" USER_CONS_COLUMNS.CONSTRAINT_NAME AS CONNAME , USER_CONS_COLUMNS.TABLE_NAME AS TABLENAME ,USER_CONS_COLUMNS.COLUMN_NAME AS COLNAME ", new Object[0]).append(" FROM USER_CONSTRAINTS JOIN USER_CONS_COLUMNS ON (USER_CONSTRAINTS.CONSTRAINT_NAME = USER_CONS_COLUMNS.CONSTRAINT_NAME) WHERE ", new Object[0]).append(" CONSTRAINT_TYPE = 'P' AND", new Object[0]).appendIn("USER_CONS_COLUMNS.TABLE_NAME", upperTables.toArray());
|
|
|
|
+ Map<String, Map<String, DesignerConstaint>> data = (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, Map<String, DesignerConstaint>> result = new CaseInsensitiveMap();
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLENAME");
|
|
|
|
+ String name = rs.getString("CONNAME");
|
|
|
|
+ result.putIfAbsent(tableName, new HashMap());
|
|
|
|
+ ((Map)result.get(tableName)).putIfAbsent(name, new DesignerConstaint());
|
|
|
|
+ DesignerConstaint constaint = (DesignerConstaint)((Map)result.get(tableName)).get(name);
|
|
|
|
+ constaint.setName(name);
|
|
|
|
+ constaint.setCode(name);
|
|
|
|
+ constaint.setComment(new LocaleString(""));
|
|
|
|
+ constaint.getRefCols().add(rs.getString(3));
|
|
|
|
+ constaint.setConstaintType(ConstaintType.Primary);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ Map<String, List<DesignerConstaint>> resultData = new CaseInsensitiveMap(16);
|
|
|
|
+ Iterator var7 = data.entrySet().iterator();
|
|
|
|
+
|
|
|
|
+ while(var7.hasNext()) {
|
|
|
|
+ Map.Entry<String, Map<String, DesignerConstaint>> item = (Map.Entry)var7.next();
|
|
|
|
+ resultData.put(item.getKey(), new ArrayList(((Map)item.getValue()).values()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class MySQLHandler implements IGetTableHandler {
|
|
|
|
+ MySQLHandler() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerColumn>> batchLoadColumns(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ String schema = this.getTableScheme(route);
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append(" SELECT TABLE_NAME,COLUMN_NAME ,COLUMN_DEFAULT ,IS_NULLABLE ,DATA_TYPE ,CHARACTER_MAXIMUM_LENGTH ,NUMERIC_PRECISION ,NUMERIC_SCALE,COLLATION_NAME ,COLUMN_KEY ,COLUMN_COMMENT,COLUMN_TYPE ", new Object[0]).append(" FROM information_schema.COLUMNS ", new Object[0]).append(" WHERE ", new Object[0]);
|
|
|
|
+ if (StringUtils.isNotBlank(schema)) {
|
|
|
|
+ builder.append(" TABLE_SCHEMA = ? ", new Object[]{new SqlParameter(":TABLE_SCHEMA", 12, schema)}).append(" AND ", new Object[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ builder.appendIn(" TABLE_NAME ", lowerCaseTables.toArray());
|
|
|
|
+ Map<String, List<DesignerColumn>> data = (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, List<DesignerColumn>> result = new HashMap(tableNames.size());
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLE_NAME");
|
|
|
|
+ result.putIfAbsent(tableName, new ArrayList());
|
|
|
|
+ List<DesignerColumn> dbcols = (List)result.get(tableName);
|
|
|
|
+ DesignerColumn col = new DesignerColumn();
|
|
|
|
+ String name = rs.getString("COLUMN_NAME");
|
|
|
|
+ Object defvalue = rs.getObject("COLUMN_DEFAULT");
|
|
|
|
+ Object nullable = rs.getObject("IS_NULLABLE");
|
|
|
|
+ String type = rs.getString("DATA_TYPE");
|
|
|
|
+ Object length = rs.getObject("CHARACTER_MAXIMUM_LENGTH");
|
|
|
|
+ Object precision = rs.getObject("NUMERIC_PRECISION");
|
|
|
|
+ Object scale = rs.getObject("NUMERIC_SCALE");
|
|
|
|
+ Object comment = rs.getObject("COLUMN_COMMENT");
|
|
|
|
+ String desc = comment == null ? "" : comment.toString();
|
|
|
|
+ col.setCode(name);
|
|
|
|
+ col.setName(name);
|
|
|
|
+ col.setType(type);
|
|
|
|
+ col.setFullType(rs.getString("COLUMN_TYPE"));
|
|
|
|
+ col.setComment(new LocaleString(desc));
|
|
|
|
+ col.setDefValue(defvalue == null ? null : String.valueOf(defvalue));
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ col.setScale(scale == null ? 0 : Integer.parseInt(String.valueOf(scale)));
|
|
|
|
+ col.setLength(length == null ? (precision == null ? -1L : Long.parseLong(String.valueOf(precision))) : Long.parseLong(String.valueOf(length)));
|
|
|
|
+ col.setPrecision(col.getLength());
|
|
|
|
+ } catch (Exception var16) {
|
|
|
|
+ col.setLength(-1L);
|
|
|
|
+ col.setScale(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ col.setNotnull("NO".equalsIgnoreCase(String.valueOf(nullable)));
|
|
|
|
+ dbcols.add(col);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getTableScheme(DBRoute route) {
|
|
|
|
+ String schema = null;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ schema = TX.__getConnection(route.getRouteKey(), true).getSchema();
|
|
|
|
+ return schema;
|
|
|
|
+ } catch (SQLException var4) {
|
|
|
|
+ throw new KDException(new ErrorCode("env.tablequery.err", "query databasename err"), new Object[]{var4});
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerIndex>> batchLoadIndexs(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ Map<String, List<DesignerIndex>> result = new HashMap(16);
|
|
|
|
+ Iterator var5 = lowerCaseTables.iterator();
|
|
|
|
+
|
|
|
|
+ while(var5.hasNext()) {
|
|
|
|
+ String tablename = (String)var5.next();
|
|
|
|
+ result.putIfAbsent(tablename, new ArrayList());
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ StringBuilder sbuilder = new StringBuilder();
|
|
|
|
+ sbuilder.append("/*dialect*/").append(" show index from ").append(tablename);
|
|
|
|
+ Map<String, DesignerIndex> tableIndexs = (Map)DB.query(route, sbuilder.toString(), (Object[])null, (rs) -> {
|
|
|
|
+ Map<String, DesignerIndex> indexMap = new HashMap(5);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String indexName = rs.getString("Key_name");
|
|
|
|
+ String column = rs.getString("Column_name");
|
|
|
|
+ indexMap.putIfAbsent(indexName, new DesignerIndex());
|
|
|
|
+ DesignerIndex index = (DesignerIndex)indexMap.get(indexName);
|
|
|
|
+ index.setCode(indexName);
|
|
|
|
+ index.setName(indexName);
|
|
|
|
+ String uniqueStr = rs.getString("Non_unique");
|
|
|
|
+ if ("0".equals(uniqueStr)) {
|
|
|
|
+ index.setIndexType(IndexType.Unique);
|
|
|
|
+ } else {
|
|
|
|
+ index.setIndexType(IndexType.Common);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ index.setIndexdef("");
|
|
|
|
+ index.setComment(new LocaleString(indexName));
|
|
|
|
+ index.getRefCols().add(column);
|
|
|
|
+ index.setTablename(tablename);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return indexMap;
|
|
|
|
+ });
|
|
|
|
+ ((List)result.get(tablename)).addAll(tableIndexs.values());
|
|
|
|
+ } catch (Exception var9) {
|
|
|
|
+ DBTableProviderNew.log.error("devp.DBTableProviderNew.err", var9);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, List<DesignerConstaint>> batchLoadConstraints(DBRoute route, List<String> tableNames) {
|
|
|
|
+ if (tableNames.isEmpty()) {
|
|
|
|
+ return new HashMap();
|
|
|
|
+ } else {
|
|
|
|
+ List<String> lowerCaseTables = (List)tableNames.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
|
|
+ String schema = this.getTableScheme(route);
|
|
|
|
+ SqlBuilder builder = new SqlBuilder();
|
|
|
|
+ builder.append("/*dialect*/", new Object[0]).append("select CONSTRAINT_NAME ,CONSTRAINT_TYPE,TABLE_NAME FROM information_schema.TABLE_CONSTRAINTS ", new Object[0]).append(" WHERE ", new Object[0]);
|
|
|
|
+ if (StringUtils.isNotBlank(schema)) {
|
|
|
|
+ builder.append(" CONSTRAINT_SCHEMA = ? ", new Object[]{new SqlParameter(":CONSTRAINT_SCHEMA", 12, schema)}).append(" AND ", new Object[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ builder.appendIn("TABLE_NAME", lowerCaseTables.toArray());
|
|
|
|
+ Map<String, List<String>> pkInfos = this.getPrimaryKeys(DB.getDBType(route), route, lowerCaseTables);
|
|
|
|
+ Map<String, Map<String, DesignerConstaint>> data = (Map)DB.query(route, builder, (rs) -> {
|
|
|
|
+ Map<String, Map<String, DesignerConstaint>> result = new HashMap(16);
|
|
|
|
+
|
|
|
|
+ while(rs.next()) {
|
|
|
|
+ String tableName = rs.getString("TABLE_NAME");
|
|
|
|
+ result.putIfAbsent(tableName, new HashMap());
|
|
|
|
+ List<String> cols = (List)pkInfos.get(tableName);
|
|
|
|
+ if (cols != null && !cols.isEmpty()) {
|
|
|
|
+ Map<String, DesignerConstaint> constaints = (Map)result.get(tableName);
|
|
|
|
+ String name = rs.getString("CONSTRAINT_NAME");
|
|
|
|
+ DesignerConstaint constaint = (DesignerConstaint)constaints.getOrDefault(name, new DesignerConstaint());
|
|
|
|
+ constaints.put(name, constaint);
|
|
|
|
+ constaint.setName(name);
|
|
|
|
+ constaint.setCode(name);
|
|
|
|
+ constaint.setComment(new LocaleString(""));
|
|
|
|
+ if (constaint.getRefCols().isEmpty()) {
|
|
|
|
+ constaint.getRefCols().add(cols.get(0));
|
|
|
|
+ } else {
|
|
|
|
+ constaint.getRefCols().set(0, cols.get(0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constaint.setConstaintType(ConstaintType.of(rs.getString("CONSTRAINT_TYPE")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ });
|
|
|
|
+ Map<String, List<DesignerConstaint>> returnData = new HashMap(data.size());
|
|
|
|
+ data.forEach((k, v) -> {
|
|
|
|
+ returnData.put(k, new ArrayList(v.values()));
|
|
|
|
+ });
|
|
|
|
+ return returnData;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|