1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.amber.entity.AmberEntityHome; 32 import com.caucho.amber.expr.CollectionIdExpr; 33 import com.caucho.amber.expr.IdExpr; 34 import com.caucho.amber.expr.JoinExpr; 35 import com.caucho.amber.expr.PathExpr; 36 import com.caucho.amber.table.Table; 37 import com.caucho.amber.type.EntityType; 38 39 public class FromItem { 40 private String _name; 41 42 private Table _table; 43 44 private AbstractQuery _query; 45 46 private PathExpr _collectionExpr; 47 48 private IdExpr _idExpr; 49 50 private int _index; 51 52 private JoinExpr _joinExpr; 53 54 private boolean _isUsed; 55 56 enum JoinSemantics { UNKNOWN, INNER, OUTER } 57 58 private JoinSemantics _joinSemantics 59 = JoinSemantics.UNKNOWN; 60 61 FromItem(Table table, String name, int index) 62 { 63 _table = table; 64 _name = name; 65 _index = index; 66 } 67 68 71 public void setIdExpr(IdExpr idExpr) 72 { 73 _idExpr = idExpr; 74 } 75 76 79 public IdExpr getIdExpr() 80 { 81 if (_idExpr != null) { 82 } 83 else if (_collectionExpr != null) { 84 _idExpr = new CollectionIdExpr(this, _collectionExpr); 85 } 86 else 87 _idExpr = new IdExpr(this); 88 89 return _idExpr; 90 } 91 92 95 public void setCollectionExpr(PathExpr collectionExpr) 96 { 97 _collectionExpr = collectionExpr; 98 } 99 100 103 public PathExpr getCollectionExpr() 104 { 105 return _collectionExpr; 106 } 107 108 111 public AbstractQuery getQuery() 112 { 113 return _query; 114 } 115 116 119 public void setQuery(AbstractQuery query) 120 { 121 _query = query; 122 } 123 124 127 public String getName() 128 { 129 return _name; 130 } 131 132 135 public EntityType getEntityType() 136 { 137 return (EntityType) getTableType(); 138 } 139 140 143 public EntityType getTableType() 144 { 145 return (EntityType) _table.getType(); 146 } 147 148 151 public Table getTable() 152 { 153 return _table; 154 } 155 156 159 public void setTable(Table table) 160 { 161 _table = table; 162 } 163 164 167 public void setJoinExpr(JoinExpr joinExpr) 168 { 169 _joinExpr = joinExpr; 170 } 171 172 175 public boolean isUsed() 176 { 177 return _isUsed; 178 } 179 180 183 public void setUsed(boolean isUsed) 184 { 185 _isUsed = isUsed; 186 } 187 188 191 public boolean isInnerJoin() 192 { 193 return _joinSemantics == JoinSemantics.INNER; 194 } 195 196 199 public boolean isOuterJoin() 200 { 201 return _joinSemantics == JoinSemantics.OUTER; 202 } 203 204 207 public void setJoinSemantics(JoinSemantics joinSemantics) 208 { 209 _joinSemantics = joinSemantics; 210 } 211 212 216 public void setOuterJoin(boolean isOuterJoin) 217 { 218 _joinSemantics = isOuterJoin ? 219 JoinSemantics.OUTER : JoinSemantics.INNER; 220 } 221 222 225 public JoinExpr getJoinExpr() 226 { 227 return _joinExpr; 228 } 229 230 233 public AmberEntityHome getEntityHome() 234 { 235 return ((EntityType) getTableType()).getHome(); 236 } 237 238 241 public int getIndex() 242 { 243 return _index; 244 } 245 246 public String toString() 247 { 248 return "FromItem[" + _table.getName() + " AS " + getName() + "]"; 249 } 250 } 251 | Popular Tags |