1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.util.CharBuf; 15 import com.versant.core.jdbc.sql.SqlDriver; 16 17 import com.versant.core.common.BindingSupportImpl; 18 19 22 public class AndExp extends SqlExp { 23 24 public AndExp() { 25 } 26 27 public AndExp(SqlExp children) { 28 super(children); 29 } 30 31 public SqlExp createInstance() { 32 return new AndExp(); 33 } 34 35 42 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 43 appendSQL(childList, driver, s, null); 44 SqlExp prev = childList; 45 for (SqlExp e = childList.next; e != null; prev = e, e = e.next) { 46 s.append(" AND "); 47 appendSQL(e, driver, s, prev); 48 } 49 } 50 51 private void appendSQL(SqlExp e, SqlDriver driver, CharBuf s, 52 SqlExp leftSibling) { 53 boolean p = e.requiresParensInAnd(); 54 if (p) s.append('('); 55 e.appendSQL(driver, s, leftSibling); 56 if (p) s.append(')'); 57 } 58 59 64 public SqlExp normalize(SqlDriver driver, SelectExp sel, boolean convertExists) { 65 super.normalize(driver, sel, convertExists); 66 67 if (!driver.isConvertExistsToDistinctJoin()) return null; 68 69 SqlExp p = null; 70 for (SqlExp e = childList; e != null;) { 71 int cj = e.getConvertToJoin(); 72 if (cj >= SqlExp.YES) { 73 boolean not = cj == SqlExp.YES_DISTINCT_NOT; 75 SelectExp sub; 76 if (not) { 77 sub = (SelectExp)(e.childList.childList); 78 } else { 79 sub = (SelectExp)(e.childList); 80 } 81 Join j = new Join(); 82 j.selectExp = sub; 83 j.exp = sub.subSelectJoinExp; 84 sub.subSelectJoinExp = null; 85 sel.addJoinMerge(j); 86 if (!sel.distinct) { 87 sel.distinct = cj >= SqlExp.YES_DISTINCT; 88 } 89 if (not) { 90 sub.setOuterRec(); 91 if (sub.whereExp != null) { 92 throw BindingSupportImpl.getInstance().fatalDatastore("Query too complex for " + driver.getName()); 93 } 94 SqlExp ne = sub.getOuterJoinNotMatchedExp(); 96 if (p == null) { 97 p = childList = ne; 98 } else { 99 p = p.next = ne; 100 } 101 e = ne.next = e.next; 102 } else { 103 SqlExp ne = sub.whereExp; 104 if (ne == null) { 105 ne = sub.getOuterJoinMatchedExp(); 106 } else { 107 sub.whereExp = null; 108 } 109 if (p == null) { 111 p = childList = ne; 112 } else { 113 p = p.next = ne; 114 } 115 e = ne.next = e.next; 116 } 117 } else { 118 p = e; 119 e = e.next; 120 } 121 } 122 123 if (childList == null) return null; if (childList.next == null) return childList; 126 return null; 127 } 128 129 } 130 | Popular Tags |