|
Lines 29-40
Link Here
|
| 29 |
import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; |
29 |
import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; |
| 30 |
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator; |
30 |
import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator; |
| 31 |
import org.eclipse.jpt.jpa.core.JpaFactory; |
31 |
import org.eclipse.jpt.jpa.core.JpaFactory; |
|
|
32 |
import org.eclipse.jpt.jpa.core.MappingKeys; |
| 32 |
import org.eclipse.jpt.jpa.core.context.AssociationOverride; |
33 |
import org.eclipse.jpt.jpa.core.context.AssociationOverride; |
| 33 |
import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; |
34 |
import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; |
| 34 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
35 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
| 35 |
import org.eclipse.jpt.jpa.core.context.AttributeOverride; |
36 |
import org.eclipse.jpt.jpa.core.context.AttributeOverride; |
| 36 |
import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; |
37 |
import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; |
| 37 |
import org.eclipse.jpt.jpa.core.context.BaseColumn; |
38 |
import org.eclipse.jpt.jpa.core.context.BaseColumn; |
|
|
39 |
import org.eclipse.jpt.jpa.core.context.BaseEmbeddedMapping; |
| 38 |
import org.eclipse.jpt.jpa.core.context.Column; |
40 |
import org.eclipse.jpt.jpa.core.context.Column; |
| 39 |
import org.eclipse.jpt.jpa.core.context.Converter; |
41 |
import org.eclipse.jpt.jpa.core.context.Converter; |
| 40 |
import org.eclipse.jpt.jpa.core.context.Embeddable; |
42 |
import org.eclipse.jpt.jpa.core.context.Embeddable; |
|
Lines 47-52
Link Here
|
| 47 |
import org.eclipse.jpt.jpa.core.context.Override_; |
49 |
import org.eclipse.jpt.jpa.core.context.Override_; |
| 48 |
import org.eclipse.jpt.jpa.core.context.PersistentType; |
50 |
import org.eclipse.jpt.jpa.core.context.PersistentType; |
| 49 |
import org.eclipse.jpt.jpa.core.context.Relationship; |
51 |
import org.eclipse.jpt.jpa.core.context.Relationship; |
|
|
52 |
import org.eclipse.jpt.jpa.core.context.RelationshipMapping; |
| 50 |
import org.eclipse.jpt.jpa.core.context.Table; |
53 |
import org.eclipse.jpt.jpa.core.context.Table; |
| 51 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
54 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
| 52 |
import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; |
55 |
import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; |
|
Lines 1156-1161
Link Here
|
| 1156 |
this.collectionTable.validate(messages, reporter, astRoot); |
1159 |
this.collectionTable.validate(messages, reporter, astRoot); |
| 1157 |
this.validateValue(messages, reporter, astRoot); |
1160 |
this.validateValue(messages, reporter, astRoot); |
| 1158 |
this.validateMapKey(messages, reporter, astRoot); |
1161 |
this.validateMapKey(messages, reporter, astRoot); |
|
|
1162 |
this.validateNoEmbeddableInMappingContainsProhibittedMapping(messages, astRoot); |
| 1163 |
} |
| 1164 |
|
| 1165 |
protected void validateNoEmbeddableInMappingContainsProhibittedMapping(List<IMessage> messages, CompilationUnit astRoot) { |
| 1166 |
Embeddable embeddableClass = getResolvedTargetEmbeddable(); |
| 1167 |
if (embeddableClass != null) { |
| 1168 |
embeddableContainsElementCollection(messages, astRoot, embeddableClass); |
| 1169 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddableClass); |
| 1170 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddableClass, new ArrayList<Embeddable>()); |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
private void embeddableHierarchyContainsProhibittedMapping(List<IMessage> messages, CompilationUnit astRoot, Embeddable parentEmbeddable, List<Embeddable> visited) { |
| 1175 |
Iterable<AttributeMapping> embeddedIterable = parentEmbeddable.getAllAttributeMappings(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); |
| 1176 |
for(AttributeMapping mapping : embeddedIterable) { |
| 1177 |
Embeddable embeddable = ((BaseEmbeddedMapping)mapping).getTargetEmbeddable(); |
| 1178 |
if (embeddable != null && embeddable != parentEmbeddable) { |
| 1179 |
embeddableContainsElementCollection(messages, astRoot, embeddable); |
| 1180 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddable); |
| 1181 |
if (!CollectionTools.contains(visited, embeddable)) { |
| 1182 |
visited.add(embeddable); |
| 1183 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddable, visited); |
| 1184 |
} |
| 1185 |
} |
| 1186 |
} |
| 1187 |
Iterable<AttributeMapping> embeddedIdIterable = parentEmbeddable.getAllAttributeMappings(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); |
| 1188 |
for(AttributeMapping mapping : embeddedIdIterable) { |
| 1189 |
Embeddable embeddable = ((BaseEmbeddedMapping)mapping).getTargetEmbeddable(); |
| 1190 |
if (embeddable != null && embeddable != parentEmbeddable) { |
| 1191 |
embeddableContainsElementCollection(messages, astRoot, embeddable); |
| 1192 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddable); |
| 1193 |
if (!CollectionTools.contains(visited, embeddable)) { |
| 1194 |
visited.add(embeddable); |
| 1195 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddable, visited); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
private void embeddableContainsProhibitedRelationshipMapping(List<IMessage> messages, CompilationUnit astRoot, Embeddable embeddable) { |
| 1202 |
boolean prohibitedMappingFound = false; |
| 1203 |
Iterable<AttributeMapping> manyToManyMappings = embeddable.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); |
| 1204 |
Iterable<AttributeMapping> oneToManyMappings = embeddable.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); |
| 1205 |
if (oneToManyMappings.iterator().hasNext() || manyToManyMappings.iterator().hasNext()) { |
| 1206 |
prohibitedMappingFound = true; |
| 1207 |
} |
| 1208 |
Iterable<AttributeMapping> manyToOneMappings = embeddable.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| 1209 |
if (manyToOneMappings.iterator().hasNext()) { |
| 1210 |
if (((RelationshipMapping)manyToOneMappings.iterator().next()).getRelationshipOwner() != null) { |
| 1211 |
prohibitedMappingFound = true; |
| 1212 |
} |
| 1213 |
} |
| 1214 |
Iterable<AttributeMapping> oneToOneMappings = embeddable.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| 1215 |
if (oneToOneMappings.iterator().hasNext()) { |
| 1216 |
if (((RelationshipMapping)oneToOneMappings.iterator().next()).getRelationshipOwner() != null) { |
| 1217 |
prohibitedMappingFound = true; |
| 1218 |
} |
| 1219 |
} |
| 1220 |
if (prohibitedMappingFound) { |
| 1221 |
messages.add( |
| 1222 |
DefaultJpaValidationMessages.buildMessage( |
| 1223 |
IMessage.HIGH_SEVERITY, |
| 1224 |
JpaValidationMessages.ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_PROHIBITED_RELATIONSHIP_MAPPING, |
| 1225 |
new String[] {embeddable.getName()}, |
| 1226 |
this, |
| 1227 |
this.getValidationTextRange(astRoot) |
| 1228 |
) |
| 1229 |
); |
| 1230 |
} |
| 1231 |
} |
| 1232 |
|
| 1233 |
private void embeddableContainsElementCollection(List<IMessage> messages, CompilationUnit astRoot, Embeddable embeddable) { |
| 1234 |
Iterable<AttributeMapping> elementCollectionMappings = embeddable.getAllAttributeMappings(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); |
| 1235 |
if (elementCollectionMappings.iterator().hasNext()) { |
| 1236 |
messages.add( |
| 1237 |
DefaultJpaValidationMessages.buildMessage( |
| 1238 |
IMessage.HIGH_SEVERITY, |
| 1239 |
JpaValidationMessages.ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_ELEMENT_COLLECTION_MAPPING, |
| 1240 |
new String[] {embeddable.getName()}, |
| 1241 |
this, |
| 1242 |
this.getValidationTextRange(astRoot) |
| 1243 |
) |
| 1244 |
); |
| 1245 |
} |
| 1159 |
} |
1246 |
} |
| 1160 |
|
1247 |
|
| 1161 |
protected void validateTargetClass(List<IMessage> messages, CompilationUnit astRoot) { |
1248 |
protected void validateTargetClass(List<IMessage> messages, CompilationUnit astRoot) { |