1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import java.util.Map ; 15 16 20 public class Join { 21 22 25 public SelectExp selectExp; 26 29 public SqlExp exp; 30 33 public Join next; 34 private Join mergedWith; 35 36 public Join() { 37 } 38 39 public Join getClone(Map cloneMap) { 40 Join clone = new Join(); 41 if (selectExp != null) clone.selectExp = (SelectExp) SqlExp.createClone(selectExp, cloneMap); 42 if (exp != null) clone.exp = SqlExp.createClone(exp, cloneMap); 43 if (next != null) clone.next = next.getClone(cloneMap); 44 return clone; 45 } 46 47 public String toString() { 48 return "Join@" + System.identityHashCode(this) + " " + selectExp; 49 } 50 51 54 public void dump(String indent) { 55 System.out.println(indent + this); 56 indent = indent + " "; 57 if (exp == null) { 58 System.out.println(indent + " exp is NULL"); 59 } else { 60 exp.dump(indent); 61 } 62 selectExp.dump(indent); 63 } 64 65 68 public void dumpList(String indent) { 69 dump(indent); 70 for (Join j = next; j != null; j = j.next) j.dump(indent); 71 } 72 73 76 public int createAlias(int index) { 77 if (mergedWith != null) { 78 index = mergedWith.createAlias(index); 79 selectExp.alias = mergedWith.selectExp.alias; 80 } 81 82 index = selectExp.createAlias(index); 83 if (exp != null) { 84 return exp.createAlias(index); 85 } else { 86 return index; 87 } 88 } 89 90 94 public void appendJoinExp(SqlExp e) { 95 if (exp == null) { 96 exp = e; 97 } else if (exp instanceof AndExp) { 98 exp.append(e); 99 } else { 100 AndExp ae = new AndExp(exp); 101 exp.next = e; 102 exp = ae; 103 } 104 } 105 106 110 public Join findDeepestJoin() { 111 if (selectExp.joinList == null) return this; 112 Join j; 113 for (j = selectExp.joinList; j.next != null; j = j.next); 114 return j.findDeepestJoin(); 115 } 116 117 120 public static boolean isEqaul(Join j1, Join j2) { 121 if (j1 == j2) return true; 122 if (j1 == null) return false; 123 if (j2 == null) return false; 124 125 if (j1.selectExp != null && j2.selectExp != null) { 126 if (j1.selectExp.jdbcField == j2.selectExp.jdbcField) { 127 if (j1.exp instanceof JoinExp && j2.exp instanceof JoinExp) { 128 if (JoinExp.isEqual((JoinExp)j1.exp, (JoinExp)j2.exp)) { 129 if (isEqaul(j1.selectExp.joinList, j2.selectExp.joinList)) { 130 return Join.isEqaul(j1.next, j2.next); 131 } 132 } 133 } 134 } 135 } 136 return false; 137 } 138 139 142 public static boolean isCurrentEqaul(Join j1, Join j2) { 143 if (j1 == j2) return true; 144 if (j1 == null) return false; 145 if (j2 == null) return false; 146 147 if (j1.selectExp != null && j2.selectExp != null) { 148 if (j1.selectExp.jdbcField == j2.selectExp.jdbcField) { 149 if (j1.exp instanceof JoinExp && j2.exp instanceof JoinExp) { 150 return JoinExp.isEqual((JoinExp)j1.exp, (JoinExp)j2.exp); 151 } 152 } 153 } 154 return false; 155 } 156 157 160 public boolean isMerged() { 161 return mergedWith != null; 162 } 163 164 public Join getMergedWith() { 165 return mergedWith; 166 } 167 168 public void setMergedWith(Join mergedWith) { 169 this.mergedWith = mergedWith; 170 } 171 } 172 | Popular Tags |