use of ca.bc.gov.hlth.hnweb.model.v3.Address in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testGetIdentifier.
public void testGetIdentifier() {
EntityManagerFactory emf = getEntityManagerFactory();
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);
em.persist(emp);
em.flush();
Integer id = emp.getId();
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
Object retrievedId = util.getIdentifier(emp);
assertTrue("Got an incorrect id from persistenceUtil.getIdentifier()", id.equals(retrievedId));
} finally {
rollbackTransaction(em);
}
}
use of ca.bc.gov.hlth.hnweb.model.v3.Address in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testClassInstanceConverter.
public void testClassInstanceConverter() {
EntityManager em = createEntityManager();
beginTransaction(em);
Address add = new Address();
add.setCity("St. Louis");
add.setType(new Bungalow());
em.persist(add);
commitTransaction(em);
int assignedSequenceNumber = add.getId();
em.clear();
getDatabaseSession().getIdentityMapAccessor().initializeAllIdentityMaps();
add = em.find(Address.class, assignedSequenceNumber);
assertTrue("Did not correctly persist a mapping using a class-instance converter", (add.getType() instanceof Bungalow));
beginTransaction(em);
em.remove(add);
commitTransaction(em);
}
use of ca.bc.gov.hlth.hnweb.model.v3.Address in project eclipselink by eclipse-ee4j.
the class EmployeePopulator method addressExample1.
public Address addressExample1() {
Address address = new Address();
address.setCity("Toronto");
address.setPostalCode("L5J2B5");
address.setProvince("ONT");
address.setStreet("1450 Acme Cr., suite 4");
address.setCountry("Canada");
return address;
}
use of ca.bc.gov.hlth.hnweb.model.v3.Address in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoadedWithReference.
public void testIsLoadedWithReference() {
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();
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 LOADED for isLoaded for phoneNumbers when it should.", util.isLoadedWithReference(emp, "phoneNumbers").equals(LoadState.LOADED));
if (emp instanceof PersistenceWeaved) {
assertTrue("ProviderUtil did not return NOT_LOADED for isLoaded for manager when it should.", util.isLoadedWithReference(emp, "manager").equals(LoadState.NOT_LOADED));
} else {
assertTrue("(NonWeaved) ProviderUtil did not return LOADED for isLoaded for manager when it should.", util.isLoadedWithReference(emp, "manager").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));
} finally {
rollbackTransaction(em);
}
}
use of ca.bc.gov.hlth.hnweb.model.v3.Address in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testSetFieldForPropertyAccessWithRefresh.
/**
* Bug 801
* Test to ensure when property access is used and the underlying variable is changed the change
* is correctly reflected in the database
*
* In this test we test making the change after the object is refreshed
*/
public void testSetFieldForPropertyAccessWithRefresh() {
EntityManager em = createEntityManager();
Employee employee = new Employee();
employee.setFirstName("Andy");
employee.setLastName("Dufresne");
Address address = new Address();
address.setCity("Shawshank");
employee.setAddress(address);
Employee manager = new Employee();
manager.setFirstName("Bobby");
manager.setLastName("Dufresne");
employee.setManager(manager);
beginTransaction(em);
em.persist(employee);
commitTransaction(em);
int id = employee.getId();
int addressId = address.getID();
int managerId = manager.getId();
beginTransaction(em);
employee = em.getReference(Employee.class, employee.getId());
em.refresh(employee);
employee.getAddress();
address = new Address();
address.setCity("Metropolis");
employee.setAddress(address);
manager = new Employee();
manager.setFirstName("Metro");
manager.setLastName("Dufresne");
employee.setManagerField(manager);
try {
commitTransaction(em);
} catch (RuntimeException e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw e;
}
clearCache();
em = createEntityManager();
beginTransaction(em);
employee = em.find(Employee.class, id);
address = employee.getAddress();
manager = employee.getManager();
assertTrue("The address was not persisted.", employee.getAddress() != null);
assertTrue("The address was not correctly persisted.", employee.getAddress().getCity().equals("Metropolis"));
assertTrue("The manager was not persisted.", employee.getManager() != null);
assertTrue("The manager was not correctly persisted.", employee.getManager().getFirstName().equals("Metro"));
Address initialAddress = em.find(Address.class, addressId);
Employee initialManager = em.find(Employee.class, managerId);
employee.setAddress((Address) null);
employee.setManager(null);
em.remove(address);
em.remove(employee);
em.remove(manager);
em.remove(initialAddress);
em.remove(initialManager);
commitTransaction(em);
}
Aggregations