1 29 30 package com.caucho.amber.expr; 31 32 import com.caucho.amber.manager.AmberPersistenceUnit; 33 import com.caucho.amber.query.FromItem; 34 import com.caucho.amber.query.QueryParser; 35 import com.caucho.amber.table.Column; 36 import com.caucho.amber.table.LinkColumns; 37 import com.caucho.jdbc.JdbcMetaData; 38 import com.caucho.util.CharBuffer; 39 40 43 public class BooleanColumnExpr extends AbstractAmberExpr { 44 protected PathExpr _parent; 45 private Column _column; 47 48 protected FromItem _fromItem; 49 50 53 public BooleanColumnExpr(PathExpr parent, Column column) 54 { 55 _parent = parent; 56 _column = column; 57 } 58 59 62 PathExpr getParent() 63 { 64 return _parent; 65 } 66 67 70 Column getColumn() 71 { 72 return _column; 73 } 74 75 78 public boolean isBoolean() 79 { 80 return true; 81 } 82 83 86 public AmberExpr bindSelect(QueryParser parser) 87 { 88 FromItem parentFromItem = _parent.bindSubPath(parser); 89 90 if (parentFromItem.getTable() == getColumn().getTable()) { 91 _fromItem = parentFromItem; 92 93 return this; 94 } 95 96 LinkColumns link = getColumn().getTable().getDependentIdLink(); 97 _fromItem = parser.createDependentFromItem(parentFromItem, link); 98 99 return this; 100 } 101 102 105 public boolean usesFrom(FromItem from, int type, boolean isNot) 106 { 107 if (_fromItem == from) 108 return true; 109 else if (_fromItem == null && _parent.getChildFromItem() == from) 110 return true; 111 else 112 return false; 113 } 114 115 118 public AmberExpr replaceJoin(JoinExpr join) 119 { 120 _parent = (PathExpr) _parent.replaceJoin(join); 121 122 return this; 123 } 124 125 128 public void generateWhere(CharBuffer cb) 129 { 130 generateInternalWhere(cb, true); 131 } 132 133 136 public void generateUpdateWhere(CharBuffer cb) 137 { 138 generateInternalWhere(cb, false); 139 } 140 141 144 public void generateHaving(CharBuffer cb) 145 { 146 generateWhere(cb); 147 } 148 149 public String toString() 150 { 151 return _parent + "." + _column.getName(); 152 } 153 154 157 private void generateInternalWhere(CharBuffer cb, 158 boolean select) 159 { 160 CharBuffer term = new CharBuffer(); 161 162 if (_fromItem != null) { 163 164 if (select) { 165 term.append(_fromItem.getName()); 166 term.append('.'); 167 } 168 169 term.append(_column.getName()); 170 } 171 else { 172 173 if (select) { 174 term.append(_parent.getChildFromItem().getName()); 175 term.append('.'); 176 } 177 178 term.append(_column.getName()); 179 } 180 181 AmberPersistenceUnit manager = _column.getTable().getAmberManager(); 182 183 JdbcMetaData metaData = manager.getMetaData(); 184 185 cb.append(metaData.generateBoolean(term.toString())); 186 } 187 } 188 | Popular Tags |