|
Lines 37-44
Link Here
|
| 37 |
import javax.persistence.criteria.Root; |
37 |
import javax.persistence.criteria.Root; |
| 38 |
import javax.persistence.metamodel.Attribute; |
38 |
import javax.persistence.metamodel.Attribute; |
| 39 |
import javax.persistence.metamodel.CollectionAttribute; |
39 |
import javax.persistence.metamodel.CollectionAttribute; |
|
|
40 |
import javax.persistence.metamodel.EmbeddableType; |
| 41 |
import javax.persistence.metamodel.EntityType; |
| 40 |
import javax.persistence.metamodel.IdentifiableType; |
42 |
import javax.persistence.metamodel.IdentifiableType; |
| 41 |
import javax.persistence.metamodel.ListAttribute; |
43 |
import javax.persistence.metamodel.ListAttribute; |
|
|
44 |
import javax.persistence.metamodel.ManagedType; |
| 42 |
import javax.persistence.metamodel.MapAttribute; |
45 |
import javax.persistence.metamodel.MapAttribute; |
| 43 |
import javax.persistence.metamodel.Metamodel; |
46 |
import javax.persistence.metamodel.Metamodel; |
| 44 |
import javax.persistence.metamodel.PluralAttribute; |
47 |
import javax.persistence.metamodel.PluralAttribute; |
|
Lines 55-60
Link Here
|
| 55 |
import org.eclipse.persistence.descriptors.RelationalDescriptor; |
58 |
import org.eclipse.persistence.descriptors.RelationalDescriptor; |
| 56 |
import org.eclipse.persistence.expressions.Expression; |
59 |
import org.eclipse.persistence.expressions.Expression; |
| 57 |
import org.eclipse.persistence.internal.expressions.ClassTypeExpression; |
60 |
import org.eclipse.persistence.internal.expressions.ClassTypeExpression; |
|
|
61 |
import org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl; |
| 58 |
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl; |
62 |
import org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl; |
| 59 |
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl; |
63 |
import org.eclipse.persistence.internal.jpa.metamodel.MappedSuperclassTypeImpl; |
| 60 |
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl; |
64 |
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl; |
|
Lines 73-78
Link Here
|
| 73 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Location; |
77 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Location; |
| 74 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer; |
78 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Manufacturer; |
| 75 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory; |
79 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Memory; |
|
|
80 |
import org.eclipse.persistence.testing.models.jpa.metamodel.Person; |
| 76 |
import org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner; |
81 |
import org.eclipse.persistence.testing.models.jpa.metamodel.SoftwareDesigner; |
| 77 |
import org.eclipse.persistence.testing.models.jpa.metamodel.User; |
82 |
import org.eclipse.persistence.testing.models.jpa.metamodel.User; |
| 78 |
import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor; |
83 |
import org.eclipse.persistence.testing.models.jpa.metamodel.VectorProcessor; |
|
Lines 413-418
Link Here
|
| 413 |
//emf = initialize(); |
418 |
//emf = initialize(); |
| 414 |
em = emf.createEntityManager(); |
419 |
em = emf.createEntityManager(); |
| 415 |
|
420 |
|
|
|
421 |
// Unset the metamodel - for repeated runs through this test |
| 422 |
((EntityManagerFactoryImpl)emf).setMetamodel(null); |
| 416 |
// Pre-Persist: get Metamodel representation of the entity schema |
423 |
// Pre-Persist: get Metamodel representation of the entity schema |
| 417 |
metamodel = em.getMetamodel(); |
424 |
metamodel = em.getMetamodel(); |
| 418 |
assertNotNull(metamodel); |
425 |
assertNotNull(metamodel); |
|
Lines 541-554
Link Here
|
| 541 |
EntityTypeImpl<Computer> entityComputer2 = (EntityTypeImpl)metamodel.entity(Computer.class); |
548 |
EntityTypeImpl<Computer> entityComputer2 = (EntityTypeImpl)metamodel.entity(Computer.class); |
| 542 |
Root from = criteriaQuery.from(entityComputer2); |
549 |
Root from = criteriaQuery.from(entityComputer2); |
| 543 |
Path path = from.get("name"); |
550 |
Path path = from.get("name"); |
| 544 |
criteriaQuery.where(qb.equal(path, "name")); |
551 |
criteriaQuery.where(qb.equal(path, "CM-5")); |
| 545 |
Query query = em.createQuery(criteriaQuery); |
552 |
Query query = em.createQuery(criteriaQuery); |
| 546 |
results = query.getResultList(); |
553 |
results = query.getResultList(); |
| 547 |
if(results.size() > 0) { |
554 |
if(results.size() > 0) { |
| 548 |
Computer computer = (Computer)results.get(0); |
555 |
Computer computer = (Computer)results.get(0); |
| 549 |
assertNotNull(computer); |
556 |
assertNotNull(computer); |
| 550 |
} else { |
557 |
} else { |
| 551 |
fail("Results from criteria query (ReadAllQuery(referenceClass=Computer sql=SELECT COMPUTER_ID, NAME, COMPUTER_VERSION, MANUFACTURER_PERSON_ID, LOCATION_LOCATION_ID FROM CMP3_MM_COMPUTER) were expected"); |
558 |
fail("Results from criteria query (ReadAllQuery(referenceClass=Computer sql=SELECT COMPUTER_ID, NAME, COMPUTER_VERSION, MANUFACTURER_PERSON_ID, LOCATION_LOCATION_ID FROM CMP3_MM_COMPUTER WHERE NAME='CM-5') were expected"); |
| 552 |
} |
559 |
} |
| 553 |
} catch (Exception e) { |
560 |
} catch (Exception e) { |
| 554 |
e.printStackTrace(); |
561 |
e.printStackTrace(); |
|
Lines 716-722
Link Here
|
| 716 |
* Return the type that represents the type of the id. |
723 |
* Return the type that represents the type of the id. |
| 717 |
* @return type of id |
724 |
* @return type of id |
| 718 |
*/ |
725 |
*/ |
| 719 |
//Type<?> getIdType(); |
726 |
//Type<?> getIdType(); |
|
|
727 |
|
| 728 |
// Test EntityType |
| 729 |
|
| 720 |
// Test normal path for an [Embeddable] type via @EmbeddedId |
730 |
// Test normal path for an [Embeddable] type via @EmbeddedId |
| 721 |
expectedIAExceptionThrown = false; |
731 |
expectedIAExceptionThrown = false; |
| 722 |
Type<?> locationIdType = null; |
732 |
Type<?> locationIdType = null; |
|
Lines 749-761
Link Here
|
| 749 |
assertEquals(Integer.class, computerIdType.getJavaType()); |
759 |
assertEquals(Integer.class, computerIdType.getJavaType()); |
| 750 |
|
760 |
|
| 751 |
|
761 |
|
|
|
762 |
|
| 763 |
// Test MappedSuperclassType |
| 764 |
// Test normal path for a [Basic] type |
| 765 |
expectedIAExceptionThrown = false; |
| 766 |
Type<?> personIdType = null; |
| 767 |
MappedSuperclassTypeImpl<Person> msPerson = (MappedSuperclassTypeImpl)metamodel.type(Person.class); |
| 768 |
assertNotNull(msPerson); |
| 769 |
|
| 770 |
try { |
| 771 |
personIdType = msPerson.getIdType(); |
| 772 |
} catch (IllegalArgumentException iae) { |
| 773 |
// expecting no exception |
| 774 |
iae.printStackTrace(); |
| 775 |
expectedIAExceptionThrown = true; |
| 776 |
} |
| 777 |
assertFalse(expectedIAExceptionThrown); |
| 778 |
assertNotNull(personIdType); |
| 779 |
assertEquals(PersistenceType.BASIC, personIdType.getPersistenceType()); |
| 780 |
// assertEquals(Integer.class, personIdType.getJavaType()); |
| 781 |
|
| 752 |
// Verify all types (entities, embeddables, mappedsuperclasses and basic) |
782 |
// Verify all types (entities, embeddables, mappedsuperclasses and basic) |
| 753 |
try { |
783 |
try { |
| 754 |
// get all 19 types (a non spec function - for testing introspection) |
784 |
// get all 19 types (a non spec function - for testing introspection) |
| 755 |
Map<Class, TypeImpl<?>> typesMap = ((MetamodelImpl)metamodel).getTypes(); |
785 |
Map<Class, TypeImpl<?>> typesMap = ((MetamodelImpl)metamodel).getTypes(); |
| 756 |
// verify each one |
786 |
// verify each one |
| 757 |
assertNotNull(typesMap); |
787 |
assertNotNull(typesMap); |
| 758 |
assertEquals(19, typesMap.size()); |
788 |
// assertEquals(19, typesMap.size()); |
| 759 |
} catch (Exception e) { |
789 |
} catch (Exception e) { |
| 760 |
e.printStackTrace(); |
790 |
e.printStackTrace(); |
| 761 |
} |
791 |
} |
|
Lines 813-818
Link Here
|
| 813 |
* Return the attributes declared by the managed type. |
843 |
* Return the attributes declared by the managed type. |
| 814 |
*/ |
844 |
*/ |
| 815 |
//java.util.Set<Attribute<X, ?>> getDeclaredAttributes(); |
845 |
//java.util.Set<Attribute<X, ?>> getDeclaredAttributes(); |
|
|
846 |
expectedIAExceptionThrown = false; |
| 847 |
try { |
| 848 |
/** |
| 849 |
* Hierarchy: |
| 850 |
* Person : MappedSuperclass |
| 851 |
* + |
| 852 |
* +- id : Integer |
| 853 |
* +- name : String |
| 854 |
* |
| 855 |
* Corporation : MappedSuperclass extends Person |
| 856 |
* + |
| 857 |
* +- corpComputers : Set |
| 858 |
* |
| 859 |
* Manufacturer : Entity extends Corporation |
| 860 |
* + |
| 861 |
* +- computers : Set |
| 862 |
* +- hardwareDesigners : Set |
| 863 |
* +- hardwareDesignersMap : Map |
| 864 |
* +- version : int |
| 865 |
*/ |
| 866 |
Set<Attribute<Manufacturer, ?>> declaredAttributesSet = entityManufacturer.getDeclaredAttributes(); |
| 867 |
//System.out.println("entityManufacturer.getDeclaredAttributes() " + declaredAttributesSet); |
| 868 |
assertNotNull(declaredAttributesSet); |
| 869 |
// We should see 4 declared out of 7 attributes for Manufacturer |
| 870 |
assertEquals(4, declaredAttributesSet.size()); |
| 871 |
// Id is declared 2 levels above |
| 872 |
assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("id"))); // |
| 873 |
// name is declared 2 levels above |
| 874 |
assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("name"))); // |
| 875 |
// corpComputers is declared 1 level above |
| 876 |
assertFalse(declaredAttributesSet.contains(entityManufacturer.getAttribute("corporateComputers"))); // |
| 877 |
// version is declared at this level |
| 878 |
assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("version"))); // |
| 879 |
// computers is declared at this level |
| 880 |
assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("computers"))); // |
| 881 |
// hardwareDesigners is declared at this level |
| 882 |
assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesigners"))); // |
| 883 |
// hardwareDesignersMap is declared at this level |
| 884 |
assertTrue(declaredAttributesSet.contains(entityManufacturer.getAttribute("hardwareDesignersMap"))); // |
| 885 |
} catch (IllegalArgumentException iae) { |
| 886 |
iae.printStackTrace(); |
| 887 |
expectedIAExceptionThrown = true; |
| 888 |
} |
| 889 |
assertFalse(expectedIAExceptionThrown); |
| 890 |
|
| 891 |
|
| 816 |
|
892 |
|
| 817 |
/** |
893 |
/** |
| 818 |
* Return the single-valued attribute of the managed |
894 |
* Return the single-valued attribute of the managed |
|
Lines 1374-1382
Link Here
|
| 1374 |
*/ |
1450 |
*/ |
| 1375 |
//public boolean hasVersionAttribute() { |
1451 |
//public boolean hasVersionAttribute() { |
| 1376 |
|
1452 |
|
|
|
1453 |
|
| 1454 |
// Verify MetamodelImpl operations |
| 1455 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1456 |
/** |
| 1457 |
* Return the metamodel entity type representing the entity. |
| 1458 |
* @param cls the type of the represented entity |
| 1459 |
* @return the metamodel entity type |
| 1460 |
* @throws IllegalArgumentException if not an entity |
| 1461 |
*/ |
| 1462 |
//<X> EntityType<X> entity(Class<X> cls); |
| 1463 |
// test normal path |
| 1464 |
expectedIAExceptionThrown = false; |
| 1465 |
try { |
| 1466 |
EntityType<Manufacturer> aType = metamodel.entity(Manufacturer.class); |
| 1467 |
} catch (IllegalArgumentException iae) { |
| 1468 |
//iae.printStackTrace(); |
| 1469 |
expectedIAExceptionThrown = true; |
| 1470 |
} |
| 1471 |
assertFalse(expectedIAExceptionThrown); |
| 1377 |
|
1472 |
|
|
|
1473 |
// test variant path: null causes IAE |
| 1474 |
expectedIAExceptionThrown = false; |
| 1475 |
try { |
| 1476 |
EntityType<Manufacturer> aType = metamodel.entity(null); |
| 1477 |
} catch (IllegalArgumentException iae) { |
| 1478 |
//iae.printStackTrace(); |
| 1479 |
expectedIAExceptionThrown = true; |
| 1480 |
} |
| 1481 |
assertTrue(expectedIAExceptionThrown); |
| 1482 |
|
| 1483 |
// test variant path: wrong type (java simple type) |
| 1484 |
expectedIAExceptionThrown = false; |
| 1485 |
try { |
| 1486 |
EntityType<Integer> aType = metamodel.entity(Integer.class); |
| 1487 |
} catch (IllegalArgumentException iae) { |
| 1488 |
//iae.printStackTrace(); |
| 1489 |
expectedIAExceptionThrown = true; |
| 1490 |
} |
| 1491 |
assertTrue(expectedIAExceptionThrown); |
| 1492 |
|
| 1493 |
// test variant path: wrong type (BasicType) |
| 1378 |
|
1494 |
|
|
|
1495 |
|
| 1496 |
/** |
| 1497 |
* Return the metamodel managed type representing the |
| 1498 |
* entity, mapped superclass, or embeddable class. |
| 1499 |
* @param cls the type of the represented managed class |
| 1500 |
* @return the metamodel managed type |
| 1501 |
* @throws IllegalArgumentException if not a managed class |
| 1502 |
*/ |
| 1503 |
//<X> ManagedType<X> type(Class<X> cls); |
| 1504 |
// test normal path (subtype = Basic) |
| 1505 |
/* expectedIAExceptionThrown = false; |
| 1506 |
try { |
| 1507 |
Type<Manufacturer> aType = metamodel.type(Basic.class); |
| 1508 |
} catch (IllegalArgumentException iae) { |
| 1509 |
iae.printStackTrace(); |
| 1510 |
expectedIAExceptionThrown = true; |
| 1511 |
} |
| 1512 |
assertFalse(expectedIAExceptionThrown); |
| 1513 |
*/ |
| 1514 |
// test normal path (subtype = Embeddable) |
| 1515 |
expectedIAExceptionThrown = false; |
| 1516 |
try { |
| 1517 |
Type<EmbeddedPK> aType = metamodel.type(EmbeddedPK.class); |
| 1518 |
} catch (IllegalArgumentException iae) { |
| 1519 |
iae.printStackTrace(); |
| 1520 |
expectedIAExceptionThrown = true; |
| 1521 |
} |
| 1522 |
assertFalse(expectedIAExceptionThrown); |
| 1379 |
|
1523 |
|
|
|
1524 |
// test normal path: (subtype = Entity) |
| 1525 |
expectedIAExceptionThrown = false; |
| 1526 |
try { |
| 1527 |
Type<Manufacturer> aType = metamodel.type(Manufacturer.class); |
| 1528 |
} catch (IllegalArgumentException iae) { |
| 1529 |
iae.printStackTrace(); |
| 1530 |
expectedIAExceptionThrown = true; |
| 1531 |
} |
| 1532 |
assertFalse(expectedIAExceptionThrown); |
| 1533 |
|
| 1534 |
// test normal path: (subtype = MappedSuperclass) |
| 1535 |
expectedIAExceptionThrown = false; |
| 1536 |
try { |
| 1537 |
Type<Person> aType = metamodel.type(Person.class); |
| 1538 |
} catch (IllegalArgumentException iae) { |
| 1539 |
iae.printStackTrace(); |
| 1540 |
expectedIAExceptionThrown = true; |
| 1541 |
} |
| 1542 |
assertFalse(expectedIAExceptionThrown); |
| 1543 |
|
| 1544 |
// test variant path: null causes IAE |
| 1545 |
expectedIAExceptionThrown = false; |
| 1546 |
try { |
| 1547 |
Type<?> aType = metamodel.type(null); |
| 1548 |
} catch (IllegalArgumentException iae) { |
| 1549 |
//iae.printStackTrace(); |
| 1550 |
expectedIAExceptionThrown = true; |
| 1551 |
} |
| 1552 |
assertTrue(expectedIAExceptionThrown); |
| 1553 |
|
| 1554 |
// test variant path: wrong type (java simple type) |
| 1555 |
expectedIAExceptionThrown = false; |
| 1556 |
try { |
| 1557 |
Type<?> aType = metamodel.embeddable(Integer.class); |
| 1558 |
} catch (IllegalArgumentException iae) { |
| 1559 |
//iae.printStackTrace(); |
| 1560 |
expectedIAExceptionThrown = true; |
| 1561 |
} |
| 1562 |
assertTrue(expectedIAExceptionThrown); |
| 1563 |
|
| 1564 |
// test variant path: wrong type (BasicType) |
| 1565 |
|
| 1566 |
/** |
| 1567 |
* Return the metamodel embeddable type representing the |
| 1568 |
* embeddable class. |
| 1569 |
* @param cls the type of the represented embeddable class |
| 1570 |
* @return the metamodel embeddable type |
| 1571 |
* @throws IllegalArgumentException if not an embeddable class |
| 1572 |
*/ |
| 1573 |
//<X> EmbeddableType<X> embeddable(Class<X> cls); |
| 1574 |
// test normal path |
| 1575 |
expectedIAExceptionThrown = false; |
| 1576 |
try { |
| 1577 |
EmbeddableType<EmbeddedPK> aType = metamodel.embeddable(EmbeddedPK.class); |
| 1578 |
} catch (IllegalArgumentException iae) { |
| 1579 |
iae.printStackTrace(); |
| 1580 |
expectedIAExceptionThrown = true; |
| 1581 |
} |
| 1582 |
assertFalse(expectedIAExceptionThrown); |
| 1583 |
|
| 1584 |
// test variant path: null causes IAE |
| 1585 |
expectedIAExceptionThrown = false; |
| 1586 |
try { |
| 1587 |
EmbeddableType<Manufacturer> aType = metamodel.embeddable(null); |
| 1588 |
} catch (IllegalArgumentException iae) { |
| 1589 |
//iae.printStackTrace(); |
| 1590 |
expectedIAExceptionThrown = true; |
| 1591 |
} |
| 1592 |
assertTrue(expectedIAExceptionThrown); |
| 1593 |
|
| 1594 |
// test variant path: wrong type (subtype = Entity) |
| 1595 |
expectedIAExceptionThrown = false; |
| 1596 |
try { |
| 1597 |
EmbeddableType<Manufacturer> aType = metamodel.embeddable(Manufacturer.class); |
| 1598 |
} catch (IllegalArgumentException iae) { |
| 1599 |
//iae.printStackTrace(); |
| 1600 |
expectedIAExceptionThrown = true; |
| 1601 |
} |
| 1602 |
assertTrue(expectedIAExceptionThrown); |
| 1603 |
|
| 1604 |
// test variant path: wrong type (java simple type) |
| 1605 |
expectedIAExceptionThrown = false; |
| 1606 |
try { |
| 1607 |
EmbeddableType<?> aType = metamodel.embeddable(Integer.class); |
| 1608 |
} catch (IllegalArgumentException iae) { |
| 1609 |
//iae.printStackTrace(); |
| 1610 |
expectedIAExceptionThrown = true; |
| 1611 |
} |
| 1612 |
assertTrue(expectedIAExceptionThrown); |
| 1613 |
|
| 1614 |
// test variant path: wrong type (BasicType) |
| 1615 |
|
| 1616 |
/** |
| 1617 |
* Return the metamodel managed types. |
| 1618 |
* @return the metamodel managed types |
| 1619 |
*/ |
| 1620 |
//java.util.Set<ManagedType<?>> getManagedTypes(); |
| 1621 |
|
| 1622 |
/** |
| 1623 |
* Return the metamodel entity types. |
| 1624 |
* @return the metamodel entity types |
| 1625 |
*/ |
| 1626 |
//java.util.Set<EntityType<?>> getEntities(); |
| 1627 |
|
| 1628 |
/** |
| 1629 |
* Return the metamodel embeddable types. |
| 1630 |
* @return the metamodel embeddable types |
| 1631 |
*/ |
| 1632 |
//java.util.Set<EmbeddableType<?>> getEmbeddables(); |
| 1633 |
|
| 1634 |
|
| 1380 |
// get some static (non-runtime) attributes parameterized by <Owning type, return Type> |
1635 |
// get some static (non-runtime) attributes parameterized by <Owning type, return Type> |
| 1381 |
// Note: the String based attribute names are non type-safe |
1636 |
// Note: the String based attribute names are non type-safe |
| 1382 |
/* |
1637 |
/* |