1 29 30 package com.caucho.amber.query; 31 32 import com.caucho.util.CharBuffer; 33 34 import com.caucho.amber.table.Column; 35 import com.caucho.amber.table.LinkColumns; 36 37 import com.caucho.amber.AmberManager; 38 39 import com.caucho.jdbc.JdbcMetaData; 40 41 44 public class BooleanColumnExpr extends AbstractAmberExpr { 45 protected PathExpr _parent; 46 private Column _column; 48 49 protected FromItem _fromItem; 50 51 54 public BooleanColumnExpr(PathExpr parent, Column column) 55 { 56 _parent = parent; 57 _column = column; 58 } 59 60 63 PathExpr getParent() 64 { 65 return _parent; 66 } 67 68 71 Column getColumn() 72 { 73 return _column; 74 } 75 76 79 public boolean isBoolean() 80 { 81 return true; 82 } 83 84 87 public AmberExpr bindSelect(QueryParser parser) 88 { 89 FromItem parentFromItem = _parent.bindSubPath(parser); 90 91 if (parentFromItem.getTable() == getColumn().getTable()) { 92 _fromItem = parentFromItem; 93 94 return this; 95 } 96 97 LinkColumns link = getColumn().getTable().getDependentIdLink(); 98 _fromItem = parser.createDependentFromItem(parentFromItem, link); 99 100 return this; 101 } 102 103 106 public boolean usesFrom(FromItem from, int type, boolean isNot) 107 { 108 if (_fromItem == from) 109 return true; 110 else if (_fromItem == null && _parent.getChildFromItem() == from) 111 return true; 112 else 113 return false; 114 } 115 116 119 public AmberExpr replaceJoin(JoinExpr join) 120 { 121 _parent = (PathExpr) _parent.replaceJoin(join); 122 123 return this; 124 } 125 126 129 public void generateWhere(CharBuffer cb) 130 { 131 CharBuffer term = new CharBuffer(); 132 133 if (_fromItem != null) { 134 term.append(_fromItem.getName()); 135 term.append('.'); 136 term.append(_column.getName()); 137 } 138 else { 139 term.append(_parent.getChildFromItem().getName()); 140 term.append('.'); 141 term.append(_column.getName()); 142 } 143 144 AmberManager manager = _column.getTable().getAmberManager(); 145 146 JdbcMetaData metaData = manager.getMetaData(); 147 148 cb.append(metaData.generateBoolean(term.toString())); 149 } 150 151 public String toString() 152 { 153 return _parent + "." + _column.getName(); 154 } 155 } 156 | Popular Tags |