package MSU.OP.SM.AOP.MEC.SIQ.SM.update.E; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; 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 org.json.JSONObject; 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_GetCulumnsPLSQL; import MS.OP.SM.AOP.MEC.SIQ.cache.DetaDBBufferCache_M; import OP.SM.AOP.MEC.SIQ.SM.reflection.Cell; import OP.SM.AOP.MEC.SIQ.SM.reflection.Row; import OP.SM.AOP.MEC.SIQ.SM.reflection.Spec; import PEU.P.cache.*; import SVQ.stable.StableShellETL; @SuppressWarnings("unchecked") //作者,著作权人: 罗瑶光,浏阳 public class U_Rows_E { public static Map updateRowByTablePathAndIndex(String tablePath, String pageIndex, JSONObject jaculumnOfUpdateRow) throws FileNotFoundException, IOException { String[] sets = tablePath.split("/"); int rowInsertIndex = Integer.valueOf(pageIndex); File fileDBTable = new File(tablePath); if (fileDBTable.isDirectory()) { String DBTableRowsPath = tablePath + "/rows"; File fileDBTableRowsPath = new File(DBTableRowsPath); if (fileDBTableRowsPath.isDirectory()) { String DBTableRowIndexPath = DBTableRowsPath + "/row" + rowInsertIndex ; File readDBTableRowIndexFile = new File(DBTableRowIndexPath); if (readDBTableRowIndexFile.exists()) { readDBTableRowIndexFile.mkdir(); Iterator it = jaculumnOfUpdateRow.keys(); while(it.hasNext()) { String culumnName = it.next(); String culumnValue = jaculumnOfUpdateRow.getString(culumnName); String needCreatCulumnPath = DBTableRowIndexPath + "/" + culumnName; File needCreatCulumn = new File(needCreatCulumnPath); needCreatCulumn.delete(); needCreatCulumn.mkdir(); File needCreatCulumnFile = new File(needCreatCulumnPath + "/value.lyg"); needCreatCulumnFile.delete(); FileWriter fw = null; try { fw = new FileWriter(needCreatCulumnPath + "/value.lyg", true); fw.write(null == culumnValue?"":culumnValue); fw.close(); //fix buffer refresh Cell cell = new Cell(); cell.I_CellValue(null == culumnValue ? "" : culumnValue); DetaDBBufferCache_M.db.getBase(sets[sets.length - 2]) .getTable(sets[sets.length - 1]).getRow("row" + pageIndex).putCell(culumnName, cell); } catch (IOException e) { e.printStackTrace(); } } } } } Map output = new HashMap<>(); output.put("totalPages", rowInsertIndex); return output; } public static Map updateRowByTablePathAndAttribute(String tablePath , String culumnName, String culumnValue, JSONObject jobj) throws IOException { String[] sets = tablePath.split("/"); File fileDBTable = new File(tablePath); if (fileDBTable.isDirectory()) { String DBTableRowsPath = tablePath + "/rows"; File fileDBTableRowsPath = new File(DBTableRowsPath); if (fileDBTableRowsPath.isDirectory()) { Here: for(int i = 0; i < fileDBTableRowsPath.list().length; i++) { String DBTableRowIndexPath = DBTableRowsPath + "/row" + i; File readDBTableRowIndexFile = new File(DBTableRowIndexPath); if (readDBTableRowIndexFile.exists()) { readDBTableRowIndexFile.mkdir(); File check = new File(DBTableRowIndexPath + "/" + culumnName + "/value.lyg"); if(!check.exists()) { continue Here; } BufferedReader reader = new BufferedReader(new FileReader(check)); String temp = ""; String tempString; while ((tempString = reader.readLine()) != null) { temp += tempString; } reader.close(); if(!temp.equalsIgnoreCase(culumnValue)) { continue Here; } Iterator it = jobj.keys(); while(it.hasNext()) { String culumnNameOfjs = it.next(); String culumnValueOfjs = jobj.get(culumnNameOfjs).toString(); String needCreatCulumnPath = DBTableRowIndexPath + "/" + culumnNameOfjs; File needCreatCulumn = new File(needCreatCulumnPath); needCreatCulumn.delete(); needCreatCulumn.mkdir(); File needCreatCulumnFile = new File(needCreatCulumnPath + "/value.lyg"); needCreatCulumnFile.delete(); FileWriter fw = null; try { fw = new FileWriter(needCreatCulumnPath + "/value.lyg", true); fw.write(null == culumnValueOfjs? "" : culumnValueOfjs); fw.close(); //fix buffer refresh Cell cell = new Cell(); cell.I_CellValue(null == culumnValueOfjs ? "" : culumnValueOfjs); DetaDBBufferCache_M.db.getBase(sets[sets.length - 2]) .getTable(sets[sets.length - 1]).getRow("row" + i).putCell(culumnNameOfjs, cell); } catch (IOException e) { e.printStackTrace(); } } } } } } Map output = new HashMap<>(); return output; } public static Object updateRowsByRecordConditions(Map object, boolean mod) throws IOException { String DBPath = Cache_M.getCacheInfo("DBPath").getValue().toString() + "/" + object.get("baseName").toString(); String DBtablePath = DBPath + "/" + object.get("tableName").toString(); String DBTableRowsPath = DBtablePath + "/rows"; List> updateObj = (List>)object.get("updateObj"); Iterator> updateObjIterator = updateObj.iterator(); List culumnValues = (List) object.get("culumnValue"); Iterator culumnValuesIterator = culumnValues.iterator(); while(updateObjIterator.hasNext()) { Map objRow = updateObjIterator.next(); Map objCells = (Map) objRow.get(StableShellETL.SHELL_ETL_ROWVALUE); Map onjCell = (Map) objCells.get("Index"); String rowIndex = "row"; rowIndex += onjCell.get("culumnValue").toString(); while(culumnValuesIterator.hasNext()) { String[] culumns = culumnValuesIterator.next(); String filePath = DBTableRowsPath + "/" + rowIndex + "/" +culumns[1] + "/value.lyg"; File currentCellChange = new File(filePath); if(currentCellChange.exists()) { if(mod) { currentCellChange.delete(); FileWriter fw = null; try { fw = new FileWriter(filePath, true); fw.write(culumns[2]); fw.close(); } catch (IOException e) { fw.close(); e.printStackTrace(); } } Cell cell = new Cell(); cell.I_CellValue(culumns[2]); Row row = DetaDBBufferCache_M.db.getBase(object.get("baseName").toString()) .getTable(object.get("tableName").toString()).getRow(rowIndex); if(mod) { row.putCell(culumns[1], cell); } } } } return object; } public static Object updateRowsByAttributesOfCondition(Map object , boolean mod) 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); }else if(DetaDBBufferCache_M.dbCache){ P_ConditionPLSQL_XCDX_Cache.P_Cache(sets, output , object.get("tableName").toString() , object.get("baseName").toString(), object); }else { P_ConditionPLSQL_XCDX_Table.P_Table(sets, output, DBTablePath, object); } } } } } } return output; } public static List> updateRowsByAttributesOfAggregation(Map object, boolean mod) { if(!object.containsKey("obj")) { return new ArrayList<>(); } List> obj = ((List>)(object.get("updateObj"))); 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 updateRowsByAttributesOfGetCulumns(Map object) { if(!object.containsKey("obj")) { return new ArrayList<>(); } List> obj = ((List>)(object.get("updateObj"))); 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; } }