1 2 12 package com.versant.core.jdbc.sql.exp; 13 14 import com.versant.core.jdbc.sql.SqlDriver; 15 import com.versant.core.util.CharBuf; 16 import com.versant.core.jdo.query.VarNodeIF; 17 18 import java.util.Map ; 19 20 23 public class ExistsExp extends UnaryExp { 24 27 private boolean distinct; 28 private VarNodeIF forVariable; 29 30 public ExistsExp(SqlExp child, boolean requiresDistinct) { 31 super(child); 32 this.distinct = requiresDistinct; 33 } 34 35 public ExistsExp(SqlExp child, boolean requiresDistinct, VarNodeIF var) { 36 this(child, requiresDistinct); 37 this.forVariable = var; 38 } 39 40 public ExistsExp() { 41 } 42 43 public SqlExp createInstance() { 44 return new ExistsExp(); 45 } 46 47 public SqlExp getClone(SqlExp clone, Map cloneMap) { 48 super.getClone(clone, cloneMap); 49 50 ((ExistsExp) clone).distinct = distinct; 51 52 return clone; 53 } 54 55 62 public void appendSQLImp(SqlDriver driver, CharBuf s, SqlExp leftSibling) { 63 s.append("EXISTS ("); 64 childList.appendSQL(driver, s, null); 65 s.append(')'); 66 } 67 68 72 public int getConvertToJoin() { 73 if (!distinct) return YES; 74 if (forVariable != null && ((VarNodeIF)forVariable).isUsedInProjection()) return YES; 75 return YES_DISTINCT; 76 } 77 78 public String toString() { 79 return super.toString() + " oneToMany " + distinct; 80 } 81 82 } 83 84 | Popular Tags |