Package org.apache.jdo.tck.pc.company

Examples of org.apache.jdo.tck.pc.company.Department


        Collection expected;
        Object result;
           
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Department dept1 = reader.getDepartment("dept1");
        expected = new HashSet();
        expected.add(reader.getFullTimeEmployee("emp1"));
        expected.add(reader.getFullTimeEmployee("emp2"));
        expected.add(reader.getPartTimeEmployee("emp3"));
           
View Full Code Here


        Collection expected;
        Object result;
           
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Department dept1 = reader.getDepartment("dept1");
        expected = new HashSet();
        expected.add(reader.getFullTimeEmployee("emp1"));
        expected.add(reader.getFullTimeEmployee("emp2"));
        expected.add(reader.getPartTimeEmployee("emp3"));
           
View Full Code Here

           
            // Set relationship
            Object emp4Oid = getOidByName("emp4");
            Employee emp4 = (Employee)pm.getObjectById(emp4Oid);
            Object dept2Oid = getOidByName("dept2");
            Department dept2 = (Department)pm.getObjectById(dept2Oid);

            dept1.addEmployee(emp4);
            pm.flush();
           
            // Postcondition
            deferredAssertTrue(emp4.getDepartment() == dept1,
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "other side of relationship not set on flush");
            deferredAssertTrue(!dept2.getEmployees().contains(emp4),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "previous relationship not unset on flush");
            pm.currentTransaction().commit();
            cleanupPM();
            getPM();
           
            pm.currentTransaction().begin();
            emp4 = (Employee)pm.getObjectById(emp4Oid);
            dept1 = (Department)pm.getObjectById(dept1Oid);
            dept2 = (Department)pm.getObjectById(dept2Oid);
            deferredAssertTrue(emp4.getDepartment() == dept1,
                ASSERTION_FAILED + testMethod,
                "In new transaction, postcondition is false; " +
                "other side of relationship is not set.");
            deferredAssertTrue(!dept2.getEmployees().contains(emp4),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "previous relationship not unset on flush");
            pm.currentTransaction().commit();
           
View Full Code Here

           
            // Set relationship
            Object emp4Oid = getOidByName("emp4");
            Employee emp4 = (Employee)pm.getObjectById(emp4Oid);
            Object dept2Oid = getOidByName("dept2");
            Department dept2 = (Department)pm.getObjectById(dept2Oid);

            Set emps = new HashSet();
            emps.add(emp4);
            dept1.setEmployees(emps);
            pm.flush();
           
            // Postcondition
            deferredAssertTrue(emp4.getDepartment() == dept1,
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "other side of relationship not set on flush");
            deferredAssertTrue(!dept2.getEmployees().contains(emp4),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "previous relationship not unset on flush");
            pm.currentTransaction().commit();
            cleanupPM();
            getPM();
           
            pm.currentTransaction().begin();
            emp4 = (Employee)pm.getObjectById(emp4Oid);
            dept1 = (Department)pm.getObjectById(dept1Oid);
            dept2 = (Department)pm.getObjectById(dept2Oid);
            deferredAssertTrue(emp4.getDepartment() == dept1,
                ASSERTION_FAILED + testMethod,
                "In new transaction, postcondition is false; " +
                "other side of relationship is not set.");
            deferredAssertTrue(!dept2.getEmployees().contains(emp4),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "previous relationship not unset on flush");
            pm.currentTransaction().commit();
           
