Package org.apache.jdo.tck.pc.mylib

Examples of org.apache.jdo.tck.pc.mylib.VersionedPCPoint


           p5oid = pm1.getObjectId(p5);
           tx1.commit();
          
           // update/delete the instances in tx1
           tx1.begin();
           VersionedPCPoint p1tx1 = (VersionedPCPoint)pm1.getObjectById(p1oid, true);
           VersionedPCPoint p2tx1 = (VersionedPCPoint)pm1.getObjectById(p2oid, true);
           VersionedPCPoint p3tx1 = (VersionedPCPoint)pm1.getObjectById(p3oid, true);
           VersionedPCPoint p4tx1 = (VersionedPCPoint)pm1.getObjectById(p4oid, true);
           p1tx1.setX(101);
           p2tx1.setX(201);
           pm1.deletePersistent(p3tx1);
           pm1.deletePersistent(p4tx1);
          
           // update/delete the instances in tx2
           tx2.begin();
           VersionedPCPoint p1tx2 = (VersionedPCPoint)pm2.getObjectById(p1oid, true);
           VersionedPCPoint p2tx2 = (VersionedPCPoint)pm2.getObjectById(p2oid, true);
           VersionedPCPoint p3tx2 = (VersionedPCPoint)pm2.getObjectById(p3oid, true);
           VersionedPCPoint p4tx2 = (VersionedPCPoint)pm2.getObjectById(p4oid, true);
           VersionedPCPoint p5tx2 = (VersionedPCPoint)pm2.getObjectById(p5oid, true);
           p1tx2.setX(102);
           pm2.deletePersistent(p2tx2);
           p3tx2.setX(202);
           pm2.deletePersistent(p4tx2);
           p5tx2.setX(502); // this change must not be committed
           Set expectedFailedObjects = new HashSet();
           expectedFailedObjects.add(p1tx2);
           expectedFailedObjects.add(p2tx2);
           expectedFailedObjects.add(p3tx2);
           expectedFailedObjects.add(p4tx2);
          
           // commit tx1 (should succeed)
           tx1.commit();
           tx1 = null;
          
           // commit tx2 (should fail)
           try {
               tx2.commit();
               fail(ASSERTION_FAILED, "concurrent commit not detected");
           }
           catch (JDOOptimisticVerificationException ex) {
               // verify the correct information in the exception
               Throwable[] ts = ex.getNestedExceptions();
               int length = ts==null ? 0 : ts.length;
               int expectedFailures = expectedFailedObjects.size();
               if (length != expectedFailures) {
                   fail(ASSERTION_FAILED,
                        "Nested exceptions[] wrong size: expected " +
                        expectedFailures + ", got " + length);
               }
               for (int i = 0; i < length; ++i) {
                   Throwable t = ts[i];
                   if (t instanceof JDOOptimisticVerificationException) {
                       if (debug)
                           logger.debug("Expected exception caught " + t.toString());
                       JDOException jex = (JDOException)t;
                       Object failed = jex.getFailedObject();
                       if (failed == null) {
                           fail(ASSERTION_FAILED,
                                "Found unexpected null in failed object");
                       }
                       else {
                           if (expectedFailedObjects.remove(failed)) {
                               if (debug)
                                   logger.debug("Found expected failed instance, oid: " +
                                                JDOHelper.getObjectId(failed));
                           }
                           else {
                               fail(ASSERTION_FAILED,
                                    "Unexpected failed instance: " + failed.toString());
                           }
                       }
                   }
                   else {
                       fail(ASSERTION_FAILED,
                            "Unexpected nested exception: " + t.toString());
                   }
               }
           }
           tx2 = null;
          
           tx3.begin();
           VersionedPCPoint p1tx3 = (VersionedPCPoint)pm3.getObjectById(p1oid, true);
           VersionedPCPoint p2tx3 = (VersionedPCPoint)pm3.getObjectById(p2oid, true);
           VersionedPCPoint p5tx3 = (VersionedPCPoint)pm3.getObjectById(p5oid, true);
           verify(p1tx3, 101);
           verify(p2tx3, 201);
           verify(p5tx3, 5);
           tx3.commit();
           tx3 = null;
View Full Code Here


        addTearDownClass(VersionedPCPoint.class);
        getPM().currentTransaction().begin();
        pm.currentTransaction().setNontransactionalWrite(true);
        pm.currentTransaction().setNontransactionalRead(true);
        pm.currentTransaction().setRetainValues(true);
        VersionedPCPoint instance =  new VersionedPCPoint(originalXValue, 200);
        pm.makePersistent(instance);
        oid = pm.getObjectId(instance);
        pm.currentTransaction().commit();
        instance.setX(newXValue);
        return instance;
    }
