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

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


        pm.currentTransaction().begin();
        makePersistentCleanInstance(comp);

        Set depts = comp.getDepartments();
        // comp or depts should transition to persistent-dirty
        comp.addDepartment(new Department(0, "HR", comp));
        int currComp = currentState(comp);
        int currDepts = currentState(depts);
        if ((currComp != PERSISTENT_DIRTY) && (currDepts != PERSISTENT_DIRTY)){
            fail(ASSERTION_FAILED,
                "Unable to create persistent-dirty instance "
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

        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

   
    /** */
    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

        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = new Company(1L, "Sun Microsystems", new Date(), new Address(0,"","","","",""));
        pm.makePersistent(comp);
        //Add transient departments
        comp.addDepartment(new Department(1L, "Department 1"));
        comp.addDepartment(new Department(2L, "Department 2"));
        comp.addDepartment(new Department(3L, "Department 3"));
        tx.commit(); //Now the transient departments should be made persistent via reachability
    }
View Full Code Here

        boolean foundDep1 = false;
        boolean foundDep2 = false;
        boolean foundDep3 = false;

        for (Iterator i = e.iterator(); i.hasNext();) {
            Department dep = (Department) i.next();
            if (dep.getName().equals("Department 1"))
                foundDep1=true;
            else if (dep.getName().equals("Department 2"))
                foundDep2=true;
            else if (dep.getName().equals("Department 3"))
                foundDep3=true;   
        }

        if (!foundDep1) {
            fail(ASSERTION_FAILED,
View Full Code Here

    private void createObjects(PersistenceManager pm) {
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = new Company(1L, "Sun Microsystems", new Date(), new Address(0,"","","","",""));
        //Add transient departments
        dep1 = new Department(1L, "Department 1");
        dep2 = new Department(2L, "Department 1");
        dep3 = new Department(3L, "Department 1");
        comp.addDepartment(dep1);
        comp.addDepartment(dep2);
        comp.addDepartment(dep3);
        pm.makePersistent(comp); //Now the transient departments should be made provisionally persistent via reachability
        int curr = currentState(dep1);
View Full Code Here

        testHollowInstance(comp);
        pm.currentTransaction().begin();
        makePersistentCleanInstance(comp);

    Set depts = comp.getDepartments();
    comp.addDepartment(new Department(0,"HR",comp)); // comp or depts should transition to persistent-dirty
    int currComp = currentState(comp);
    int currDepts = currentState(depts);
    if ((currComp != PERSISTENT_DIRTY) && (currDepts != PERSISTENT_DIRTY)){
        fail(ASSERTION_FAILED,
        "Unable to create persistent-dirty instance " +
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

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.