View Full Code Here

    public void testSetToNewFromMappedSide() {
        testMethod = "testSetToNewFromMappedSide";
        if (isTestToBePerformed) {
           
            // Set relationship
            IDepartment deptNew = new Department(99L, "The New Department");
            pm.makePersistent(deptNew);
            emp1.setDepartment(deptNew);
            Object deptNewOid = pm.getObjectId((Object)deptNew);
            pm.flush();
           
            assertFalse(testMethod + ": Test aborted, precondition is false; " +
                "expected deptNewOid to be non-null", deptNewOid == null);
           
            // Postcondition
            deferredAssertTrue(deptNew.getEmployees().contains(emp1),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "other side of relationship not set on flush");
            deferredAssertTrue(!dept1.getEmployees().contains(emp1),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "previous relationship (dept1) not nulled on flush");
           
            pm.currentTransaction().commit();
            cleanupPM();
            getPM();
           
            pm.currentTransaction().begin();
            emp1 = (Employee)pm.getObjectById(emp1Oid);
            deptNew = (Department)pm.getObjectById(deptNewOid);
            dept1 = (Department)pm.getObjectById(dept1Oid);
            deferredAssertTrue(deptNew.getEmployees().contains(emp1),
                ASSERTION_FAILED + testMethod,
                "Postcondition is false; "
                + "other side of relationship not set in new pm");
            deferredAssertTrue(!dept1.getEmployees().contains(emp1),
                ASSERTION_FAILED + testMethod,
View Full Code Here

        Transaction tx = pm.currentTransaction();
        try {
            tx.setNontransactionalRead(true);
            tx.begin();
            Company c = new Company(1L, "MyCompany", new Date(), null);
            Department d = new Department(999, "MyDepartment", c);
            pm.makePersistent(c);
            pm.makePersistent(d);
            Object oid = pm.getObjectId(d);
            if (!tx.getNontransactionalRead()) {
                fail(ASSERTION_FAILED,
                     "tx.getNontransactionalRead returns false after setting the flag to true.");
            }
            tx.commit();
            if (!tx.getNontransactionalRead()) {
                fail(ASSERTION_FAILED,
                     "tx.getNontransactionalRead returns false after setting the flag to true.");
            }

            // make sure transaction is not active
            if (tx.isActive()) {
                fail(ASSERTION_FAILED,
                     "transaction still active after tx.commit.");
            }
            tx = null;

            // read department
            d = (Department)pm.getObjectById(oid, true);
            long deptid = d.getDeptid();
            if (deptid != 999) {
                fail("Reading department outside of a transaction returns unexpected value of d.deptid, expected 999, got " + deptid);
            }

            // navigate from department to company
            c = (Company)d.getCompany();
            if (c == null) {
                 fail("Navigating from department to company outside of a transaction returns null.");
            }
            String companyName = c.getName();
            if (!"MyCompany".equals(companyName)) {
                fail("Navigated company returns unexpected value of c.name, expected MyCompany, got " + companyName);
            }

            // run query
            Query q = pm.newQuery(Department.class);
            q.setFilter("name == \"MyDepartment\"");
            Collection result = (Collection)q.execute();
            Iterator i = result.iterator();
            if (!i.hasNext()) {
                fail(ASSERTION_FAILED,
                     "Query outside of a transaction returned empty collection.");
            }
            d = (Department)i.next();
            String deptName = d.getName();
            if (!"MyDepartment".equals(deptName)) {
                fail("Department in query result returns unexpected value of d.name, expected MyDepartment, got " + deptName);
            }
            if (i.hasNext()) {
                fail(ASSERTION_FAILED,
View Full Code Here

        Transaction tx = pm.currentTransaction();
        try {
            tx.setNontransactionalRead(false);
            tx.begin();
            Company c = new Company(1L, "MyCompany", new Date(), null);
            Department d = new Department(999, "MyDepartment", c);
           
            pm.makePersistent(c);
            pm.makePersistent(d);
            if (tx.getNontransactionalRead()) {
                fail(ASSERTION_FAILED,
                     "tx.getNontransactionalRead before commit returns true after setting the flag to false.");
            }
            tx.commit();
            if (tx.getNontransactionalRead()) {
                fail(ASSERTION_FAILED,
                     "tx.getNontransactionalRead after commit returns true after setting the flag to false.");
            }

            // make sure transaction is not active
            if (tx.isActive()) {
                fail(ASSERTION_FAILED,
                     "transaction still active after tx.commit.");
            }
            tx = null;

            try {
                // read department name
                String name = d.getName();
                fail(ASSERTION_FAILED,
                     "Field read permitted outside an active transaction when NontransactionalRead is false.");
            } catch (JDOUserException juex) {
                 if (debug)
                     logger.debug(" Caught expected JDOUserException " + juex);
            }
            try {
                // navigate from department to company
                c = (Company)d.getCompany();
                fail(ASSERTION_FAILED,
                     "Navigation permitted outside an active transaction when NontransactionalRead is false.");
            } catch (JDOUserException juex) {
                 if (debug)
                     logger.debug(" Caught expected JDOUserException " + juex);
View Full Code Here

        Collection expected;
        Object result;
           
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Department dept1 = (Department)reader.getDepartment("dept1");
        expected = new HashSet();
        expected.add(reader.getFullTimeEmployee("emp1"));
        expected.add(reader.getFullTimeEmployee("emp2"));
        expected.add(reader.getPartTimeEmployee("emp3"));
           
View Full Code Here

   
    /** */
    public void testNegative() {
        // get parameter dept1
        getPM().currentTransaction().begin();
        Department dept1 = (Department) getPersistentCompanyModelInstance("dept1");
        getPM().currentTransaction().commit();
       
        // pass parameter dept1 to query of different pm
        PersistenceManager pm2 = pmf.getPersistenceManager();
        pm2.currentTransaction().begin();
View Full Code Here

                                            born.getTime(), addr3,
                                            hired.getTime(), 400000.0);
        scott.addToTeam(ed);

        // Set up their departments.
        Department board =
            new Department(2001L, "board", company);
        h = new HashSet();
        h.add(scott);
        board.setEmployees(h);
        scott.setDepartment(board);
       
        company.addDepartment(board);

        Department emg = new Department(2002L, "emg", company);
        h = new HashSet();
        h.add(ed);
        emg.setEmployees(h);
        ed.setDepartment(emg);
       
        company.addDepartment(emg);

        // Insure these guys
View Full Code Here

TOP

Related Classes of org.apache.jdo.tck.pc.company.Department

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.