use of org.eclipse.persistence.testing.models.jpa.advanced.NonEntity in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoadedWithoutReference.
public void testIsLoadedWithoutReference() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("Abe");
emp.setLastName("Jones");
Address addr = new Address();
addr.setCity("Palo Alto");
emp.setAddress(addr);
PhoneNumber pn = new PhoneNumber();
pn.setNumber("1234456");
pn.setType("Home");
emp.addPhoneNumber(pn);
pn.setOwner(emp);
Employee manager = new Employee();
manager.addManagedEmployee(emp);
emp.setManager(manager);
em.persist(emp);
em.flush();
em.clear();
clearCache();
ProviderUtil util = (new PersistenceProvider()).getProviderUtil();
if (emp instanceof PersistenceWeaved) {
assertTrue("ProviderUtil did not return LOADED for isLoaded when it should.", util.isLoaded(emp).equals(LoadState.LOADED));
emp = em.getReference(Employee.class, emp.getId());
// If fetch group weaving is off then we will load EAGER mappings and LOADED will be returned.
if (isWeavingForFetchGroupsEnabled()) {
assertTrue("ProviderUtil did not return NOT_LOADED for isLoaded when it should.", util.isLoaded(emp).equals(LoadState.NOT_LOADED));
} else {
assertTrue("ProviderUtil did not return LOADED for isLoaded when it should.", util.isLoaded(emp).equals(LoadState.LOADED));
}
} else {
assertTrue("(NonWeaved) ProviderUtil did not return UNKNOWN for isLoaded when it should.", util.isLoaded(emp).equals(LoadState.UNKNOWN));
emp = em.getReference(Employee.class, emp.getId());
assertTrue("(NonWeaved) ProviderUtil did not return UNKNOWN for isLoaded when it should.", util.isLoaded(emp).equals(LoadState.UNKNOWN));
}
assertTrue("ProviderUtil did not return UNKNOWN for isLoaded when it should.", util.isLoaded(new NonEntity()).equals(LoadState.UNKNOWN));
} finally {
rollbackTransaction(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.NonEntity in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoadedWithoutReferenceAttribute.
public void testIsLoadedWithoutReferenceAttribute() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("Abe");
emp.setLastName("Jones");
Address addr = new Address();
addr.setCity("Palo Alto");
emp.setAddress(addr);
PhoneNumber pn = new PhoneNumber();
pn.setNumber("1234456");
pn.setType("Home");
emp.addPhoneNumber(pn);
pn.setOwner(emp);
Employee manager = new Employee();
manager.addManagedEmployee(emp);
emp.setManager(manager);
em.persist(emp);
em.flush();
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
emp.getAddress().getCity();
emp.getPhoneNumbers().size();
ProviderUtil util = (new PersistenceProvider()).getProviderUtil();
if (emp instanceof PersistenceWeaved) {
assertTrue("ProviderUtil did not return LOADED for isLoaded for address when it should.", util.isLoadedWithReference(emp, "address").equals(LoadState.LOADED));
assertTrue("ProviderUtil did not return NOT_LOADED for isLoaded for manager when it should.", util.isLoadedWithReference(emp, "manager").equals(LoadState.NOT_LOADED));
} else {
assertTrue("(Unweaved) ProviderUtil did not return LOADED for isLoaded for address when it should.", util.isLoadedWithReference(emp, "address").equals(LoadState.LOADED));
assertTrue("(Unweaved) ProviderUtil did not return LOADED for isLoaded for manager when it should.", util.isLoadedWithReference(emp, "manager").equals(LoadState.LOADED));
}
assertTrue("ProviderUtil did not return LOADED for isLoaded for phoneNumbers when it should.", util.isLoadedWithReference(emp, "phoneNumbers").equals(LoadState.LOADED));
assertTrue("ProviderUtil did not return NOT_LOADED for isLoaded for projects when it should.", util.isLoadedWithReference(emp, "projects").equals(LoadState.NOT_LOADED));
assertTrue("ProviderUtil did not return UNKNOWN for isLoaded when it should.", util.isLoaded(new NonEntity()).equals(LoadState.UNKNOWN));
} finally {
rollbackTransaction(em);
}
}
Aggregations