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

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


       
        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

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

    public void test() {
        //Try to get a PersistenceManager and begin and commit a transaction
        pm = getPM();
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = new Company(1L, "Sun Microsystems", new Date(),
                                   new Address(0,"","","","",""));
        pm.makePersistent(comp);
        tx.commit();
        pm.close();
        pm = null;
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

        properties.put(Constants.PROPERTY_READONLY, "true");
        pmf2 = JDOHelper.getPersistenceManagerFactory(properties);
        // insert an instance to find
        getPM();
        pm.currentTransaction().begin();
        Company comp = new Company(1L, "Sun Microsystems", new Date(),
                                   new Address(0,"","","","",""));
        pm.makePersistent(comp);
        oid = pm.getObjectId(comp);
        pm.currentTransaction().commit();
        pm.close();
View Full Code Here

    public void testMakePersistent() {
        //Try to makePersistent and flush the transaction
        pm = pmf2.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = new Company(2L, "Sun Microsystems2", new Date(),
                                   new Address(0,"","","","",""));
        try {
            pm.makePersistent(comp);
            pm.flush();
            fail("When the PersistenceManagerFactory is read only, " +
View Full Code Here

        //Try to update and flush the transaction
        pm = pmf2.getPersistenceManager();
        pm.getExtent(Company.class); // make sure that oid class is loaded
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = (Company)pm.getObjectById(oid);
        try {
            comp.setName("new name");
            pm.flush();
            fail("When the PersistenceManagerFactory is read only, " +
                    "flush of an updated instance must throw " +
                    "JDOReadOnlyException.");
        } catch (JDOReadOnlyException jDOReadOnlyException) {
View Full Code Here

        //Try to deletePersistent and flush the transaction
        pm = pmf2.getPersistenceManager();
        pm.getExtent(Company.class); // make sure that oid class is loaded
        Transaction tx = pm.currentTransaction();
        tx.begin();
        Company comp = (Company)pm.getObjectById(oid);
        try {
            pm.deletePersistent(comp);
            pm.flush();
            fail("When the PersistenceManagerFactory is read only, " +
                    "flush of a persistent-deleted instance must throw " +
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

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.