Search in sources :

Example 16 with Address

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);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_2.Employee) Address(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_1.Address) JpaEntityManagerFactory(org.eclipse.persistence.jpa.JpaEntityManagerFactory) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceUnitUtil(jakarta.persistence.PersistenceUnitUtil) PhoneNumber(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.PhoneNumber)

Example 17 with Address

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) Address(org.eclipse.persistence.testing.models.jpa.xml.composite.advanced.member_1.Address) Bungalow(org.eclipse.persistence.testing.models.jpa.xml.composite.advanced.member_1.Bungalow)

Example 18 with Address

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;
}
Also used : Address(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_1.Address)

Example 19 with 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);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) ProviderUtil(jakarta.persistence.spi.ProviderUtil) Employee(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_2.Employee) PersistenceWeaved(org.eclipse.persistence.internal.weaving.PersistenceWeaved) Address(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_1.Address) PersistenceProvider(org.eclipse.persistence.jpa.PersistenceProvider) PhoneNumber(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_3.PhoneNumber)

Example 20 with Address

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_2.Employee) Address(org.eclipse.persistence.testing.models.jpa.composite.advanced.member_1.Address)

Aggregations

Test (org.junit.Test)91 Address (org.orcid.jaxb.model.record_v2.Address)82 Address (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_1.Address)45 Addresses (org.orcid.jaxb.model.record_v2.Addresses)43 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)43 Keyword (org.orcid.jaxb.model.record_v2.Keyword)42 OtherName (org.orcid.jaxb.model.record_v2.OtherName)42 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)42 Email (org.orcid.jaxb.model.record_v2.Email)41 EntityManager (jakarta.persistence.EntityManager)36 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)35 Biography (org.orcid.jaxb.model.record_v2.Biography)34 Emails (org.orcid.jaxb.model.record_v2.Emails)34 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)33 Keywords (org.orcid.jaxb.model.record_v2.Keywords)32 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)32 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)31 Name (org.orcid.jaxb.model.record_v2.Name)31 Person (org.orcid.jaxb.model.record_v2.Person)31 Employee (org.eclipse.persistence.testing.models.jpa.composite.advanced.member_2.Employee)26