001package gudusoft.gsqlparser.dlineage.metadata; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import gudusoft.gsqlparser.util.SQLUtil; 007 008public class Schema extends TreeNode { 009 010 private String name; 011 private List<Synonym> synonyms; 012 private List<Sequence> sequences; 013 private List<Table> tables; 014 private List<Table> views; 015 private List<Table> others; 016 private List<Package> packages; 017 private List<Procedure> procedures; 018 private List<Procedure> functions; 019 private List<Procedure> triggers; 020 private List<Process> processes; 021 022 public String getName() { 023 return name; 024 } 025 026 public void setName(String name) { 027 if (SQLUtil.parseNames(name).size() > 1) { 028 name = "\"" + name + "\""; 029 } 030 this.name = name; 031 } 032 033 public List<Table> getTables() { 034 return tables; 035 } 036 037 public List<Table> getViews() { 038 return views; 039 } 040 041 public void appendTables(List<Table> tables) { 042 if (tables == null) { 043 return; 044 } 045 046 List<Table> tableList = new ArrayList<Table>(); 047 List<Table> viewList = new ArrayList<Table>(); 048 List<Table> otherList = new ArrayList<Table>(); 049 for (Table table : tables) { 050 if (table.getType() == null) { 051 continue; 052 } 053 if ("view".equalsIgnoreCase(table.getType()) || "materialized view".equalsIgnoreCase(table.getType())) { 054 viewList.add(table); 055 } else if ("table".equalsIgnoreCase(table.getType())) { 056 tableList.add(table); 057 } else { 058 otherList.add(table); 059 } 060 } 061 062 if (!tableList.isEmpty()) { 063 if (this.tables != null) { 064 this.tables.addAll(tableList); 065 } else { 066 this.tables = tableList; 067 } 068 } 069 070 if (!viewList.isEmpty()) { 071 if (this.views != null) { 072 this.views.addAll(viewList); 073 } else { 074 this.views = viewList; 075 } 076 } 077 078 if (!otherList.isEmpty()) { 079 if (this.others != null) { 080 this.others.addAll(otherList); 081 } else { 082 this.others = otherList; 083 } 084 } 085 } 086 087 public void appendViews(List<Table> views) { 088 if (views == null) { 089 return; 090 } 091 092 List<Table> viewList = new ArrayList<Table>(); 093 for (Table table : views) { 094 if (table.getType() == null) { 095 continue; 096 } 097 if ("view".equalsIgnoreCase(table.getType()) || "materialized view".equalsIgnoreCase(table.getType())) { 098 viewList.add(table); 099 } 100 } 101 102 if (!viewList.isEmpty()) { 103 if (this.views != null) { 104 this.views.addAll(viewList); 105 } else { 106 this.views = viewList; 107 } 108 } 109 } 110 111 public List<Synonym> getSynonyms() { 112 return synonyms; 113 } 114 115 public void setSynonyms(List<Synonym> synonyms) { 116 if (this.synonyms != null) { 117 this.synonyms.addAll(synonyms); 118 } else { 119 this.synonyms = synonyms; 120 } 121 } 122 123 public List<Sequence> getSequences() { 124 return sequences; 125 } 126 127 public void setSequences(List<Sequence> sequences) { 128 if (this.sequences != null) { 129 this.sequences.addAll(sequences); 130 } else { 131 this.sequences = sequences; 132 } 133 } 134 135 public List<Package> getPackages() { 136 return packages; 137 } 138 139 public void setPackages(List<Package> packages) { 140 if (this.packages != null) { 141 this.packages.addAll(packages); 142 } else { 143 this.packages = packages; 144 } 145 } 146 147 public List<Procedure> getProcedures() { 148 return procedures; 149 } 150 151 public void setProcedures(List<Procedure> procedures) { 152 if (this.procedures != null) { 153 this.procedures.addAll(procedures); 154 } else { 155 this.procedures = procedures; 156 } 157 } 158 159 public List<Procedure> getFunctions() { 160 return functions; 161 } 162 163 public void setFunctions(List<Procedure> functions) { 164 if (this.functions != null) { 165 this.functions.addAll(functions); 166 } else { 167 this.functions = functions; 168 } 169 } 170 171 public List<Procedure> getTriggers() { 172 return triggers; 173 } 174 175 public void setTriggers(List<Procedure> triggers) { 176 if (this.triggers != null) { 177 this.triggers.addAll(triggers); 178 } else { 179 this.triggers = triggers; 180 } 181 } 182 183 public void appendTable(Table table) { 184 if (table == null || table.getType() == null) { 185 return; 186 } 187 if ("view".equalsIgnoreCase(table.getType()) || "materialized view".equalsIgnoreCase(table.getType())) { 188 if (views == null) { 189 views = new ArrayList<Table>(); 190 } 191 views.add(table); 192 } else if ("table".equalsIgnoreCase(table.getType())) { 193 if (tables == null) { 194 tables = new ArrayList<Table>(); 195 } 196 tables.add(table); 197 } else { 198 if (others == null) { 199 others = new ArrayList<Table>(); 200 } 201 others.add(table); 202 } 203 } 204 205 public void appendPackage(Package oraclePackage) { 206 if (packages == null) { 207 packages = new ArrayList<Package>(); 208 } 209 packages.add(oraclePackage); 210 } 211 212 public void appendProcedure(Procedure procedure) { 213 if (procedure == null || procedure.getType() == null) { 214 return; 215 } 216 if (procedure.getType().toLowerCase().indexOf("function") != -1) { 217 if (functions == null) { 218 functions = new ArrayList<Procedure>(); 219 } 220 procedure.setType("function"); 221 functions.add(procedure); 222 } else if (procedure.getType().toLowerCase().indexOf("trigger") != -1) { 223 if (triggers == null) { 224 triggers = new ArrayList<Procedure>(); 225 } 226 procedure.setType("trigger"); 227 triggers.add(procedure); 228 } else { 229 if (procedures == null) { 230 procedures = new ArrayList<Procedure>(); 231 } 232 procedure.setType("procedure"); 233 procedures.add(procedure); 234 } 235 } 236 237 public List<Table> getOthers() { 238 return others; 239 } 240 241 public void appendOthers(List<Table> others) { 242 if (!others.isEmpty()) { 243 if (this.others != null) { 244 this.others.addAll(others); 245 } else { 246 this.others = others; 247 } 248 } 249 } 250 251 public void setTables(List<Table> tables) { 252 this.tables = tables; 253 } 254 255 public void setViews(List<Table> views) { 256 this.views = views; 257 } 258 259 public void setOthers(List<Table> others) { 260 this.others = others; 261 } 262 263 public List<Process> getProcesses() { 264 return processes; 265 } 266 267 public void setProcesses(List<Process> processes) { 268 this.processes = processes; 269 } 270 271 public void appendProcess(Process process) { 272 if (process == null) { 273 return; 274 } 275 if (processes == null) { 276 processes = new ArrayList<Process>(); 277 } 278 processes.add(process); 279 } 280}