001 002package gudusoft.gsqlparser.dlineage.dataflow.model; 003 004 005import gudusoft.gsqlparser.TCustomSqlStatement; 006import gudusoft.gsqlparser.TSourceToken; 007import gudusoft.gsqlparser.dlineage.util.DlineageUtil; 008import gudusoft.gsqlparser.dlineage.util.Pair3; 009import gudusoft.gsqlparser.nodes.TParseTreeNode; 010import gudusoft.gsqlparser.util.SQLUtil; 011 012public class CallRelationship extends AbstractRelationship { 013 014 private String sqlHash; 015 private String sqlComment; 016 private Long procedureId; 017 private Boolean builtIn; 018 private TParseTreeNode callObject; 019 protected Pair3<Long, Long, String> startPosition; 020 protected Pair3<Long, Long, String> endPosition; 021 022 @Override 023 public RelationshipType getRelationshipType() { 024 return RelationshipType.call; 025 } 026 027 public String getSqlHash() { 028 return sqlHash; 029 } 030 031 public void setTarget(RelationshipElement<?> target) { 032 super.setTarget(target); 033 if(ModelBindingManager.getGlobalOption().isTraceSQL()) { 034 TCustomSqlStatement stmt = DlineageUtil.getTopStmt(ModelBindingManager.getGlobalStmtStack().peek()); 035 this.sqlHash = ModelBindingManager.get().getSqlHash(stmt); 036 try { 037 this.sqlComment = stmt.getCommentBeforeNode(); 038 } catch (Exception e) { 039 } 040 } 041 042 if(ModelBindingManager.getGlobalOption().isTraceProcedure()) { 043 TCustomSqlStatement stmt = DlineageUtil.getTopStmt(ModelBindingManager.getGlobalStmtStack().peek()); 044 Object model = ModelBindingManager.get().getModel(stmt); 045 if(model instanceof Procedure) { 046 this.procedureId = ((Procedure)model).getId(); 047 } 048 } 049 } 050 051 public String getSqlComment() { 052 return sqlComment; 053 } 054 055 public Long getProcedureId() { 056 return procedureId; 057 } 058 059 public Boolean getBuiltIn() { 060 return builtIn; 061 } 062 063 public void setBuiltIn(Boolean builtIn) { 064 this.builtIn = builtIn; 065 } 066 067 public TParseTreeNode getCallObject() { 068 return callObject; 069 } 070 071 public void setCallObject(TParseTreeNode callObject) { 072 this.callObject = callObject; 073 if (callObject != null && callObject.toString() != null) { 074 TSourceToken startToken = callObject.getStartToken(); 075 TSourceToken endToken = callObject.getEndToken(); 076 this.startPosition = new Pair3<Long, Long, String>(startToken.lineNo, startToken.columnNo, 077 ModelBindingManager.getGlobalHash()); 078 this.endPosition = new Pair3<Long, Long, String>(endToken.lineNo, 079 endToken.columnNo + SQLUtil.endTrim(endToken.astext).length(), ModelBindingManager.getGlobalHash()); 080 } 081 } 082 083 public Pair3<Long, Long, String> getStartPosition() { 084 return startPosition; 085 } 086 087 public Pair3<Long, Long, String> getEndPosition() { 088 return endPosition; 089 } 090 091}