1 2 12 package com.versant.core.jdbc; 13 14 import com.versant.core.metadata.FetchGroupField; 15 import com.versant.core.metadata.MDStatics; 16 import com.versant.core.metadata.FetchGroup; 17 18 import java.util.List ; 19 import java.util.ArrayList ; 20 21 26 public class JoinStructure implements Comparable { 27 public FetchGroupField fgField; 28 public JoinStructure parent; 29 public boolean refField; 30 public int level = 1; 31 32 public FetchGroupField[] fgFields; 33 36 public boolean rootJoinStructure; 37 41 public List colJoinStructs; 42 public FetchGroup fetchGroup; 43 private boolean finished; 44 45 public JoinStructure(FetchGroup fg) { 46 rootJoinStructure = true; 47 colJoinStructs = new ArrayList (); 48 this.fetchGroup = fg; 49 } 50 51 public JoinStructure(JoinStructure parent, FetchGroupField field) { 52 this.fgField = field; 53 this.setParent(parent); 54 this.refField = (field.fmd.category == MDStatics.CATEGORY_REF); 55 if (!refField) { 56 addColJoinStruct(this); 57 } 58 } 59 60 public boolean isRefField() { 61 return refField; 62 } 63 64 67 public void finish() { 68 if (finished) return; 69 finished = true; 70 List structs = colJoinStructs; 71 if (structs == null) return; 72 for (int i = 0; i < structs.size(); i++) { 73 JoinStructure js = (JoinStructure) structs.get(i); 74 js.finishImp(); 75 } 76 } 77 78 private void finishImp() { 79 fgFields = new FetchGroupField[level - 1]; 80 appendTo(fgFields); 81 } 82 83 private void appendTo(FetchGroupField[] fgFArray) { 84 if (rootJoinStructure) return; 85 fgFArray[level - 2] = fgField; 86 parent.appendTo(fgFArray); 87 } 88 89 private void addColJoinStruct(JoinStructure js) { 90 if (rootJoinStructure) { 91 colJoinStructs.add(js); 92 } else { 93 parent.addColJoinStruct(js); 94 } 95 } 96 97 private void setParent(JoinStructure joinStructure) { 98 if (joinStructure != null) { 99 parent = joinStructure; 100 level = parent.level + 1; 101 } 102 } 103 104 public int compareTo(Object o) { 105 JoinStructure other = (JoinStructure) o; 106 return level - other.level; 107 } 108 109 public String toString() { 110 if (rootJoinStructure) { 111 return "JoinStructure2@" + System.identityHashCode(this) + " for ROOT"; 112 } else { 113 return "JoinStructure2@" + System.identityHashCode(this) + " for " + fgField.fmd.name + " ref " + isRefField(); 114 } 115 } 116 117 public void dump(String indent) { 118 System.out.println(indent + "this = " + this + " finished " + finished); 119 if (colJoinStructs == null) return; 120 for (int i = 0; i < colJoinStructs.size(); i++) { 121 JoinStructure joinStructure = (JoinStructure) colJoinStructs.get(i); 122 joinStructure.dump(indent + " "); 123 } 124 } 125 } 126 | Popular Tags |