001package gudusoft.gsqlparser.nodes; 002 003import gudusoft.gsqlparser.IRelation; 004import gudusoft.gsqlparser.TAttributeNode; 005import gudusoft.gsqlparser.TBaseType; 006import gudusoft.gsqlparser.TLog; 007 008 009import java.util.ArrayList; 010 011public class TFromClause extends TNodeWithAliasClause implements IRelation { 012 013 014 015 private ArrayList<TAttributeNode> relationAttributes; 016// public ArrayList<TObjectName> getReferenceAttributes(){ 017// return null; 018// } 019 020 @Override 021 public ArrayList<TAttributeNode> getAttributes(){ 022 // if (!relationAttributes.isEmpty()) return relationAttributes; 023 if (relationAttributes == null) { 024 relationAttributes = new ArrayList<>(); 025 } 026 for(TTable table:relations){ 027 //relationAttributes.addAll(table.getAttributes()); 028 TAttributeNode.addAllNodesToList(table.getAttributes(),relationAttributes); 029 } 030 031 return relationAttributes; 032 } 033 034 @Override 035 public String getRelationName(){ 036 return null; 037 } 038 039 @Override 040 public int size(){ 041 return relationAttributes != null ? relationAttributes.size() : 0; 042 } 043 044 public void collectAttributes(){ 045 if (relationAttributes == null) { 046 relationAttributes = new ArrayList<>(); 047 } 048 relationAttributes.clear(); 049 for(TTable table:relations){ 050 //relationAttributes.addAll(table.getAttributes()); 051 TAttributeNode.addAllNodesToList(table.getAttributes(),relationAttributes); 052 } 053 054 TBaseType.log(String.format("Prepare attributes for from clause: %s",this.toString()), TLog.DEBUG,this.getStartToken()); 055 for(TAttributeNode node:relationAttributes){ 056 TBaseType.log(String.format("\tAttriubte: %s",node.getName()),TLog.DEBUG); 057 } 058 } 059 060 061 062 063 public TFromClause(ArrayList<TTable> relations){ 064 this.relations = relations != null ? relations : new ArrayList<>(); 065 } 066 067 public ArrayList<TTable> getRelations() { 068 if (relations == null) { 069 relations = new ArrayList<>(); 070 } 071 return relations; 072 } 073 074 private ArrayList<TTable> relations; 075 076 public void accept(TParseTreeVisitor v) 077 { 078 v.preVisit(this); 079 v.postVisit(this); 080 } 081 082 /** 083 * Accept visitor to visit this class. 084 * @param v user defined visitor. 085 */ 086 public void acceptChildren(TParseTreeVisitor v) 087 { 088 v.preVisit(this); 089 for(TTable table:relations){ 090 table.acceptChildren(v); 091 } 092 v.postVisit(this); 093 } 094 095}