|
Lines 20-25
Link Here
|
| 20 |
import org.eclipse.jpt.common.core.utility.TextRange; |
20 |
import org.eclipse.jpt.common.core.utility.TextRange; |
| 21 |
import org.eclipse.jpt.common.utility.Filter; |
21 |
import org.eclipse.jpt.common.utility.Filter; |
| 22 |
import org.eclipse.jpt.common.utility.internal.Association; |
22 |
import org.eclipse.jpt.common.utility.internal.Association; |
|
|
23 |
import org.eclipse.jpt.common.utility.internal.CollectionTools; |
| 23 |
import org.eclipse.jpt.common.utility.internal.SimpleAssociation; |
24 |
import org.eclipse.jpt.common.utility.internal.SimpleAssociation; |
| 24 |
import org.eclipse.jpt.common.utility.internal.StringTools; |
25 |
import org.eclipse.jpt.common.utility.internal.StringTools; |
| 25 |
import org.eclipse.jpt.common.utility.internal.Tools; |
26 |
import org.eclipse.jpt.common.utility.internal.Tools; |
|
Lines 34-44
Link Here
|
| 34 |
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper; |
35 |
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper; |
| 35 |
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; |
36 |
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; |
| 36 |
import org.eclipse.jpt.jpa.core.JpaFactory; |
37 |
import org.eclipse.jpt.jpa.core.JpaFactory; |
|
|
38 |
import org.eclipse.jpt.jpa.core.MappingKeys; |
| 37 |
import org.eclipse.jpt.jpa.core.context.AssociationOverride; |
39 |
import org.eclipse.jpt.jpa.core.context.AssociationOverride; |
| 38 |
import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; |
40 |
import org.eclipse.jpt.jpa.core.context.AssociationOverrideContainer; |
| 39 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
41 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
| 40 |
import org.eclipse.jpt.jpa.core.context.AttributeOverride; |
42 |
import org.eclipse.jpt.jpa.core.context.AttributeOverride; |
| 41 |
import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; |
43 |
import org.eclipse.jpt.jpa.core.context.AttributeOverrideContainer; |
|
|
44 |
import org.eclipse.jpt.jpa.core.context.BaseEmbeddedMapping; |
| 42 |
import org.eclipse.jpt.jpa.core.context.Column; |
45 |
import org.eclipse.jpt.jpa.core.context.Column; |
| 43 |
import org.eclipse.jpt.jpa.core.context.Converter; |
46 |
import org.eclipse.jpt.jpa.core.context.Converter; |
| 44 |
import org.eclipse.jpt.jpa.core.context.Embeddable; |
47 |
import org.eclipse.jpt.jpa.core.context.Embeddable; |
|
Lines 56-61
Link Here
|
| 56 |
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverride; |
59 |
import org.eclipse.jpt.jpa.core.context.ReadOnlyOverride; |
| 57 |
import org.eclipse.jpt.jpa.core.context.ReadOnlyTable; |
60 |
import org.eclipse.jpt.jpa.core.context.ReadOnlyTable; |
| 58 |
import org.eclipse.jpt.jpa.core.context.Relationship; |
61 |
import org.eclipse.jpt.jpa.core.context.Relationship; |
|
|
62 |
import org.eclipse.jpt.jpa.core.context.RelationshipMapping; |
| 59 |
import org.eclipse.jpt.jpa.core.context.Table; |
63 |
import org.eclipse.jpt.jpa.core.context.Table; |
| 60 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
64 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
| 61 |
import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; |
65 |
import org.eclipse.jpt.jpa.core.context.java.JavaAssociationOverrideContainer; |
|
Lines 96-102
Link Here
|
| 96 |
import org.eclipse.jpt.jpa.core.jpa2.JpaFactory2_0; |
100 |
import org.eclipse.jpt.jpa.core.jpa2.JpaFactory2_0; |
| 97 |
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; |
101 |
import org.eclipse.jpt.jpa.core.jpa2.MappingKeys2_0; |
| 98 |
import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; |
102 |
import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; |
|
|
103 |
import org.eclipse.jpt.jpa.core.jpa2.context.ManyToOneRelationship2_0; |
| 99 |
import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField; |
104 |
import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField; |
|
|
105 |
import org.eclipse.jpt.jpa.core.jpa2.context.OneToOneRelationship2_0; |
| 100 |
import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; |
106 |
import org.eclipse.jpt.jpa.core.jpa2.context.Orderable2_0; |
| 101 |
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAssociationOverrideContainer2_0; |
107 |
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAssociationOverrideContainer2_0; |
| 102 |
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAttributeOverrideContainer2_0; |
108 |
import org.eclipse.jpt.jpa.core.jpa2.context.java.JavaAttributeOverrideContainer2_0; |
|
Lines 1474-1479
Link Here
|
| 1474 |
this.collectionTable.validate(messages, reporter, astRoot); |
1480 |
this.collectionTable.validate(messages, reporter, astRoot); |
| 1475 |
this.validateValue(messages, reporter, astRoot); |
1481 |
this.validateValue(messages, reporter, astRoot); |
| 1476 |
this.validateMapKey(messages, reporter, astRoot); |
1482 |
this.validateMapKey(messages, reporter, astRoot); |
|
|
1483 |
this.validateNoEmbeddableInMappingContainsProhibittedMapping(messages, astRoot); |
| 1484 |
} |
| 1485 |
|
| 1486 |
protected void validateNoEmbeddableInMappingContainsProhibittedMapping(List<IMessage> messages, CompilationUnit astRoot) { |
| 1487 |
Embeddable embeddableClass = getResolvedTargetEmbeddable(); |
| 1488 |
if (embeddableClass != null) { |
| 1489 |
embeddableContainsElementCollection(messages, astRoot, embeddableClass); |
| 1490 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddableClass); |
| 1491 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddableClass, new ArrayList<Embeddable>()); |
| 1492 |
} |
| 1493 |
embeddableClass = getResolvedMapKeyEmbeddable(); |
| 1494 |
if (embeddableClass != null) { |
| 1495 |
embeddableContainsElementCollection(messages, astRoot, embeddableClass); |
| 1496 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddableClass); |
| 1497 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddableClass, new ArrayList<Embeddable>()); |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
private void embeddableHierarchyContainsProhibittedMapping(List<IMessage> messages, CompilationUnit astRoot, Embeddable parentEmbeddable, List<Embeddable> visited) { |
| 1502 |
Iterable<AttributeMapping> embeddedIterable = parentEmbeddable.getAllAttributeMappings(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); |
| 1503 |
for(AttributeMapping mapping : embeddedIterable) { |
| 1504 |
Embeddable embeddable = ((BaseEmbeddedMapping)mapping).getTargetEmbeddable(); |
| 1505 |
if (embeddable != null && embeddable != parentEmbeddable) { |
| 1506 |
embeddableContainsElementCollection(messages, astRoot, embeddable); |
| 1507 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddable); |
| 1508 |
if (!CollectionTools.contains(visited, embeddable)) { |
| 1509 |
visited.add(embeddable); |
| 1510 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddable, visited); |
| 1511 |
} |
| 1512 |
} |
| 1513 |
} |
| 1514 |
Iterable<AttributeMapping> embeddedIdIterable = parentEmbeddable.getAllAttributeMappings(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); |
| 1515 |
for(AttributeMapping mapping : embeddedIdIterable) { |
| 1516 |
Embeddable embeddable = ((BaseEmbeddedMapping)mapping).getTargetEmbeddable(); |
| 1517 |
if (embeddable != null && embeddable != parentEmbeddable) { |
| 1518 |
embeddableContainsElementCollection(messages, astRoot, embeddable); |
| 1519 |
embeddableContainsProhibitedRelationshipMapping(messages, astRoot, embeddable); |
| 1520 |
if (!CollectionTools.contains(visited, embeddable)) { |
| 1521 |
visited.add(embeddable); |
| 1522 |
embeddableHierarchyContainsProhibittedMapping(messages, astRoot, embeddable, visited); |
| 1523 |
} |
| 1524 |
} |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
private void embeddableContainsProhibitedRelationshipMapping(List<IMessage> messages, CompilationUnit astRoot, Embeddable embeddable) { |
| 1529 |
boolean prohibitedMappingFound = false; |
| 1530 |
RelationshipMapping relationshipMapping = null; |
| 1531 |
Iterable<AttributeMapping> manyToManyMappings = embeddable.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); |
| 1532 |
Iterable<AttributeMapping> oneToManyMappings = embeddable.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); |
| 1533 |
if (oneToManyMappings.iterator().hasNext()) { |
| 1534 |
relationshipMapping = (RelationshipMapping)oneToManyMappings.iterator().next(); |
| 1535 |
prohibitedMappingFound = true; |
| 1536 |
} |
| 1537 |
if (manyToManyMappings.iterator().hasNext()) { |
| 1538 |
relationshipMapping = (RelationshipMapping)manyToManyMappings.iterator().next(); |
| 1539 |
prohibitedMappingFound = true; |
| 1540 |
} |
| 1541 |
Iterable<AttributeMapping> manyToOneMappings = embeddable.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| 1542 |
if (manyToOneMappings.iterator().hasNext()) { |
| 1543 |
relationshipMapping = (RelationshipMapping)manyToOneMappings.iterator().next(); |
| 1544 |
if (((RelationshipMapping)manyToOneMappings.iterator().next()).getRelationshipOwner() != null |
| 1545 |
|| ((ManyToOneRelationship2_0)relationshipMapping.getRelationship()).getJoinTableStrategy().getJoinTable() != null) { |
| 1546 |
prohibitedMappingFound = true; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
Iterable<AttributeMapping> oneToOneMappings = embeddable.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| 1550 |
if (oneToOneMappings.iterator().hasNext()) { |
| 1551 |
relationshipMapping = (RelationshipMapping)oneToOneMappings.iterator().next(); |
| 1552 |
if (relationshipMapping.getRelationshipOwner() != null |
| 1553 |
|| ((OneToOneRelationship2_0)relationshipMapping.getRelationship()).getJoinTableStrategy().getJoinTable() != null) { |
| 1554 |
prohibitedMappingFound = true; |
| 1555 |
} |
| 1556 |
} |
| 1557 |
if (prohibitedMappingFound) { |
| 1558 |
if (getPersistentAttribute().isVirtual()) { |
| 1559 |
messages.add( |
| 1560 |
DefaultJpaValidationMessages.buildMessage( |
| 1561 |
IMessage.HIGH_SEVERITY, |
| 1562 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_PROHIBITED_RELATIONSHIP_MAPPING, |
| 1563 |
new String[] {this.getName(), |
| 1564 |
embeddable.getName(), relationshipMapping.getName()}, |
| 1565 |
this, |
| 1566 |
this.getValidationTextRange(astRoot) |
| 1567 |
) |
| 1568 |
); |
| 1569 |
} else { |
| 1570 |
messages.add( |
| 1571 |
DefaultJpaValidationMessages.buildMessage( |
| 1572 |
IMessage.HIGH_SEVERITY, |
| 1573 |
JpaValidationMessages.ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_PROHIBITED_RELATIONSHIP_MAPPING, |
| 1574 |
new String[] {embeddable.getName(), relationshipMapping.getName()}, |
| 1575 |
this, |
| 1576 |
this.getValidationTextRange(astRoot) |
| 1577 |
) |
| 1578 |
); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
} |
| 1582 |
|
| 1583 |
private void embeddableContainsElementCollection(List<IMessage> messages, CompilationUnit astRoot, Embeddable embeddable) { |
| 1584 |
Iterable<AttributeMapping> elementCollectionMappings = embeddable.getAllAttributeMappings(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); |
| 1585 |
if (elementCollectionMappings.iterator().hasNext()) { |
| 1586 |
if (getPersistentAttribute().isVirtual()) { |
| 1587 |
messages.add( |
| 1588 |
DefaultJpaValidationMessages.buildMessage( |
| 1589 |
IMessage.HIGH_SEVERITY, |
| 1590 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_ELEMENT_COLLECTION_MAPPING, |
| 1591 |
new String[] {this.getName(), embeddable.getName(), elementCollectionMappings.iterator().next().getName()}, |
| 1592 |
this, |
| 1593 |
this.getValidationTextRange(astRoot) |
| 1594 |
) |
| 1595 |
); |
| 1596 |
} else { |
| 1597 |
messages.add( |
| 1598 |
DefaultJpaValidationMessages.buildMessage( |
| 1599 |
IMessage.HIGH_SEVERITY, |
| 1600 |
JpaValidationMessages.ELEMENT_COLLECTION_CONTAINS_EMBEDDABLE_WITH_ELEMENT_COLLECTION_MAPPING, |
| 1601 |
new String[] {embeddable.getName(), elementCollectionMappings.iterator().next().getName()}, |
| 1602 |
this, |
| 1603 |
this.getValidationTextRange(astRoot) |
| 1604 |
) |
| 1605 |
); |
| 1606 |
} |
| 1607 |
} |
| 1477 |
} |
1608 |
} |
| 1478 |
|
1609 |
|
| 1479 |
protected void validateTargetClass(List<IMessage> messages, CompilationUnit astRoot) { |
1610 |
protected void validateTargetClass(List<IMessage> messages, CompilationUnit astRoot) { |