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 OrExp extends SqlExp { 23 24 public OrExp(SqlExp children) { 25 super(children); 26 } 27 28 public OrExp() { 29 } 30 31 public SqlExp createInstance() { 32 return new OrExp(); 33 } 34 35 39 public boolean requiresParensInAnd() { 40 return true; 41 } 42 43 50 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 51 childList.appendSQL(driver, s, null); 52 SqlExp prev = childList; 53 for (SqlExp e = childList.next; e != null; prev = e, e = e.next) { 54 s.append(" OR "); 55 e.appendSQL(driver, s, prev); 56 } 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 Join j = new Join(); 81 j.selectExp = sub; 82 j.exp = sub.subSelectJoinExp; 83 sub.subSelectJoinExp = null; 84 sel.addJoinMerge(j); 85 if (!sel.distinct) { 86 sel.distinct = cj >= SqlExp.YES_DISTINCT; 87 } 88 sub.setOuterRec(); 89 if (not) { 90 if (sub.whereExp != null) { 91 throw BindingSupportImpl.getInstance().fatalDatastore( 92 "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 if (p == null) 110 p = childList = ne; 111 else 112 p = p.next = ne; 113 e = ne.next = e.next; 114 } 115 } else { 116 p = e; 117 e = e.next; 118 } 119 } 120 121 if (childList == null) return null; if (childList.next == null) return childList; 124 return null; 125 } 126 127 } 128 129 | Popular Tags |