1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.entity.Entity; 32 import com.caucho.amber.entity.EntityItem; 33 import com.caucho.amber.field.AmberField; 34 import com.caucho.amber.manager.AmberConnection; 35 import com.caucho.amber.query.FromItem; 36 import com.caucho.amber.query.QueryParser; 37 import com.caucho.amber.table.LinkColumns; 38 import com.caucho.amber.table.Table; 39 import com.caucho.amber.type.AbstractStatefulType; 40 import com.caucho.amber.type.EmbeddableType; 41 import com.caucho.amber.type.EntityType; 42 import com.caucho.amber.type.RelatedType; 43 import com.caucho.amber.type.Type; 44 import com.caucho.util.CharBuffer; 45 46 import java.lang.reflect.Method ; 47 import java.sql.ResultSet ; 48 import java.sql.SQLException ; 49 import java.util.ArrayList ; 50 import java.util.HashSet ; 51 import java.util.Iterator ; 52 import java.util.Map ; 53 54 57 abstract public class LoadExpr extends AbstractAmberExpr { 58 PathExpr _expr; 59 FromItem _fromItem; 60 int _index; 61 62 ArrayList <FromItem> _subItems = new ArrayList <FromItem>(); 63 64 public static LoadExpr create(PathExpr expr) 65 { 66 if (expr instanceof EmbeddedExpr) 67 return new LoadEmbeddedExpr(expr); 68 69 return new LoadEntityExpr(expr); 70 } 71 72 LoadExpr(PathExpr expr) 73 { 74 _expr = expr; 75 } 76 77 80 public Type getType() 81 { 82 return _expr.getTargetType(); 83 } 84 85 88 public PathExpr getExpr() 89 { 90 return _expr; 91 } 92 93 97 public int getIndex() 98 { 99 return _index; 100 } 101 102 105 public String getTable() 106 { 107 return _fromItem.getName(); 108 } 109 110 113 public FromItem bindSubPath(QueryParser parser) 114 { 115 throw new UnsupportedOperationException (); 116 } 117 118 121 public boolean usesFrom(FromItem from, int type, boolean isNot) 122 { 123 if (_fromItem == from) 124 return true; 125 126 for (int i = 0; i < _subItems.size(); i++) { 127 FromItem subItem = _subItems.get(i); 128 129 if (from == subItem) 130 return true; 131 } 132 133 return _expr.usesFrom(from, type, isNot); 134 } 135 136 139 public FromItem getChildFromItem() 140 { 141 return _expr.getChildFromItem(); 142 } 143 144 147 public void generateSelect(CharBuffer cb) 148 { 149 generateSelect(cb, true); 150 } 151 152 155 public void generateSelect(CharBuffer cb, 156 boolean fullSelect) 157 { 158 AbstractStatefulType type = (AbstractStatefulType) getType(); 159 160 if (type instanceof EmbeddableType) { 161 _expr.generateSelect(cb); 162 return; 163 } 164 165 if (type instanceof RelatedType) { 166 RelatedType relatedType = (RelatedType) type; 167 cb.append(relatedType.getId().generateSelect(getTable())); 168 } 169 170 if (! fullSelect) 171 return; 172 173 String valueSelect = type.generateLoadSelect(_fromItem.getTable(), 174 _fromItem.getName()); 175 176 if (valueSelect != null && ! "".equals(valueSelect)) { 177 cb.append(", "); 178 cb.append(valueSelect); 179 } 180 181 for (int i = 0; i < _subItems.size(); i++) { 182 FromItem item = _subItems.get(i); 183 184 valueSelect = type.generateLoadSelect(item.getTable(), item.getName()); 185 186 if (! valueSelect.equals("")) { 187 cb.append(", "); 188 cb.append(valueSelect); 189 } 190 } 191 } 192 193 196 public void generateWhere(CharBuffer cb, String fieldName) 197 { 198 throw new UnsupportedOperationException (); 199 } 200 201 204 public void generateUpdateWhere(CharBuffer cb, String fieldName) 205 { 206 generateWhere(cb, fieldName); 207 } 208 209 212 public void generateHaving(CharBuffer cb, String fieldName) 213 { 214 generateWhere(cb, fieldName); 215 } 216 } 217 | Popular Tags |