001package gudusoft.gsqlparser.dlineage.dataflow.model.xml; 002 003import gudusoft.gsqlparser.dlineage.dataflow.model.ModelBindingManager; 004import gudusoft.gsqlparser.dlineage.dataflow.model.json.Coordinate; 005import gudusoft.gsqlparser.dlineage.util.DlineageUtil; 006import gudusoft.gsqlparser.sqlenv.ESQLDataObjectType; 007import gudusoft.gsqlparser.sqlenv.TSQLEnv; 008import gudusoft.gsqlparser.util.SQLUtil; 009 010import javax.xml.bind.annotation.XmlAttribute; 011import javax.xml.bind.annotation.XmlElement; 012import javax.xml.bind.annotation.XmlTransient; 013import javax.xml.bind.annotation.XmlType; 014import java.util.ArrayList; 015import java.util.LinkedHashSet; 016import java.util.List; 017 018@XmlType( 019 propOrder = {"id", "server", "userName", "database", "schema", "name", "displayName", "alias", "uri", "type", "subType", 020 "processIds", "fileType", "fileFormat", "location", "namespace", "isTarget", "coordinate", "columns", "parent", "more", "fromDDL"} 021) 022public class table implements Cloneable { 023 024 private String id; 025 026 private String server; 027 028 private String userName; 029 030 private String database; 031 032 private String schema; 033 034 private String name; 035 036 private String displayName; 037 038 private String alias; 039 040 private String type; 041 042 private String subType; 043 044 private String uri; 045 046 private List<String> processIds; 047 048 private String isTarget; 049 050 private StringBuffer coordinate = new StringBuffer(); 051 052 private List<column> columns; 053 054 private String parent; 055 056 private String fileType; 057 058 private String fileFormat; 059 060 private String location; 061 062 private String namespace; 063 064 @XmlTransient 065 private String starStmt; 066 067 private Boolean more; 068 069 @XmlTransient 070 private String isDetermined; 071 072 private String fromDDL; 073 074 @XmlTransient 075 private LinkedHashSet<String> coordinateItems = new LinkedHashSet<String>(); 076 077 @XmlAttribute(required = false) 078 public String getAlias() { 079 return alias; 080 } 081 082 public void setAlias(String alias) { 083 this.alias = alias; 084 } 085 086 @XmlElement(name = "column", required = false) 087 public List<column> getColumns() { 088 if (this.columns == null) { 089 this.columns = new ArrayList<column>(); 090 } 091 return columns; 092 } 093 094 public void setColumns(List<column> columns) { 095 this.columns = columns; 096 } 097 098 @XmlAttribute(required = false) 099 public String getCoordinate() { 100 String result = coordinate.toString(); 101 if (SQLUtil.isEmpty(result)) 102 return null; 103 return result; 104 } 105 106 public void appendCoordinate(String coordinate) { 107 if (!coordinateItems.contains(coordinate)) { 108 coordinateItems.add(coordinate); 109 if (!ModelBindingManager.getGlobalOption().isTraceTablePosition()) { 110 this.coordinate.setLength(0); 111 for (String item : coordinateItems) { 112 if (this.coordinate.length() > 0) { 113 if (item.indexOf("-1") != -1) { 114 continue; 115 } 116 this.coordinate.append(","); 117 } 118 this.coordinate.append(item); 119 } 120 } else { 121 if (this.coordinate.length() > 0) { 122 if (coordinate.indexOf("-1") == -1) { 123 this.coordinate.append(","); 124 } 125 } 126 if (coordinate.indexOf("-1") == -1) { 127 this.coordinate.append(coordinate); 128 } 129 } 130 } 131 } 132 133 public void setCoordinate(String coordinate) { 134 if (SQLUtil.isEmpty(coordinate)) { 135 return; 136 } 137 this.coordinate.setLength(0); 138 this.coordinate.append(coordinate); 139 } 140 141 public void clearCoordinate() { 142 this.coordinate = new StringBuffer(); 143 } 144 145 @XmlAttribute(required = false) 146 public String getUserName() { 147 return userName; 148 } 149 150 public void setUserName(String userName) { 151 this.userName = userName; 152 } 153 154 @XmlAttribute(required = false) 155 public String getServer() { 156 return server; 157 } 158 159 public void setServer(String server) { 160 this.server = server; 161 } 162 163 @XmlAttribute(required = false) 164 public String getName() { 165 return name; 166 } 167 168 public void setName(String name) { 169 this.name = name; 170 } 171 172 @XmlAttribute(required = false) 173 public String getDisplayName() { 174 return displayName; 175 } 176 177 public void setDisplayName(String displayName) { 178 this.displayName = displayName; 179 } 180 181 @XmlAttribute(required = false) 182 public String getId() { 183 return id; 184 } 185 186 public void setId(String id) { 187 this.id = id; 188 } 189 190 @XmlAttribute(required = false) 191 public List<String> getProcessIds() { 192 return processIds; 193 } 194 195 public void setProcessIds(List<String> processIds) { 196 this.processIds = processIds; 197 } 198 199 @XmlAttribute(required = false) 200 public String getType() { 201 return type; 202 } 203 204 public void setType(String type) { 205 this.type = type; 206 } 207 208 @XmlAttribute(required = false) 209 public String getUri() { 210 return uri; 211 } 212 213 public void setUri(String uri) { 214 this.uri = uri; 215 } 216 217 @XmlAttribute(required = false) 218 public String getFileType() { 219 return fileType; 220 } 221 222 public void setFileType(String fileType) { 223 this.fileType = fileType; 224 } 225 226 @XmlAttribute(required = false) 227 public String getFileFormat() { 228 return fileFormat; 229 } 230 231 public void setFileFormat(String fileFormat) { 232 this.fileFormat = fileFormat; 233 } 234 235 @XmlAttribute(required = false) 236 public String getLocation() { 237 return location; 238 } 239 240 public void setLocation(String location) { 241 this.location = location; 242 } 243 244 @XmlAttribute(required = false) 245 public String getNamespace() { 246 return namespace; 247 } 248 249 public void setNamespace(String namespace) { 250 this.namespace = namespace; 251 } 252 253 @XmlTransient 254 public String getStarStmt() { 255 return starStmt; 256 } 257 258 public void setStarStmt(String starStmt) { 259 this.starStmt = starStmt; 260 } 261 262 @XmlTransient 263 public String getIsDetermined() { 264 return isDetermined; 265 } 266 267 public void setIsDetermined(String isDetermined) { 268 this.isDetermined = isDetermined; 269 } 270 271 public boolean isFunction() { 272 return "function".equals(type) || "function".equals(subType); 273 } 274 275 public boolean isView() { 276 return "view".equals(type); 277 } 278 279 public boolean isDatabaseType() { 280 return "database".equals(type); 281 } 282 283 public boolean isSchemaType() { 284 return "schema".equals(type); 285 } 286 287 public boolean isSequence() { 288 return "sequence".equals(type); 289 } 290 291 public boolean isStage() { 292 return "stage".equals(type); 293 } 294 295 public boolean isDataSource() { 296 return "dataSource".equals(type); 297 } 298 299 public boolean isStream() { 300 return "stream".equals(type); 301 } 302 303 public boolean isVariable() { 304 return "variable".equals(type); 305 } 306 307 public boolean isCursor() { 308 return "cursor".equals(type); 309 } 310 311 public boolean isFile() { 312 return "file".equals(type) || "path".equals(type); 313 } 314 315 public boolean isTable() { 316 return "table".equals(type) || "pseudoTable".equals(type) || "constantTable".equals(type); 317 } 318 319 public boolean isPseudoTable() { 320 return "pseudoTable".equals(type); 321 } 322 323 public boolean isConstantTable() { 324 return "pseudoTable".equals(type); 325 } 326 327 public boolean isResultSet() { 328 return type != null && !isView() && !isCursor() && !isTable() && !isStage() && !isSequence() && !isDataSource() && !isDatabaseType() && !isSchemaType() && !isStream() && !isVariable() && !isFile(); 329 } 330 331 @XmlAttribute(name = "isTarget", required = false) 332 public String getIsTarget() { 333 return isTarget; 334 } 335 336 public boolean isTarget() { 337 return "true".equals(isTarget); 338 } 339 340 @XmlAttribute(required = false) 341 public String getParent() { 342 return parent; 343 } 344 345 public void setParent(String parent) { 346 this.parent = parent; 347 } 348 349 @XmlAttribute(required = false) 350 public String getDatabase() { 351 return database; 352 } 353 354 public void setDatabase(String database) { 355 if (SQLUtil.parseNames(database).size() > 1) { 356 database = "\"" + database + "\""; 357 } 358 this.database = database; 359 } 360 361 @XmlAttribute(required = false) 362 public String getSchema() { 363 return schema; 364 } 365 366 public void setSchema(String schema) { 367 if (SQLUtil.parseNames(schema).size() > 1) { 368 schema = "\"" + schema + "\""; 369 } 370 this.schema = schema; 371 } 372 373 @XmlAttribute(required = false) 374 public String getSubType() { 375 return subType; 376 } 377 378 public void setSubType(String subType) { 379 this.subType = subType; 380 } 381 382 public String getFullName() { 383 if (isDatabaseType()) { 384 return database; 385 } 386 StringBuilder fullName = new StringBuilder(); 387 if (!SQLUtil.isEmpty(database)) { 388 fullName.append(database).append("."); 389 } 390 if (!SQLUtil.isEmpty(schema)) { 391 fullName.append(schema).append("."); 392 } 393 if (fullName.length() > 0) { 394 fullName.append(getTableNameOnly()); 395 } else { 396 fullName.append(name); 397 } 398 return fullName.toString(); 399 } 400 401 public String getFullSchemaName() { 402 StringBuilder fullName = new StringBuilder(); 403 if (!SQLUtil.isEmpty(database)) { 404 if(ModelBindingManager.getGlobalVendor()!=null) { 405 fullName.append(DlineageUtil.getIdentifierNormalName(database, ESQLDataObjectType.dotCatalog)).append("."); 406 } 407 else{ 408 fullName.append(database).append("."); 409 } 410 } 411 if (!SQLUtil.isEmpty(schema)) { 412 if(ModelBindingManager.getGlobalVendor()!=null) { 413 fullName.append(DlineageUtil.getIdentifierNormalName(schema, ESQLDataObjectType.dotSchema)); 414 } 415 else { 416 fullName.append(schema).append("."); 417 } 418 } 419 String fullSchemaName = fullName.toString(); 420 if (fullSchemaName.endsWith(".")) { 421 fullSchemaName = fullSchemaName.substring(0, fullSchemaName.length() - 1); 422 } 423 if (fullSchemaName.length() == 0) { 424 fullSchemaName = TSQLEnv.DEFAULT_SCHEMA_NAME; 425 } 426 return fullSchemaName; 427 } 428 429 public String getTableNameOnly() { 430 if (name.indexOf("@") != -1 && SQLUtil.trimColumnStringQuote(name.substring(name.lastIndexOf("@") + 1).trim()).equals(SQLUtil.trimColumnStringQuote(database))) { 431 List<String> segments = SQLUtil.parseNames(name.substring(0, name.lastIndexOf("@")).trim()); 432 if (segments.size() > 2) { 433 return SQLUtil.mergeSegments(segments, 2); 434 } 435 return segments.get(segments.size() - 1); 436 } else { 437 List<String> segments = SQLUtil.parseNames(name); 438 if (segments.size() > 2) { 439 return SQLUtil.mergeSegments(segments, 2); 440 } 441 return segments.get(segments.size() - 1); 442 } 443 } 444 445 public void setIsTarget(String isTarget) { 446 this.isTarget = isTarget; 447 } 448 449 public int getOccurrencesNumber() { 450 return PositionUtil.getOccurrencesNumber(coordinate.toString()); 451 } 452 453 public Coordinate getStartPos(int index) { 454 return PositionUtil.getStartPos(coordinate.toString(), index); 455 } 456 457 public Coordinate getEndPos(int index) { 458 return PositionUtil.getEndPos(coordinate.toString(), index); 459 } 460 461 public Boolean getMore() { 462 return more; 463 } 464 465 public void setMore(Boolean more) { 466 this.more = more; 467 } 468 469 @XmlAttribute(required = false) 470 public String getFromDDL() { 471 return fromDDL; 472 } 473 474 public void setFromDDL(String fromDDL) { 475 this.fromDDL = fromDDL; 476 } 477 478 @Override 479 public Object clone() throws CloneNotSupportedException { 480 return super.clone(); 481 } 482}