1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.util.L10N; 32 33 import com.caucho.amber.type.EntityType; 34 35 import com.caucho.amber.field.AmberField; 36 37 40 public class FromIdSchemaExpr extends SchemaExpr { 41 private static final L10N L = new L10N(FromIdSchemaExpr.class); 42 43 private IdExpr _id; 44 45 48 public FromIdSchemaExpr(IdExpr id) 49 { 50 _id = id; 51 } 52 53 56 public String getTailName() 57 { 58 return _id.getId(); 59 } 60 61 64 public SchemaExpr createField(QueryParser parser, String name) 65 throws QueryParseException 66 { 67 EntityType type = _id.getTargetType(); 68 69 AmberField field = type.getField(name); 70 71 if (field == null) 72 throw parser.error(L.l("{0}: '{1}' is an unknown field.", 73 type.getBeanClass().getName(), 74 name)); 75 76 AmberExpr fieldExpr = _id.createField(parser, name); 77 78 if (fieldExpr instanceof ManyToOneExpr) 79 return new CollectionSchemaExpr((ManyToOneExpr) fieldExpr, name); 80 84 else if (fieldExpr instanceof OneToManyExpr) 85 return new OneToManySchemaExpr((OneToManyExpr) fieldExpr); 86 throw parser.error(L.l("{0}: '{1}' must be a collection.", 87 type.getBeanClass().getName(), 88 name)); 89 } 90 91 94 public FromItem addFromItem(QueryParser parser, String id) 95 throws QueryParseException 96 { 97 return parser.addFromItem(_id.getTargetType().getTable(), id); 98 } 99 } 100 | Popular Tags |