Search in sources :

Example 6 with Manager

use of org.jpox.samples.models.company.Manager in project tests by datanucleus.

the class AttachDetachTest method testAttachDetachNonTransactionalRead.

public void testAttachDetachNonTransactionalRead() {
    try {
        Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
        Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
        Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
        Object id;
        PersistenceManager pm = newPM();
        Transaction tx = pm.currentTransaction();
        tx.setNontransactionalRead(true);
        try {
            tx.begin();
            pm.makePersistent(woody);
            pm.makePersistent(boss);
            pm.makePersistent(bart);
            tx.commit();
            // non transactional read
            Collection c = (Collection) pm.newQuery(Employee.class).execute();
            Employee detachedEmployee = (Employee) pm.detachCopy(c.iterator().next());
            // test with String
            detachedEmployee.setFirstName("detached guy");
            id = JDOHelper.getObjectId(detachedEmployee);
            tx.begin();
            pm.makePersistent(detachedEmployee);
            tx.commit();
            System.gc();
            tx.begin();
            Employee emp = (Employee) pm.getObjectById(id, true);
            assertEquals("expected change in attached instance", "detached guy", emp.getFirstName());
            tx.commit();
            // non transactional read
            c = (Collection) pm.newQuery(Employee.class).execute();
            detachedEmployee = (Employee) pm.detachCopy(c.iterator().next());
            // test with Integer (Object) fields non DFG
            detachedEmployee.setYearsInCompany(new Integer(33));
            id = JDOHelper.getObjectId(detachedEmployee);
            tx.begin();
            pm.makePersistent(detachedEmployee);
            tx.commit();
            System.gc();
            tx.begin();
            emp = (Employee) pm.getObjectById(id, true);
            assertEquals("expected change in attached instance", 33, emp.getYearsInCompany().intValue());
            tx.commit();
            // non transactional read
            c = (Collection) pm.newQuery(Employee.class).execute();
            detachedEmployee = (Employee) pm.detachCopy(c.iterator().next());
            // test with long (Primitive)
            detachedEmployee.setPersonNum(546);
            id = JDOHelper.getObjectId(detachedEmployee);
            tx.begin();
            pm.makePersistent(detachedEmployee);
            tx.commit();
            System.gc();
            tx.begin();
            emp = (Employee) pm.getObjectById(id, true);
            assertEquals("expected change in attached instance", 546, emp.getPersonNum());
            tx.commit();
            // non transactional read
            c = (Collection) pm.newQuery(Employee.class).execute();
            detachedEmployee = (Employee) pm.detachCopy(c.iterator().next());
            // test with PC (Object)
            detachedEmployee.setManager(bart);
            id = JDOHelper.getObjectId(detachedEmployee);
            tx.begin();
            pm.makePersistent(detachedEmployee);
            tx.commit();
            System.gc();
            tx.begin();
            emp = (Employee) pm.getObjectById(id, true);
            assertEquals("expected change in attached instance", bart.getFirstName(), emp.getManager().getFirstName());
            tx.commit();
        } catch (Exception e) {
            LOG.error("Exception in test", e);
            fail(e.toString());
        } finally {
            if (tx.isActive())
                tx.rollback();
            pm.close();
        }
    } finally {
        CompanyHelper.clearCompanyData(pmf);
    }
}
Also used : Employee(org.jpox.samples.models.company.Employee) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Collection(java.util.Collection) ClassWithNonPCCollection(org.datanucleus.samples.detach.ClassWithNonPCCollection) Manager(org.jpox.samples.models.company.Manager) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDODetachedFieldAccessException(javax.jdo.JDODetachedFieldAccessException) JDOUserException(javax.jdo.JDOUserException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Example 7 with Manager

use of org.jpox.samples.models.company.Manager in project tests by datanucleus.

the class AttachDetachTest method attachDetachedManager.

/**
 * Helper method for attaching a detached Manager object
 * @param detached
 * @return the attached object
 */
private Manager attachDetachedManager(Manager detached) {
    PersistenceManager pm = newPM();
    Transaction tx = pm.currentTransaction();
    Object attached = null;
    try {
        tx.begin();
        attached = pm.makePersistent(detached);
        tx.commit();
    } catch (Exception e) {
        LOG.error("Exception in test", e);
        fail(e.toString());
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    return (Manager) attached;
}
Also used : Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Manager(org.jpox.samples.models.company.Manager) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDODetachedFieldAccessException(javax.jdo.JDODetachedFieldAccessException) JDOUserException(javax.jdo.JDOUserException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Example 8 with Manager

use of org.jpox.samples.models.company.Manager in project tests by datanucleus.

the class AttachDetachTest method testDetachAttach_OneToMany.

/**
 * test pc objects aggregating other pcs. associations 1-n
 */
public void testDetachAttach_OneToMany() {
    try {
        Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
        Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
        Manager boss2 = new Manager(4, "Boss", "WakesUp2", "boss2@wakes.up", 5, "serial 4");
        Manager boss3 = new Manager(5, "Boss", "WakesUp3", "boss3@wakes.up", 6, "serial 5");
        Manager boss4 = new Manager(6, "Boss", "WakesUp4", "boss4@wakes.up", 7, "serial 6");
        Manager boss5 = new Manager(7, "Boss", "WakesUp5", "boss5@wakes.up", 8, "serial 7");
        bart.addSubordinate(boss);
        bart.addSubordinate(boss2);
        Department deptB = new Department("DeptB");
        bart.addDepartment(deptB);
        Manager bartDetached;
        Manager bart2;
        Object id;
        Object id2;
        PersistenceManager pm = newPM();
        Transaction tx = pm.currentTransaction();
        pm.getFetchPlan().addGroup("groupSubordinates");
        // This is a fix for the fact that Person hashCode/equals rely on non-PK fields and so use of
        // this class outside of a txn will try to load these fields
        tx.setNontransactionalRead(true);
        try {
            // test detach and attach
            tx.begin();
            pm.makePersistent(bart);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            id = pm.getObjectId(bart);
            Employee employeeChanged = (Employee) bartDetached.getSubordinates().iterator().next();
            employeeChanged.setLastName("Simpson0");
            id2 = JDOHelper.getObjectId(employeeChanged);
            tx.begin();
            bart2 = (Manager) pm.makePersistent(bartDetached);
            tx.commit();
            System.gc();
            tx.begin();
            bart2 = (Manager) pm.getObjectById(id, true);
            employeeChanged = (Employee) pm.getObjectById(id2, true);
            assertEquals(bart2.getSubordinates().size(), 2);
            assertEquals("expected change in attached instance", "Simpson0", employeeChanged.getLastName());
            tx.commit();
            // test pc are the same after attach
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            tx.begin();
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("attached instance returned must be the one already enlisted in the PM", bartDetached.getSubordinates().containsAll(bart2.getSubordinates()));
            tx.commit();
            // test pc are the same after attach, now in different order, first attach and later get object
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("attached instance returned must be the one already enlisted in the PM", bartDetached.getSubordinates().containsAll(bart2.getSubordinates()));
            tx.commit();
            // test changing aggregated pc. add element pc which is not yet persistent
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            assertTrue("pc instance should not be already persistent", !JDOHelper.isPersistent(boss3));
            bartDetached.addSubordinate(boss3);
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            pm.flush();
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("add element to collection was not applied to the datastore", bartDetached.getSubordinates().contains(boss3));
            assertTrue("aggregated pc instance was expected to be made persistent", JDOHelper.isPersistent(boss3));
            // verify if previous boss were not lost
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss));
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss2));
            tx.commit();
            // test changing aggregated pc. add element pc which is already persistent
            tx.begin();
            pm.makePersistent(boss4);
            tx.commit();
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            bartDetached.addSubordinate(boss4);
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("add element to collection was not applied to the datastore", bartDetached.getSubordinates().contains(boss4));
            assertTrue("aggregated pc instance was expected to be made persistent", JDOHelper.isPersistent(boss4));
            // verify if previous boss were not lost
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss));
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss2));
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss3));
            tx.commit();
            // test changing aggregated pc. remove element
            tx.begin();
            pm.makePersistent(boss4);
            tx.commit();
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            bartDetached.removeSubordinate(boss4);
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("remove element in aggregated pc instance was not applied to the datastore", !bartDetached.getSubordinates().contains(boss4));
            assertTrue("aggregated pc instance was expected to be made persistent", JDOHelper.isPersistent(boss4));
            // verify if previous boss were not lost
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss));
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss2));
            assertTrue("previous aggregated pc instances were lost", bartDetached.getSubordinates().contains(boss3));
            tx.commit();
            // test changing aggregated pc. aggregated pc is cleared
            tx.begin();
            pm.makePersistent(boss4);
            tx.commit();
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.setLastName("Simpson1");
            bartDetached.clearSubordinates();
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", bartDetached, bart2);
            assertTrue("clear Collection with aggregated pc instance was not applied to the datastore", bartDetached.getSubordinates().size() == 0);
            tx.commit();
            // test sco fields made dirty
            tx.begin();
            pm.makePersistent(boss5);
            tx.commit();
            tx.begin();
            bart = (Manager) pm.getObjectById(id, true);
            bartDetached = (Manager) pm.detachCopy(bart);
            tx.commit();
            bartDetached.addSubordinate(boss5);
            JDOHelper.makeDirty(bartDetached, "subordinates");
            tx.begin();
            bartDetached = (Manager) pm.makePersistent(bartDetached);
            tx.commit();
            tx.begin();
            bart2 = (Manager) pm.getObjectById(id, true);
            assertEquals(1, bart2.getSubordinates().size());
            assertTrue("SCO field should is missing element", bart2.getSubordinates().contains(boss5));
            assertTrue("element of SCO field is not persistent", JDOHelper.isPersistent(boss5));
            tx.commit();
        } catch (Exception e) {
            LOG.error("Exception in test", e);
            fail(e.toString());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        CompanyHelper.clearCompanyData(pmf);
    }
}
Also used : Department(org.jpox.samples.models.company.Department) Employee(org.jpox.samples.models.company.Employee) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Manager(org.jpox.samples.models.company.Manager) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDODetachedFieldAccessException(javax.jdo.JDODetachedFieldAccessException) JDOUserException(javax.jdo.JDOUserException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Example 9 with Manager

use of org.jpox.samples.models.company.Manager in project tests by datanucleus.

the class AttachDetachTest method testDetachAttach_ManyToOne.

/**
 * test pc objects aggregating other pcs. associations N-1
 */
public void testDetachAttach_ManyToOne() {
    try {
        Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
        Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
        Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
        Manager boss2 = new Manager(4, "Boss", "WakesUp2", "boss2@wakes.up", 5, "serial 4");
        Manager boss3 = new Manager(5, "Boss", "WakesUp3", "boss3@wakes.up", 6, "serial 5");
        woody.setManager(bart);
        Department deptB = new Department("DeptB");
        deptB.setManager(bart);
        Employee woodyDetached;
        Employee bossDetached;
        Object id;
        Object idBoss;
        PersistenceManager pm = newPM();
        Transaction tx = pm.currentTransaction();
        try {
            // -----------------------------------------------------------------------------------------
            // test 1 - test detach and attach
            // -----------------------------------------------------------------------------------------
            tx.begin();
            pm.makePersistent(woody);
            pm.makePersistent(boss);
            pm.makePersistent(deptB);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            id = pm.getObjectId(woody);
            idBoss = pm.getObjectId(boss);
            woodyDetached.getManager().setLastName("Simpson0");
            tx.begin();
            pm.makePersistent(woodyDetached);
            tx.commit();
            System.gc();
            tx.begin();
            Employee woody2 = (Employee) pm.getObjectById(id, true);
            assertEquals("expected change in attached instance", "Simpson0", woody2.getManager().getLastName());
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 2 - test pc are the same after attach
            // -----------------------------------------------------------------------------------------
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            woodyDetached.setLastName("Simpson1");
            tx.begin();
            woody2 = (Employee) pm.getObjectById(id, true);
            Employee woodyAttached = (Employee) pm.makePersistent(woodyDetached);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached, woody2);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached.getManager(), woody2.getManager());
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 3 - test pc are the same after attach, now in different order, first attach and later get object
            // -----------------------------------------------------------------------------------------
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            woodyDetached.setLastName("Simpson1");
            tx.begin();
            woodyAttached = (Employee) pm.makePersistent(woodyDetached);
            woody2 = (Employee) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached, woody2);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached.getManager(), woody2.getManager());
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 4 - test changing aggregated pc. aggregated pc is not yet persistent
            // -----------------------------------------------------------------------------------------
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            woodyDetached.setLastName("Simpson1");
            assertTrue("pc instance should not be already persistent", !JDOHelper.isPersistent(boss3));
            woodyDetached.setManager(boss3);
            tx.begin();
            woodyAttached = (Employee) pm.makePersistent(woodyDetached);
            woody2 = (Employee) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached, woody2);
            assertEquals("changed aggregated pc instance was not applied to the datastore", woodyAttached.getManager(), boss3);
            assertTrue("aggregated pc instance was expected to be made persistent", JDOHelper.isPersistent(boss3));
            tx.commit();
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            assertEquals("changed aggregated pc instance was not applied to the datastore", woody.getManager(), boss3);
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 5 - test changing aggregated pc. aggregated pc is already persistent
            // -----------------------------------------------------------------------------------------
            tx.begin();
            pm.makePersistent(boss2);
            tx.commit();
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            woodyDetached.setLastName("Simpson1");
            woodyDetached.setManager(boss2);
            tx.begin();
            woodyAttached = (Employee) pm.makePersistent(woodyDetached);
            woody2 = (Employee) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached, woody2);
            assertEquals("changed aggregated pc instance was not applied to the datastore", woodyAttached.getManager(), boss2);
            assertTrue("aggregated pc instance was expected to be made persistent", JDOHelper.isPersistent(boss2));
            tx.commit();
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            assertEquals("changed aggregated pc instance was not applied to the datastore", woody.getManager(), boss2);
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 6 - test setting aggregated pc to null
            // -----------------------------------------------------------------------------------------
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            woodyDetached = (Employee) pm.detachCopy(woody);
            tx.commit();
            woodyDetached.setLastName("Simpson1");
            woodyDetached.setManager(null);
            tx.begin();
            woodyAttached = (Employee) pm.makePersistent(woodyDetached);
            woody2 = (Employee) pm.getObjectById(id, true);
            assertEquals("attached instance returned must be the one already enlisted in the PM", woodyAttached, woody2);
            assertEquals("attached instance returned has incorrect last name", "Simpson1", woody2.getLastName());
            assertNull("changed aggregated pc instance was not applied to the datastore. it should be null", woodyAttached.getManager());
            tx.commit();
            tx.begin();
            woody = (Employee) pm.getObjectById(id, true);
            assertNull("changed aggregated pc instance was not applied to the datastore. it should be null", woody.getManager());
            tx.commit();
            // -----------------------------------------------------------------------------------------
            // test 7 - test detach and read aggregated pc field when its null
            // -----------------------------------------------------------------------------------------
            tx.begin();
            boss = (Manager) pm.getObjectById(idBoss, true);
            bossDetached = (Manager) pm.detachCopy(boss);
            tx.commit();
            assertNull("pc field should be null", bossDetached.getManager());
        } catch (Exception e) {
            LOG.error("Exception in test", e);
            fail(e.toString());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        CompanyHelper.clearCompanyData(pmf);
    }
}
Also used : Department(org.jpox.samples.models.company.Department) Employee(org.jpox.samples.models.company.Employee) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Manager(org.jpox.samples.models.company.Manager) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDODetachedFieldAccessException(javax.jdo.JDODetachedFieldAccessException) JDOUserException(javax.jdo.JDOUserException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Example 10 with Manager

use of org.jpox.samples.models.company.Manager in project tests by datanucleus.

the class AttachDetachTest method testFetchDepthOnDetachCopyAll.

/**
 * Test of detachCopyAll with fetch-depth. See JIRA "NUCCORE-24"
 */
public void testFetchDepthOnDetachCopyAll() {
    try {
        Manager bob = new Manager(1, "Bob", "Woodpecker", "bob@woodpecker.com", 13, "serial 1");
        Manager dave = new Manager(1, "Dave", "Woodpecker", "dave@woodpecker.com", 13, "serial 2");
        Employee mary = new Employee(1, "Mary", "Woodpecker", "mary@woodpecker.com", 13, "serial 3");
        mary.setManager(dave);
        dave.setManager(bob);
        PersistenceManager pm = newPM();
        Transaction tx = pm.currentTransaction();
        try {
            // Save Mary will also save Dave and Bob.
            tx.begin();
            pm.makePersistent(mary);
            tx.commit();
            tx.begin();
            // Group A has firstName and manager, amount other things.
            // No max fetch-depth is defined, so they default to 1.
            pm.getFetchPlan().setGroup("groupA");
            Query<Employee> query = pm.newQuery(pm.getExtent(Employee.class, true));
            query.setOrdering("firstName descending");
            Collection<Employee> c = query.executeList();
            c = pm.detachCopyAll(c);
            tx.commit();
            assertEquals("c.size() == 3", c.size(), 3);
            for (Iterator i = c.iterator(); i.hasNext(); ) {
                Employee em = (Employee) i.next();
                try {
                    em.getManager();
                } catch (Exception e) {
                    fail("Manager must be returned for maxFetchDepth of 1 : employee " + em.getFirstName() + " has no manager");
                }
            }
        } catch (Exception e) {
            LOG.error("Exception in test", e);
            fail(e.toString());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        CompanyHelper.clearCompanyData(pmf);
    }
}
Also used : Employee(org.jpox.samples.models.company.Employee) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Iterator(java.util.Iterator) Manager(org.jpox.samples.models.company.Manager) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) JDODetachedFieldAccessException(javax.jdo.JDODetachedFieldAccessException) JDOUserException(javax.jdo.JDOUserException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)106 Manager (org.jpox.samples.models.company.Manager)106 Transaction (javax.jdo.Transaction)97 Department (org.jpox.samples.models.company.Department)50 Query (javax.jdo.Query)48 Employee (org.jpox.samples.models.company.Employee)45 JDOUserException (javax.jdo.JDOUserException)41 Collection (java.util.Collection)40 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)38 StoreManager (org.datanucleus.store.StoreManager)34 InsuranceDepartment (org.jpox.samples.models.company.InsuranceDepartment)29 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)27 Iterator (java.util.Iterator)22 JDODetachedFieldAccessException (javax.jdo.JDODetachedFieldAccessException)17 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)15 JDOException (javax.jdo.JDOException)14 Extent (javax.jdo.Extent)13 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)13 List (java.util.List)11 Properties (java.util.Properties)10