1 29 30 package com.caucho.amber.expr; 31 32 import com.caucho.amber.query.FromItem; 33 import com.caucho.amber.query.QueryParseException; 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.amber.type.Type; 38 import com.caucho.util.CharBuffer; 39 40 41 44 public class ColumnExpr extends AbstractAmberExpr { 45 protected PathExpr _parent; 46 private Column _column; 48 49 protected FromItem _fromItem; 50 51 54 public ColumnExpr(PathExpr parent, Column column) 55 { 56 _parent = parent; 57 _column = column; 58 } 59 60 63 public PathExpr getParent() 64 { 65 return _parent; 66 } 67 68 71 public Column getColumn() 72 { 73 return _column; 74 } 75 76 79 public Type getType() 80 { 81 return getColumn().getType(); 82 } 83 84 87 public AmberExpr createBoolean() 88 throws QueryParseException 89 { 90 if (getColumn().getType().isBoolean()) 91 return new BooleanColumnExpr(_parent, _column); 92 else 93 return super.createBoolean(); 94 } 95 96 99 public AmberExpr bindSelect(QueryParser parser) 100 { 101 FromItem parentFromItem = _parent.bindSubPath(parser); 102 103 if (parentFromItem.getTable() == getColumn().getTable()) { 104 _fromItem = parentFromItem; 105 106 return this; 107 } 108 109 LinkColumns link = getColumn().getTable().getDependentIdLink(); 110 111 if (link == null) 112 return this; 113 114 _fromItem = parser.createDependentFromItem(parentFromItem, link); 115 116 return this; 117 } 118 119 122 public boolean usesFrom(FromItem from, int type, boolean isNot) 123 { 124 if (_fromItem == from) 125 return true; 126 else if (_fromItem == null && _parent.getChildFromItem() == from) 127 return true; 128 else 129 return false; 130 } 131 132 135 public AmberExpr replaceJoin(JoinExpr join) 136 { 137 _parent = (PathExpr) _parent.replaceJoin(join); 138 139 return this; 140 } 141 142 145 public void generateWhere(CharBuffer cb) 146 { 147 generateInternalWhere(cb, true); 148 } 149 150 153 public void generateUpdateWhere(CharBuffer cb) 154 { 155 generateInternalWhere(cb, false); 156 } 157 158 161 public void generateHaving(CharBuffer cb) 162 { 163 generateWhere(cb); 164 } 165 166 public String toString() 167 { 168 return _parent + "." + _column.getName(); 169 } 170 171 174 private void generateInternalWhere(CharBuffer cb, 175 boolean select) 176 { 177 if (_fromItem != null) { 178 179 if (select) { 180 cb.append(_fromItem.getName()); 181 cb.append('.'); 182 } 183 184 cb.append(_column.getName()); 185 } 186 else { 187 188 if (select) { 189 cb.append(_parent.getChildFromItem().getName()); 190 cb.append('.'); 191 } 192 193 cb.append(_column.getName()); 194 } 195 } 196 } 197 | Popular Tags |