1 29 30 package com.caucho.amber.field; 31 32 import com.caucho.amber.manager.AmberPersistenceUnit; 33 import com.caucho.amber.table.Column; 34 import com.caucho.amber.table.LinkColumns; 35 import com.caucho.amber.type.RelatedType; 36 import com.caucho.java.JavaWriter; 37 import com.caucho.log.Log; 38 import com.caucho.util.CharBuffer; 39 import com.caucho.util.L10N; 40 41 import java.io.IOException ; 42 import java.util.ArrayList ; 43 import java.util.HashSet ; 44 import java.util.logging.Logger ; 45 46 49 public class SubId extends Id { 50 private static final L10N L = new L10N(SubId.class); 51 protected static final Logger log = Log.open(SubId.class); 52 53 private Id _parentId; 54 private LinkColumns _link; 55 56 public SubId(RelatedType ownerType, RelatedType rootType) 57 { 58 super(ownerType, new ArrayList <IdField>()); 59 60 _parentId = rootType.getId(); 61 } 62 63 66 public ArrayList <IdField> getParentKeys() 67 { 68 return _parentId.getKeys(); 69 } 70 71 74 public ArrayList <IdField> getKeys() 75 { 76 return _parentId.getKeys(); 77 } 78 79 82 public String getForeignTypeName() 83 { 84 return _parentId.getForeignTypeName(); 85 } 86 87 90 public void generatePrologue(JavaWriter out, HashSet <Object > completedSet) 91 throws IOException 92 { 93 } 94 95 98 public int generateLoadForeign(JavaWriter out, String rs, 99 String indexVar, int index) 100 throws IOException 101 { 102 return _parentId.generateLoadForeign(out, rs, indexVar, index); 103 } 104 105 108 public int generateLoadForeign(JavaWriter out, String rs, 109 String indexVar, int index, 110 String name) 111 throws IOException 112 { 113 return _parentId.generateLoadForeign(out, rs, indexVar, index, name); 114 } 115 116 119 public String generateSelect(String id) 120 { 121 ArrayList <IdField> keys = getParentKeys(); 122 123 CharBuffer cb = CharBuffer.allocate(); 124 125 for (int i = 0; i < keys.size(); i++) { 126 if (i != 0) 127 cb.append(", "); 128 129 cb.append(keys.get(i).generateSelect(id)); 130 } 131 132 return cb.close(); 133 } 134 135 138 public String generateLoadSelect(String id) 139 { 140 return null; 141 } 142 143 146 public String generateGetProperty(String value) 147 { 148 return _parentId.generateGetProperty(value); 149 } 150 151 154 public void generateLoadFromObject(JavaWriter out, String obj) 155 throws IOException 156 { 157 _parentId.generateLoadFromObject(out, obj); 158 } 159 160 163 public void generateSet(JavaWriter out, String obj) 164 throws IOException 165 { 166 _parentId.generateSet(out, obj); 167 } 168 169 172 public void generateUpdateFromObject(JavaWriter out, String obj) 173 throws IOException 174 { 175 _parentId.generateUpdateFromObject(out, obj); 176 } 177 178 181 public String generateMatchArgWhere(String id) 182 { 183 ArrayList <IdField> keys = getParentKeys(); 184 185 CharBuffer cb = CharBuffer.allocate(); 186 187 for (int i = 0; i < keys.size(); i++) { 188 if (i != 0) 189 cb.append(" and "); 190 191 generateMatchArgWhere(cb, keys.get(i), id); 192 } 193 194 return cb.close(); 195 } 196 197 198 201 private void generateMatchArgWhere(CharBuffer cb, IdField parentId, String id) 202 { 203 LinkColumns link = getOwnerType().getTable().getDependentIdLink(); 204 205 ArrayList <Column> columns = parentId.getColumns(); 206 207 for (int i = 0; i < columns.size(); i++) { 208 Column column = columns.get(i); 209 210 if (i != 0) 211 cb.append(" and "); 212 213 cb.append(id); 214 cb.append('.'); 215 cb.append(link.getSourceColumn(column).getName()); 216 cb.append("=?"); 217 } 218 } 219 220 223 public String generateCreateTableSQL(AmberPersistenceUnit manager) 224 { 225 return null; 226 } 227 228 231 public void generateSetKey(JavaWriter out, String pstmt, 232 String obj, String index) 233 throws IOException 234 { 235 _parentId.generateSetKey(out, pstmt, obj, index); 236 } 237 238 241 public void generateSet(JavaWriter out, String pstmt, 242 String obj, String index) 243 throws IOException 244 { 245 _parentId.generateSet(out, pstmt, obj, index); 246 } 247 248 251 public void generateSet(JavaWriter out, String pstmt, String index) 252 throws IOException 253 { 254 _parentId.generateSet(out, pstmt, index); 255 } 256 257 260 public void generateSetInsert(JavaWriter out, String pstmt, String index) 261 throws IOException 262 { 263 _parentId.generateSetInsert(out, pstmt, index); 264 } 265 266 269 public String generateCastFromObject(String value) 270 { 271 return value; 272 } 273 274 277 public void generateMatch(JavaWriter out, String key) 278 throws IOException 279 { 280 out.println("return " + generateEquals("super", key) + ";"); 281 } 282 283 286 public String generateEquals(String leftBase, String value) 287 { 288 return leftBase + ".equals(" + value + ")"; 289 } 290 291 294 public void generateCheckCreateKey(JavaWriter out) 295 throws IOException 296 { 297 } 298 299 302 public String toObject(String value) 303 { 304 return value; 305 } 306 } 307 | Popular Tags |