View Full Code Here

     */
    protected void checkXValue(String location, int expectedXValue) {
        PersistenceManager pmCheck = pmf.getPersistenceManager();
        try {
            pmCheck.currentTransaction().begin();
            VersionedPCPoint instance =
                (VersionedPCPoint)pmCheck.getObjectById(oid, true);
            int actualXValue = instance.getX();
            pmCheck.currentTransaction().commit();
            if (expectedXValue != actualXValue) {
                appendMessage(location + NL +
                              "expected: " + expectedXValue + NL +
                              "  actual: " + actualXValue);
View Full Code Here

    protected void conflictingUpdate() {
        PersistenceManager pmConflict = pmf.getPersistenceManager();
        try {
            pmConflict.currentTransaction().setOptimistic(false);
            pmConflict.currentTransaction().begin();
            VersionedPCPoint instance =
                (VersionedPCPoint)pmConflict.getObjectById(oid);
            instance.setX(conflictXValue);
            pmConflict.currentTransaction().commit();
        } finally {
            cleanupPM(pmConflict);
        }
    }
View Full Code Here

           p5oid = pm1.getObjectId(p5);
           tx1.commit();
          
           // update/delete the instances in tx1
           tx1.begin();
           VersionedPCPoint p1tx1 = (VersionedPCPoint)pm1.getObjectById(p1oid, true);
           VersionedPCPoint p2tx1 = (VersionedPCPoint)pm1.getObjectById(p2oid, true);
           VersionedPCPoint p3tx1 = (VersionedPCPoint)pm1.getObjectById(p3oid, true);
           VersionedPCPoint p4tx1 = (VersionedPCPoint)pm1.getObjectById(p4oid, true);
           p1tx1.setX(101);
           p2tx1.setX(201);
           pm1.deletePersistent(p3tx1);
           pm1.deletePersistent(p4tx1);
          
           // update/delete the instances in tx2
           tx2.begin();
           VersionedPCPoint p1tx2 = (VersionedPCPoint)pm2.getObjectById(p1oid, true);
           VersionedPCPoint p2tx2 = (VersionedPCPoint)pm2.getObjectById(p2oid, true);
           VersionedPCPoint p3tx2 = (VersionedPCPoint)pm2.getObjectById(p3oid, true);
           VersionedPCPoint p4tx2 = (VersionedPCPoint)pm2.getObjectById(p4oid, true);
           VersionedPCPoint p5tx2 = (VersionedPCPoint)pm2.getObjectById(p5oid, true);
           p1tx2.setX(102);
           pm2.deletePersistent(p2tx2);
           p3tx2.setX(202);
           pm2.deletePersistent(p4tx2);
           p5tx2.setX(502); // this change must not be committed
           Set expectedFailedObjects = new HashSet();
           expectedFailedObjects.add(p1tx2);
           expectedFailedObjects.add(p2tx2);
           expectedFailedObjects.add(p3tx2);
           expectedFailedObjects.add(p4tx2);
          
           // commit tx1 (should succeed)
           tx1.commit();
           tx1 = null;
          
           // commit tx2 (should fail)
           try {
               tx2.commit();
               fail(ASSERTION_FAILED, "concurrent commit not detected");
           }
           catch (JDOOptimisticVerificationException ex) {
               // verify the correct information in the exception
               Throwable[] ts = ex.getNestedExceptions();
               int length = ts==null ? 0 : ts.length;
               int expectedFailures = expectedFailedObjects.size();
               if (length != expectedFailures) {
                   fail(ASSERTION_FAILED,
                        "Nested exceptions[] wrong size: expected " +
                        expectedFailures + ", got " + length);
               }
               for (int i = 0; i < length; ++i) {
                   Throwable t = ts[i];
                   if (t instanceof JDOOptimisticVerificationException) {
                       if (debug)
                           logger.debug("Expected exception caught " + t.toString());
                       JDOException jex = (JDOException)t;
                       Object failed = jex.getFailedObject();
                       if (failed == null) {
                           fail(ASSERTION_FAILED,
                                "Found unexpected null in failed object");
                       }
                       else {
                           if (expectedFailedObjects.remove(failed)) {
                               if (debug)
                                   logger.debug("Found expected failed instance, oid: " +
                                                JDOHelper.getObjectId(failed));
                           }
                           else {
                               fail(ASSERTION_FAILED,
                                    "Unexpected failed instance: " + failed.toString());
                           }
                       }
                   }
                   else {
                       fail(ASSERTION_FAILED,
                            "Unexpected nested exception: " + t.toString());
                   }
               }
           }
           tx2 = null;
          
           tx3.begin();
           VersionedPCPoint p1tx3 = (VersionedPCPoint)pm3.getObjectById(p1oid, true);
           VersionedPCPoint p2tx3 = (VersionedPCPoint)pm3.getObjectById(p2oid, true);
           VersionedPCPoint p5tx3 = (VersionedPCPoint)pm3.getObjectById(p5oid, true);
           verify(p1tx3, 101);
           verify(p2tx3, 201);
           verify(p5tx3, 5);
           tx3.commit();
           tx3 = null;
View Full Code Here

    public void localSetUp () {
        addTearDownClass(VersionedPCPoint.class);
        pm = getPM();
        Transaction tx = pm.currentTransaction();
        tx.begin();
        VersionedPCPoint pnt = new VersionedPCPoint (0,0);
        pm.makePersistent(pnt);
        oid = pm.getObjectId((Object)pnt);
        tx.commit();
    }
View Full Code Here

        if (debug) logger.debug ("\nSTART RefreshAllNoParameterSideEffects");

        Transaction tx1 = pm1.currentTransaction();
        tx1.setOptimistic(true);
        tx1.begin();
        VersionedPCPoint pnt1 = (VersionedPCPoint)pm1.getObjectById(oid, true);
        pnt1.setX(11)// make transactional

        Transaction tx2 = pm2.currentTransaction();
        tx2.begin();
        VersionedPCPoint pnt2 = (VersionedPCPoint)pm2.getObjectById(oid);
        pnt2.setX(22);
        pnt2.setY(Integer.valueOf("22"));
        tx2.commit();

        if (doRefresh)
            pm1.refreshAll();
        pnt1.setX(33);
        pnt1.setY(Integer.valueOf("33"));
        try {
            tx1.commit();
        } catch (javax.jdo.JDOOptimisticVerificationException ove) {
            if (doRefresh) {
                appendMessage("Expected no exception on commit with doRefresh "
                        + "true, but got " + ove.toString());
            }
            // else expect exception
        } catch (Exception e) {
            appendMessage("Unexpected exception on commit. doRefresh is "
                    + doRefresh + ".  Exception is: " + e.toString());
        }

        // verify that correct value was committed
        VersionedPCPoint pntExpected = new VersionedPCPoint(33, 33);
        if (!doRefresh) {
            pntExpected.setX(22);
            pntExpected.setY(Integer.valueOf("22"));
        }
           
        Transaction txVerify = pmVerify.currentTransaction();
        txVerify.begin();
        VersionedPCPoint pntVerify =
                (VersionedPCPoint)pmVerify.getObjectById(oid, true);
        if (pntVerify.getX() != pntExpected.getX()
                || pntVerify.getY().intValue() != pntExpected.getY().intValue())
        {
            appendMessage("After commit with doRefresh " + doRefresh
                    + " expected ("
                    + pntExpected.getX() + ", " + pntExpected.getY()
                    + ") but actual is ("
                    + pntVerify.getX() + ", " + pntVerify.getY() + ").");
        }
        txVerify.commit();
       
        if (debug) logger.debug ("END RefreshAllNoParameterSideEffects"
                + "doRefresh is " + doRefresh);
View Full Code Here

    public void localSetUp () {
        addTearDownClass(VersionedPCPoint.class);
        pm = getPM();
        Transaction tx = pm.currentTransaction();
        tx.begin();
        VersionedPCPoint pnt1 = new VersionedPCPoint(0,0);
        VersionedPCPoint pnt2 = new VersionedPCPoint (-1,-1);
        coll.add(pnt1);
        coll.add(pnt2);
        pm.makePersistentAll(coll);

        oids.add(0, pm.getObjectId((Object)pnt1));
View Full Code Here

            appendMessage("Unexpected exception on commit. doRefresh is "
                    + doRefresh + ".  Exception is: " + e.toString());
        }

        // verify that correct value was committed
        VersionedPCPoint pntExpected = new VersionedPCPoint(33, 33);
        if (!doRefresh) {
            pntExpected.setX(22);
            pntExpected.setY(Integer.valueOf("22"));
        }
           
        Transaction txVerify = pmVerify.currentTransaction();
        txVerify.begin();
        Collection pointsVerify =
                pmVerify.getObjectsById(oids, true);
        if (((VersionedPCPoint)pointsVerify.toArray()[0]).getX()
                != pntExpected.getX()
                || ((VersionedPCPoint)pointsVerify.toArray()[0]).getY().intValue()
                != pntExpected.getY().intValue())
        {
            appendMessage("After commit with doRefresh " + doRefresh
                    + " expected ("
                    + pntExpected.getX() + ", " + pntExpected.getY()
                    + ") but actual is ("
                    + ((VersionedPCPoint)pointsVerify.toArray()[0]).getX()
                    + ", "
                    + ((VersionedPCPoint)pointsVerify.toArray()[0]).getY().intValue()
                    + ").");
View Full Code Here

    /** Test for JDOHelper.getVersion() in queries. */
    public void testGetVersion() {
        // create some sample data
        pm.currentTransaction().begin();
        VersionedPCPoint pt1 = new VersionedPCPoint(1, 2);
        pm.makePersistent(pt1);
        pm.currentTransaction().commit();
        Object id = pm.getObjectId(pt1);

        try
View Full Code Here

TOP

Related Classes of org.apache.jdo.tck.pc.mylib.VersionedPCPoint

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.