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

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


    /** */
    protected void initDB() {
        HashSet h;
        Address addr1 = new Address (7001L, "18 Network Circle",
                                     "Santa Clara", "CA", "94455", "USA");
        company = new Company (1L, "Sun Microsystems", new Date(), addr1);
        GregorianCalendar born =
            new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
        GregorianCalendar hired =
            new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));

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,"","","","",""));
        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

    /** */
    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);
        if( curr != PERSISTENT_NEW ){
            fail(ASSERTION_FAILED, "dep1 should be persistent-new, state is " + states[curr]);
        }
        curr = currentState(dep2);
        if( curr != PERSISTENT_NEW ){
            fail(ASSERTION_FAILED, "dep2 should be persistent-new, state is " + states[curr]);
        }
        curr = currentState(dep3);
        if( curr != PERSISTENT_NEW ){
            fail(ASSERTION_FAILED, "dep3 should be persistent-new, state is " + states[curr]);
        }
        //Remove departments
        comp.removeDepartment(dep1);
        comp.removeDepartment(dep2);
        comp.removeDepartment(dep3);
        tx.commit(); //Now the removed departments should be made transient again
    }
View Full Code Here

    /** This tests that persistence-capable instances track changes or notify their owning instance that they are dirty */
    public void testPCInstance() {
        pm = getPM();
    pm.currentTransaction().begin();
    Company comp = getPersistentNewInstance(0);
    pm.currentTransaction().commit(); // obj should transition to hollow
    testHollowInstance(comp);
    pm.currentTransaction().begin();
    makePersistentCleanInstance(comp);

    Address addr = (Address)comp.getAddress();
    addr.setStreet("200 Orange Street"); // comp or addr should transition to persistent-dirty
    int currComp = currentState(comp);
    int currAddr = currentState(addr);
    if ((currComp != PERSISTENT_DIRTY) && (currAddr != PERSISTENT_DIRTY)){
        fail(ASSERTION_FAILED,
View Full Code Here

    /** This tests that mutable system class instances track changes or notify their owning instance that they are dirty */
    public void testMutableSystemClass() {
        pm = getPM();
        pm.currentTransaction().begin();
        Company comp = getPersistentNewInstance(1);
        pm.currentTransaction().commit(); // obj should transition to hollow
        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

    }
    }

  public Company getPersistentNewInstance(long companyid)
  {
    Company obj = new Company(companyid, "MyCompany", new Date(), new Address(0,"","","","",""));
      pm.makePersistent(obj); // obj should transition to persistent-new
      int curr = currentState(obj);
      if( curr != PERSISTENT_NEW ){
          fail(ASSERTION_FAILED,
        "Unable to create persistent-new 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
View Full Code Here

    public void runTestWhenNontransactionalReadIsFalse(PersistenceManager pm) {
        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()) {
View Full Code Here

TOP

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

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.