001package gudusoft.gsqlparser.ir.builder.common; 002 003import gudusoft.gsqlparser.TStatementList; 004import gudusoft.gsqlparser.ir.bound.BoundObjectRef; 005import gudusoft.gsqlparser.ir.bound.BoundRoutineRef; 006import gudusoft.gsqlparser.ir.common.Confidence; 007import gudusoft.gsqlparser.ir.common.SourceAnchor; 008 009import java.util.Collections; 010import java.util.List; 011 012/** 013 * Result of analyzing a single dynamic SQL occurrence. 014 * <p> 015 * Stored as a first-class sidecar collection on {@code BoundProgram} 016 * via {@code getDynamicSqlExtractions()}. 017 */ 018public final class DynamicSqlExtraction { 019 020 /** 021 * Status of dynamic SQL extraction. 022 */ 023 public enum Status { 024 /** SQL was successfully parsed and refs extracted. */ 025 RESOLVED, 026 /** SQL could not be determined at analysis time. */ 027 AMBIGUOUS, 028 /** SQL text was found but parsing failed. */ 029 PARSE_ERROR 030 } 031 032 private final Status status; 033 private final String originalText; 034 private final String normalizedSql; 035 private final TStatementList stmts; 036 private final List<BoundObjectRef> objectRefs; 037 private final List<BoundRoutineRef> routineRefs; 038 private final Confidence confidence; 039 private final String reason; 040 private final String owningRoutineId; 041 private final SourceAnchor anchor; 042 043 public DynamicSqlExtraction(Status status, String originalText, String normalizedSql, 044 TStatementList stmts, 045 List<BoundObjectRef> objectRefs, 046 List<BoundRoutineRef> routineRefs, 047 Confidence confidence, String reason, 048 String owningRoutineId, SourceAnchor anchor) { 049 this.status = status; 050 this.originalText = originalText; 051 this.normalizedSql = normalizedSql; 052 this.stmts = stmts; 053 this.objectRefs = objectRefs != null 054 ? Collections.unmodifiableList(objectRefs) 055 : Collections.<BoundObjectRef>emptyList(); 056 this.routineRefs = routineRefs != null 057 ? Collections.unmodifiableList(routineRefs) 058 : Collections.<BoundRoutineRef>emptyList(); 059 this.confidence = confidence; 060 this.reason = reason; 061 this.owningRoutineId = owningRoutineId; 062 this.anchor = anchor; 063 } 064 065 public Status getStatus() { return status; } 066 public String getOriginalText() { return originalText; } 067 public String getNormalizedSql() { return normalizedSql; } 068 public TStatementList getStmts() { return stmts; } 069 public List<BoundObjectRef> getObjectRefs() { return objectRefs; } 070 public List<BoundRoutineRef> getRoutineRefs() { return routineRefs; } 071 public Confidence getConfidence() { return confidence; } 072 public String getReason() { return reason; } 073 public String getOwningRoutineId() { return owningRoutineId; } 074 public SourceAnchor getAnchor() { return anchor; } 075 076 @Override 077 public String toString() { 078 return "DynamicSqlExtraction{" + status + ", " + originalText + "}"; 079 } 080}