1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import oracle.toplink.essentials.descriptors.ClassDescriptor; 25 import oracle.toplink.essentials.exceptions.EJBQLException; 26 import oracle.toplink.essentials.expressions.*; 27 import oracle.toplink.essentials.mappings.DatabaseMapping; 28 29 36 public class AttributeNode extends Node { 37 38 39 private String name; 40 41 42 private boolean outerJoin; 43 44 45 private boolean requiresCollectionAttribute; 46 47 48 private DatabaseMapping mapping; 49 50 53 public AttributeNode() { 54 super(); 55 } 56 57 61 public AttributeNode(String name) { 62 setAttributeName(name); 63 } 64 65 69 public void validate(ParseTreeContext context) { 70 } 72 73 74 public Expression addToExpression(Expression parentExpression, GenerationContext context) { 75 if (isCollectionAttribute()) { 76 if (context.hasMemberOfNode()) { 78 return parentExpression.noneOf(name, new ExpressionBuilder().equal(context.getMemberOfNode().getLeftExpression())); 79 } 80 return outerJoin ? parentExpression.anyOfAllowingNone(name) : 81 parentExpression.anyOf(name); 82 } else { 83 if (requiresCollectionAttribute()) { 85 throw EJBQLException.invalidCollectionMemberDecl(name); 86 } 87 88 if (context.shouldUseOuterJoins() || isOuterJoin()) { 89 return parentExpression.getAllowingNull(name); 90 } else { 91 return parentExpression.get(name); 92 } 93 } 94 } 95 96 100 public boolean isAttributeNode() { 101 return true; 102 } 103 104 105 public String getAttributeName() { 106 return name; 107 } 108 109 110 public void setAttributeName(String name) { 111 this.name = name; 112 } 113 114 115 public boolean isOuterJoin() { 116 return outerJoin; 117 } 118 119 120 public void setOuterJoin(boolean outerJoin) { 121 this.outerJoin = outerJoin; 122 } 123 124 125 public boolean requiresCollectionAttribute() { 126 return requiresCollectionAttribute; 127 } 128 129 130 public void setRequiresCollectionAttribute(boolean requiresCollectionAttribute) { 131 this.requiresCollectionAttribute = requiresCollectionAttribute; 132 } 133 134 135 public DatabaseMapping getMapping() { 136 return mapping; 137 } 138 139 140 public void setMapping(DatabaseMapping mapping) { 141 this.mapping = mapping; 142 } 143 144 145 public boolean isCollectionAttribute() { 146 DatabaseMapping mapping = getMapping(); 147 return (mapping != null) && mapping.isCollectionMapping(); 148 } 149 150 153 public DatabaseMapping resolveMapping(GenerationContext context, Class ownerClass) { 154 ClassDescriptor descriptor = context.getSession().getDescriptor(ownerClass); 155 return (descriptor==null) ? null : descriptor.getMappingForAttributeName(getAttributeName()); 156 } 157 158 162 public Class resolveClass(GenerationContext context, Class ownerClass) { 163 DatabaseMapping mapping; 164 165 mapping = resolveMapping(context, ownerClass); 166 167 if ((mapping == null) || (mapping.isDirectToFieldMapping())) { 172 return ownerClass; 173 } 174 175 ClassDescriptor descriptor = mapping.getReferenceDescriptor(); 176 return (descriptor==null) ? null : descriptor.getJavaClass(); 177 } 179 180 184 public String getAsString() { 185 return getAttributeName(); 186 } 187 } 188 | Popular Tags |