Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.BidirectionalAssociationObjectB


        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();

        BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
        a.setPk("A" + currentTime);
        BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        db.makePersistent(a);
        db.makePersistent(b);
        tx.commit();

        tx.begin();
        tx.lock(a, Transaction.WRITE);
        tx.lock(b, Transaction.WRITE);
        a.setRelatedB(b);
        b.setRelatedA(a);
        tx.commit();

         /**
         * now make sure they are in db, A first, then B
         */
        tx.begin();
        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName() + " where pk=$1");
        query.bind("A"+currentTime);
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();
        while (it.hasNext())
        {
            i++;
            a = (BidirectionalAssociationObjectA) it.next();
            if (a.getRelatedB() == null)
                fail("a should have had a related b");
        }
        if (i > 1)
            fail("should have found only one bidirectionalAssociationObjectA, instead found: " + i);

        query = odmg.newOQLQuery();
        i = 0;
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName() + " where pk=$1");
        query.bind("B"+currentTime);
        all = (ManageableCollection) query.execute();
        it = all.ojbIterator();
        while (it.hasNext())
        {
            i++;
            b = (BidirectionalAssociationObjectB) it.next();
            if (b.getRelatedA() == null)
                fail("b should have had a related a");

        }
        if (i > 1)
            fail("should have found only one bidirectionalAssociationObjectB, instead found: " + i);
View Full Code Here


        db.open(databaseName, Database.OPEN_READ_WRITE);
        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();
        BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
        a.setPk("A" + currentTime);
        BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        b.setRelatedA(a);
        a.setRelatedB(b);
        db.makePersistent(a);
        db.makePersistent(b);
        tx.commit();
View Full Code Here

        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();
        BidirectionalAssociationObjectB temp = null;
        while (it.hasNext())
        {
            temp = (BidirectionalAssociationObjectB) it.next();
            if (temp.getRelatedA() == null)
                fail("should have relatedA");
            i++;
        }
        tx.commit();
        if (i == 0)
View Full Code Here

     * @throws Exception
     */
    public void testDeleteA() throws Exception
    {
        BidirectionalAssociationObjectA a;
        BidirectionalAssociationObjectB b;
        /**
         * create at least one A/B
         */
        testCreateWithUpdate();

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();

        while (it.hasNext())
        {
            a = (BidirectionalAssociationObjectA)it.next();
            b = a.getRelatedB();
            if (b != null)
            {
                tx.lock(b, Transaction.WRITE);
                b.setRelatedA(null);   // break relationship to avoid ri violation
            }
            db.deletePersistent(a);
        }

        tx.commit();
View Full Code Here

     * @throws Exception
     */
    public void testDeleteB() throws Exception
    {
        BidirectionalAssociationObjectA a;
        BidirectionalAssociationObjectB b;

        /**
         * create at least one A/B
         */
        testCreateWithUpdate();
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(databaseName, Database.OPEN_READ_WRITE);
        OQLQuery query = odmg.newOQLQuery();
        query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ManageableCollection all = (ManageableCollection) query.execute();
        java.util.Iterator it = all.ojbIterator();

        while (it.hasNext())
        {
            b = (BidirectionalAssociationObjectB)it.next();
            a = b.getRelatedA();
            if (a != null)
            {
                tx.lock(a, Transaction.WRITE);
                a.setRelatedB(null);    // break relationship to avoid ri violation
            }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.BidirectionalAssociationObjectB

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.