Advertisement
Khadija_Assem

Untitled

Nov 29th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. public commandState select(queryParsedData data) throws SQLException, IOException, SAXException, ParserConfigurationException {
  2. commandState cS = new commandState();
  3. java.sql.SQLException ex = new java.sql.SQLException();
  4. String XMLpath = data.getDataBaseName()+System.getProperty("file.separator")+data.getTableName()+".xml";
  5. cachedTable table = cachedTables.get(chashedPathes.indexOf(XMLpath));
  6.  
  7. if(chashedPathes.indexOf(XMLpath)< 0){
  8. cS.setExecuted(false);
  9. System.out.println(XMLpath + " : Schema Not found");
  10. throw ex;
  11. }else {
  12. ArrayList<ArrayList<Object>> selected = new ArrayList<>();
  13. if(!((data.getCondition().contains("="))||(data.getCondition().contains(">"))||(data.getCondition().contains("<")))){
  14. if (data.isSelectAll()){
  15. for (int i=0;i<table.getRows().size();i++) {
  16. ArrayList<Object> NEW = new ArrayList<>();
  17. String temp = new String();
  18. for(Object s : table.getRows().get(i).keySet())
  19. temp = temp.concat("\n").concat((String) table.getRows().get(i).get(s)) ;
  20. NEW.add(temp);
  21. selected.add(NEW);
  22. }
  23. }
  24. else{
  25. ArrayList<Object> NEW = new ArrayList<>();
  26. for (int i=0;i<table.getRows().size();i++) {
  27. String temp = new String();
  28. boolean flag = false;
  29. for(Object s : table.getRows().get(i).keySet()) {
  30. NEW = new ArrayList<>();
  31. for(Object S : data.getData().keySet()){
  32. if (s.equals(S)) {
  33. temp = temp.concat("\n").concat((String) table.getRows().get(i).get(s));
  34. flag = true;
  35. }
  36. }
  37. if(flag)
  38. NEW.add(temp);
  39. }
  40. }
  41. if (!NEW.isEmpty())
  42. selected.add(NEW);
  43. }
  44. cS.setArray(selected);
  45. }
  46. else{
  47. if (data.isSelectAll()){
  48. String conditionString = data.getCondition();
  49. String[] condition = conditionString.split(" *= *| *< *| *> *");
  50. boolean flag = false;
  51. ArrayList<Object> NEW = new ArrayList<>();
  52. for (int i=0;i<table.getRows().size();i++) {
  53. NEW = new ArrayList<>();
  54. String temp = new String();
  55. for(Object s : table.getRows().get(i).keySet()) {
  56. temp = new String();
  57. if (util.conditionValidator((String) s,(String) table.getRows().get(i).get(s),data)) {
  58. for(Object F : table.getRows().get(i).keySet()) {
  59. temp = temp.concat("\n").concat((String) table.getRows().get(i).get(F));
  60. flag = true;
  61. }
  62. }
  63. if (flag)
  64. NEW.add(temp);
  65. if(!(NEW.size()==0))
  66. selected.add(NEW);
  67. }
  68.  
  69. }
  70. }
  71. else{
  72. ArrayList<Object> NEW = new ArrayList<>();
  73. for (int i=0;i<table.getRows().size();i++) {
  74. String temp = new String();
  75. boolean flag = false;
  76. for(Object s : table.getRows().get(i).keySet()) {
  77. NEW = new ArrayList<>();
  78. for(Object S : data.getData().keySet()){
  79. String conditionString = data.getCondition();
  80. String[] condition = conditionString.split(" *= *| *< *| *> *");
  81. System.out.println("SELECT " + condition[0]+ " "+ s);
  82. if (condition[0].equals(s)) {
  83. flag = false;
  84. System.out.println("SELECT " + condition[0]);
  85. System.out.println("KKKKKKKKKKKK ");
  86. if (util.conditionValidator((String) s,(String) table.getRows().get(i).get(s),data)) {
  87. temp = temp.concat("\n").concat((String) table.getRows().get(i).get(s));
  88. flag = true;
  89. }
  90. if(flag)
  91. NEW.add(temp);
  92. }
  93. }
  94. if (NEW.size()!=0)
  95. selected.add(NEW);
  96. }
  97. }
  98. }
  99. cS.setArray(selected);
  100. }
  101. }
  102. System.out.println("ROWS "+table.getRows());
  103. System.out.println("VALUES "+table.getCoulmnsValues());
  104. return cS;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement