Examples of BidirectionalAssociationObjectA


Examples of org.apache.ojb.broker.BidirectionalAssociationObjectA

        Database db = odmg.newDatabase();
        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();
        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);

View Full Code Here

Examples of org.apache.ojb.broker.BidirectionalAssociationObjectA

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        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

Examples of org.apache.ojb.broker.BidirectionalAssociationObjectA

        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();
        BidirectionalAssociationObjectA temp = null;
        while (it.hasNext())
        {
            temp = (BidirectionalAssociationObjectA) it.next();
            if (temp.getRelatedB() == null)
                fail("should have relatedB");
            i++;
        }
        tx.commit();
        if (i == 0)
View Full Code Here

Examples of org.apache.ojb.broker.BidirectionalAssociationObjectA

     * test deleting an object participating in a bidirectional associative relationship. Will throw if it can't delete.
     * @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
            }
View Full Code Here

Examples of org.apache.ojb.broker.BidirectionalAssociationObjectA

     * test deleting an object participating in a bidirectional associative relationship. Will throw if it can't delete.
     * @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
            }
            db.deletePersistent(b);
        }

        tx.commit();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.