package MSQ.OP.SM.AOP.MEC.SIQ.SM.OSQ.E; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_AggregationPLSQL; import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_ConditionPLSQL_XCDX_Cache; import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_ConditionPLSQL_XCDX_Map; import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_ConditionPLSQL_XCDX_Table; //import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_ConditionPLSQL; import ME.SM.OP.SM.AOP.MEC.SIQ.E.P_GetCulumnsPLSQL; import MS.OP.SM.AOP.MEC.SIQ.cache.DetaDBBufferCache_M; import OP.SM.AOP.MEC.SIQ.SM.reflection.Spec; import PEU.P.cache.*; import SVQ.stable.StableShellETL; @SuppressWarnings({ "unused", "unchecked" }) //作者,著作权人: 罗瑶光,浏阳 public class Q_Rows_E { public static List> selectRowsByAttribute(String currentDB , String tableName, String culmnName, Object value) throws IOException{ if(value==null) { value=""; } String objectType = ""; List> output = new ArrayList<>(); //锁定数据库 String DBPath = Cache_M.getCacheInfo("DBPath").getValue().toString() + "/" + currentDB; //锁定表 File fileDBPath = new File(DBPath); if (fileDBPath.isDirectory()) { String DBTablePath = DBPath + "/" + tableName; File fileDBTable = new File(DBTablePath); if (fileDBTable.isDirectory()) { String DBTableCulumnPath = DBTablePath + "/spec/" + culmnName; File fileDBTableCulumn = new File(DBTableCulumnPath); if (fileDBTableCulumn.isDirectory()) { //读取列数据格式 String[] fileList = fileDBTableCulumn.list(); File readDBTableSpecCulumnFile = new File(DBTableCulumnPath + "/" + fileList[0]); BufferedReader reader = new BufferedReader(new FileReader(readDBTableSpecCulumnFile)); String tempString = null; while ((tempString = reader.readLine()) != null) { objectType = tempString; } reader.close(); if(objectType.contains("string")) { String DBTableRowsPath = DBTablePath + "/rows"; File fileDBTableRowsPath = new File(DBTableRowsPath); if (fileDBTableRowsPath.isDirectory()) { String[] rowList = fileDBTableRowsPath.list(); NextRow: for(String row: rowList) { Map rowMap = new HashMap<>(); String DBTableRowIndexPath = DBTablePath + "/rows/" + row; File readDBTableRowIndexFile = new File(DBTableRowIndexPath); if (readDBTableRowIndexFile.isDirectory()) { String isDelete = DBTableRowIndexPath + "/is_delete_1" ; File isDeleteFile = new File(isDelete); if(isDeleteFile.exists()) { continue NextRow; } String DBTableRowIndexCulumnPath = DBTableRowIndexPath + "/" + culmnName; File readDBTableRowIndexCulumnFile = new File(DBTableRowIndexCulumnPath); if (readDBTableRowIndexCulumnFile.isDirectory()) { reader = new BufferedReader(new FileReader(readDBTableRowIndexCulumnFile + "/" + "value.lyg")); String temp=""; while ((tempString = reader.readLine()) != null) { temp += tempString; } reader.close(); if(temp.equalsIgnoreCase(value.toString())) { String[] culumnList = readDBTableRowIndexFile.list(); NextFile: for(String culumn: culumnList) { if(culumn.contains("is_delete")) { continue NextFile; } String DBTableCulumnIndexPath = DBTableRowIndexPath + "/" + culumn; File readDBTableCulumnIndexPathFile = new File(DBTableCulumnIndexPath); if (readDBTableRowIndexCulumnFile.isDirectory()) { reader = new BufferedReader( new FileReader(readDBTableCulumnIndexPathFile + "/" + "value.lyg")); temp=""; while ((tempString = reader.readLine()) != null) { temp += tempString; } reader.close(); rowMap.put(culumn, temp); }else { rowMap.put(culumn, null); } } output.add(rowMap); } } } } } } } } } return output; } @SuppressWarnings("static-access") public static void main(String[] args) { try { new Q_Rows_E().selectRowsByAttribute("backend", "login" , "usr_name", "yaoguangluo"); // deletefile("D:/file"); } catch (FileNotFoundException ex) { } catch (IOException ex) { } System.out.println("ok"); } public static Map selectRowsByTablePath(String tablePath, String pageBegin , String pageEnd, String direction) throws IOException { Map output = new HashMap<>(); int totalPages = 0; output.put("tablePath", tablePath); int rowBeginIndex = Integer.valueOf(pageBegin); int rowEndIndex = Integer.valueOf(pageEnd); String objectType = ""; List rowMapList = new ArrayList<>(); File fileDBTable = new File(tablePath); if (fileDBTable.isDirectory()) { String DBTableRowsPath = tablePath + "/rows"; File fileDBTableRowsPath = new File(DBTableRowsPath); if (fileDBTableRowsPath.isDirectory()) { File[] files = fileDBTableRowsPath.listFiles(); totalPages = files.length; int i = 0; int index = 0; Here: while(i<15) { String DBTableRowIndexPath = DBTableRowsPath + "/row" + (direction.contains("next")? rowEndIndex++: --rowBeginIndex); File readDBTableRowIndexFile = new File(DBTableRowIndexPath); if (!readDBTableRowIndexFile.exists()) { break; } File deleteTest = new File(DBTableRowIndexPath + "/is_delete_1"); if (deleteTest.exists()) { continue Here; } i++; Map rowMap = new HashMap<>(); String[] readDBTableRowCulumnsIndexFile = readDBTableRowIndexFile.list(); Map culumnMaps = new HashMap<>(); NextFile: for(String readDBTableRowCulumnIndexFile: readDBTableRowCulumnsIndexFile) { if(readDBTableRowCulumnIndexFile.contains("is_delete")) { continue NextFile; } Map culumnMap = new HashMap<>(); String DBTableRowIndexCulumnPath = DBTableRowIndexPath + "/" + readDBTableRowCulumnIndexFile; File readDBTableRowIndexCulumnFile = new File(DBTableRowIndexCulumnPath); if (readDBTableRowIndexCulumnFile.exists()) { String temp = ""; FileInputStream fis = new FileInputStream(new File(DBTableRowIndexCulumnPath + "/value.lyg")); BufferedInputStream bis = new BufferedInputStream(fis); byte[] buffer = new byte[1024]; int cnt; while((cnt = bis.read(buffer)) != -1) { temp += new String(buffer, 0, cnt); } fis.close(); bis.close(); culumnMap.put(StableShellETL.SHELL_ETL_CULUMNNAME, readDBTableRowCulumnIndexFile); culumnMap.put("culumnValue", temp); culumnMaps.put(readDBTableRowCulumnIndexFile, culumnMap); } } rowMap.put(StableShellETL.SHELL_ETL_ROWVALUE, culumnMaps); if(direction.contains("next")) { rowMap.put("rowIndex", rowEndIndex-1); rowMapList.add(rowMap); }else { rowMap.put("rowIndex", rowBeginIndex); rowMapList.add(0, rowMap); } } } } if(direction.contains("next")) { output.put("pageBegin", Integer.valueOf(pageEnd)); output.put("pageEnd", rowEndIndex); output.put("totalPages", totalPages); }else { output.put("pageBegin", rowBeginIndex); output.put("pageEnd", Integer.valueOf(pageBegin)); output.put("totalPages", totalPages); } output.put("obj", rowMapList); List spec= new ArrayList<>(); Map row = (Map) rowMapList.get(0); Map culumns = (Map) row.get(StableShellETL.SHELL_ETL_ROWVALUE); Iterator it=culumns.keySet().iterator(); while(it.hasNext()) { spec.add(((Map)culumns.get(it.next())).get(StableShellETL.SHELL_ETL_CULUMNNAME).toString()); } output.put("spec", spec); return output; } //因为数据id的补充, 今天开始进行相应的debug验证 罗瑶光20210405 public static Object selectRowsByAttributesOfCondition(Map object) throws IOException { if(!object.containsKey("recordRows")) { Map recordRows = new ConcurrentHashMap<>(); object.put("recordRows", recordRows); } Spec spec = new Spec(); spec.I_CulumnTypes(new ConcurrentHashMap()); String objectType = ""; List> output = new ArrayList<>(); //锁定数据库 String DBPath = Cache_M.getCacheInfo("DBPath").getValue().toString() + "/" + object.get("baseName").toString(); //锁定表 File fileDBPath = new File(DBPath); if (fileDBPath.isDirectory()) { String DBTablePath = DBPath + "/" + object.get("tableName").toString(); File fileDBTable = new File(DBTablePath); if (fileDBTable.isDirectory()) { String DBTableCulumnPath = DBTablePath + "/spec"; File fileDBTableCulumn = new File(DBTableCulumnPath); if (fileDBTableCulumn.isDirectory()) { //读取列数据格式 String[] fileList = fileDBTableCulumn.list(); for(int i=0; i conditionValues = (List) object.get(StableShellETL.SHELL_ETL_CONDITION); Iterator iterator = conditionValues.iterator(); while(iterator.hasNext()) { boolean overMap = output.size() == 0? false: true; String[] conditionValueArray = iterator.next(); String type = conditionValueArray[1]; boolean andMap = type.equalsIgnoreCase("and")?true:false; for(int i = 2; i < conditionValueArray.length; i++) { String[] sets = conditionValueArray[i].split("\\|"); if(overMap&& andMap) { P_ConditionPLSQL_XCDX_Map.P_Map(sets, output, DBTablePath);//1 }else if(DetaDBBufferCache_M.dbCache){ P_ConditionPLSQL_XCDX_Cache.P_Cache(sets, output, object.get("tableName").toString() , object.get("baseName").toString(), object);//1 }else { //DMA的表格导入, 我等下同样进行验算,2年的编写过程全部朔源. 20210405 让猫腻 无死角. P_ConditionPLSQL_XCDX_Table.P_Table(sets, output, DBTablePath, object);//1 } } } } } } return output; } public static List> selectRowsByAttributesOfAggregation(Map object) { if(!object.containsKey("obj")) { return new ArrayList<>(); } List> obj = ((List>)(object.get("obj"))); List aggregationValues = (List) object.get("aggregation"); Iterator iterator = aggregationValues.iterator(); while(iterator.hasNext()) { boolean overMap = obj.size() == 0? false: true; String[] aggregationValueArray = iterator.next(); String type = aggregationValueArray[1]; boolean limitMap = type.equalsIgnoreCase("limit")?true:false; for(int i = 2; i < aggregationValueArray.length; i++) { String[] sets = aggregationValueArray[i].split("\\|"); String DBPath = Cache_M.getCacheInfo("DBPath").getValue().toString() + "/" + object.get("baseName").toString(); String dBTablePath = DBPath + "/" + object.get("tableName").toString(); if(limitMap) { P_AggregationPLSQL.P_AggregationLimitMap(sets, obj); } //基于sort key 前序treeMap 之后排序功能设计 //基于sort key 后序treeMap } } return obj; } public static Object selectRowsByAttributesOfGetCulumns(Map object) { if(!object.containsKey("obj")) { return new ArrayList<>(); } List> obj = ((List>)(object.get("obj"))); List getCulumnsValues = (List) object.get("getCulumns"); Iterator iterator = getCulumnsValues.iterator(); while(iterator.hasNext()) { boolean overMap = obj.size() == 0? false: true; String[] getCulumnsValueArray = iterator.next(); if(overMap) { P_GetCulumnsPLSQL.P_GetCulumnsMap(obj, getCulumnsValueArray); } } return obj; } }