1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.jdbc.sql.SqlDriver; 15 import com.versant.core.jdbc.metadata.JdbcColumn; 16 import com.versant.core.util.CharBuf; 17 import com.versant.core.common.Debug; 18 19 import java.util.Map ; 20 21 import com.versant.core.common.BindingSupportImpl; 22 23 26 public class JoinExp extends LeafExp { 27 28 private JdbcColumn left; 29 private SelectExp leftTable; 30 private JdbcColumn right; 31 private SelectExp rightTable; 32 33 public JoinExp(JdbcColumn left, SelectExp leftTable, 34 JdbcColumn right, SelectExp rightTable) { 35 if (Debug.DEBUG) { 36 if (left.table != leftTable.table) { 37 throw BindingSupportImpl.getInstance().internal("The column's table is not " + 38 "the same as the table being joined from"); 39 } 40 41 if (right.table != rightTable.table) { 42 throw BindingSupportImpl.getInstance().internal("The column's table is not " + 43 "the same as the table being joined too"); 44 } 45 } 46 this.left = left; 47 this.leftTable = leftTable; 48 this.right = right; 49 this.rightTable = rightTable; 50 } 51 52 public void setLeftTable(SelectExp leftSExp) { 53 leftTable = leftSExp; 54 } 55 56 public JoinExp() { 57 } 58 59 public SqlExp createInstance() { 60 return new JoinExp(); 61 } 62 63 public SqlExp getClone(SqlExp clone, Map cloneMap) { 64 super.getClone(clone, cloneMap); 65 JoinExp cst = (JoinExp) clone; 66 67 cst.left = left; 68 if (leftTable != null) cst.leftTable = (SelectExp) createClone(leftTable, cloneMap); 69 cst.right = right; 70 if (rightTable != null) cst.rightTable = (SelectExp) createClone(rightTable, cloneMap); 71 72 return clone; 73 } 74 75 public String toString() { 76 return super.toString() + " " + left + " = " + right; 77 } 78 79 86 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 87 driver.appendSqlJoin(leftTable.alias, left, 88 rightTable.alias, right, rightTable.outer, s); 89 } 90 91 97 public void setOuter(boolean on) { 98 rightTable.outer = on; 99 } 100 101 public boolean isOuter() { 102 return rightTable.outer; 103 } 104 105 111 public void replaceSelectExpRef(SelectExp old, SelectExp nw) { 112 if (old == leftTable) leftTable = nw; 113 if (old == rightTable) rightTable = nw; 114 } 115 116 public static boolean isEqual(JoinExp jExp1, JoinExp jExp2) { 117 if (jExp1 == jExp2) return true; 118 if (jExp1 == null) return false; 119 if (jExp2 == null) return false; 120 121 if ((jExp1.left == jExp2.left) 122 && (jExp1.right == jExp2.right) 123 && (jExp1.isOuter() == jExp2.isOuter())) { 124 return true; 125 } 126 return false; 127 128 } 129 } 130 131 | Popular Tags |