Package org.odmg

Examples of org.odmg.Transaction


            throws Exception
    {
        /**
         * 1. create the objects with specific values we'll search on later.
         */
        Transaction tx = odmg.newTransaction();
        tx.begin();

        Contract contract = new Contract();
        contract.setPk("C" + System.currentTimeMillis());
        contract.setContractValue1("version.contract.contractValue1.testComplexOQL");
        contract.setContractValue2(1);
        contract.setContractValue3("contractvalue3");
        contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
        database.makePersistent(contract);

        RelatedToContract rtc = new RelatedToContract();
        rtc.setPk("R" + System.currentTimeMillis());
        rtc.setRelatedValue1("test");
        rtc.setRelatedValue2(5);
        rtc.setRelatedValue3(new Timestamp(System.currentTimeMillis()));
        contract.setRelatedToContract(rtc);
        database.makePersistent(rtc);

        Version version = new Version();
        version.setPk("V" + System.currentTimeMillis());
        version.setVersionValue1("versionvalue1");
        version.setVersionValue2(1);
        version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
        version.setContract(contract);
        database.makePersistent(version);

        Effectiveness eff = new Effectiveness();
        eff.setPk("E" + System.currentTimeMillis());
        eff.setEffValue1("effValue1.testComplexOQL");
        eff.setEffValue2(20);
        eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
        eff.setVersion(version);
        database.makePersistent(eff);

        tx.commit();
        /**
         * 2. define the complex OQL query to find the object we created
         */
        String oql = "select s from " + org.apache.ojb.broker.Effectiveness.class.getName() + " where " +
                " version.contract.contractValue1=$1 and effValue1 = $2 and " +
View Full Code Here


            throws Exception
    {
        /**
         * 1. create the objects with specific values we'll search on later.
         */
        Transaction tx = odmg.newTransaction();
        tx.begin();

        Contract contract = new Contract();
        contract.setPk("C" + System.currentTimeMillis());
        contract.setContractValue1("version.contract.contractValue1.testComplexOQL");
        contract.setContractValue2(1);
        contract.setContractValue3("contractvalue3");
        contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
        database.makePersistent(contract);

        Version version = new Version();
        version.setPk("V" + System.currentTimeMillis());
        version.setVersionValue1("versionvalue1");
        version.setVersionValue2(1);
        version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
        version.setContract(contract);
        database.makePersistent(version);

        Effectiveness eff = new Effectiveness();
        eff.setPk("E" + System.currentTimeMillis());
        eff.setEffValue1("effValue1.testComplexOQL");
        eff.setEffValue2(20);
        eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
        eff.setVersion(version);
        database.makePersistent(eff);

        tx.commit();
        /**
         * 2. define the complex OQL query to find the object we created
         */
        String oql = "select s from " + org.apache.ojb.broker.Effectiveness.class.getName() + " where " +
                " version.contract.contractValue1=$1 and effValue1 = $2 and " +
View Full Code Here

         * create some data for us to delete.
         */
        createData(database, odmg);

        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();

        OQLQuery query = odmg.newOQLQuery();
        ManageableCollection all = null;
        java.util.Iterator it = null;
        int i = 0;
        query.create("select effectiveness from " + org.apache.ojb.broker.Effectiveness.class.getName());

        /**
         * try doing this as part of one transaction, ODMG should figure out
         * which order to delete in.
         */
        all = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        it = all.ojbIterator();
        Effectiveness eff = null;
        Version ver = null;
        Contract contract = null;
        while (it.hasNext())
        {
            eff = (Effectiveness) it.next();
            ver = eff.getVersion();
            contract = ver.getContract();

            tx.begin();
            database.deletePersistent(eff);
            tx.commit();

            tx.begin();
            database.deletePersistent(ver);
            tx.commit();

            tx.begin();
            database.deletePersistent(contract);
            tx.commit();
            // keep the count
            i++;
        }
        if (i < COUNT)
            fail("Should have found at least " + COUNT + " items to delete, only found " + i);
View Full Code Here

         * create some data for us to delete.
         */
        createData(database, odmg);

        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();

        OQLQuery query = odmg.newOQLQuery();
        ManageableCollection all = null;
        java.util.Iterator it = null;
        int i = 0;
        query.create("select effectiveness from " + org.apache.ojb.broker.Effectiveness.class.getName());

        /**
         * try doing this as part of one transaction, ODMG should figure out
         * which order to delete in.
         */
        all = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        it = all.ojbIterator();
        Effectiveness eff = null;
        Version ver = null;
        Contract contract = null;
        /**
         * should mark all these objects for delete then on commit
         * ODMG should make sure they get deleted in proper order
         */
        tx.begin();
        while (it.hasNext())
        {
            eff = (Effectiveness) it.next();
            ver = eff.getVersion();
            contract = ver.getContract();
            /**
             * should mean that version and effectivedate are cascade deleted.
             */
            database.deletePersistent(contract);
            i++;
        }
        /**
         * commit all changes.
         */
        tx.commit();
        if (i < COUNT)
            fail("Should have found at least " + COUNT + " effectiveness to delete, only found " + i);
        /**
         * run query again, should get 0 results.
         */
 
View Full Code Here

     */
    public void testQuery() throws Exception
    {
        createData(database, odmg);
        // 3. Get a list of some articles
        Transaction tx = odmg.newTransaction();
        tx.begin();

        OQLQuery query = odmg.newOQLQuery();
        String sql = "select effectiveness from " + Effectiveness.class.getName();
        query.create(sql);

        ManageableCollection allEffectiveness = (ManageableCollection) query.execute();

        // Iterator over the restricted articles objects
        java.util.Iterator it = allEffectiveness.ojbIterator();
        int i = 0;
        while (it.hasNext())
        {
            Effectiveness value = (Effectiveness) it.next();
            /**
             * check pk value of related contract item.
             */
            if (value.getVersion().getContract().getPk() == null)
                fail("Contract PK should not be null");
            i++;
        }
        if (i < COUNT)
            fail("Should have found at least " + COUNT + " items, only found: " + i);
        tx.commit();
    }
View Full Code Here

     * test changing a versions fk reference to it's contract.
     * The old bug in ODMG wouldn't trigger an update if an object reference changed.
     */
    public void testContractReassignment() throws Exception
    {
        Transaction tx = odmg.newTransaction();
        Contract contract = new Contract();
        contract.setPk("contract1");
        contract.setContractValue1("contract1value1");
        contract.setContractValue2(1);
        contract.setContractValue3("contract1value3");
        contract.setContractValue4(new Timestamp(System.currentTimeMillis()));

        Version version = new Version();
        version.setPk("version1");
        version.setVersionValue1("version1value1");
        version.setVersionValue2(1);
        version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
        version.setContract(contract);

        Effectiveness eff = new Effectiveness();
        eff.setPk("eff1");
        eff.setEffValue1("eff1value1");
        eff.setEffValue2(1);
        eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
        eff.setVersion(version);

        Contract contract2 = new Contract();
        contract2.setPk("contract2");
        contract2.setContractValue1("contract2value1");
        contract2.setContractValue2(1);
        contract2.setContractValue3("contractvalue3");
        contract2.setContractValue4(new Timestamp(System.currentTimeMillis()));

        Version version2 = new Version();
        version2.setPk("version2");
        version2.setVersionValue1("version2value1");
        version2.setVersionValue2(1);
        version2.setVersionValue3(new Timestamp(System.currentTimeMillis()));
        version2.setContract(contract2);

        Effectiveness eff2 = new Effectiveness();
        eff2.setPk("eff2");
        eff2.setEffValue1("eff2value1");
        eff2.setEffValue2(1);
        eff2.setEffValue3(new Timestamp(System.currentTimeMillis()));
        eff2.setVersion(version2);

        /**
         * make them persistent
         */
        tx.begin();
        database.makePersistent(eff2);
        database.makePersistent(eff);
        tx.commit();

        /**
         * do the reassignment
         */
        tx.begin();
        tx.lock(version, Transaction.WRITE);
        tx.lock(version2, Transaction.WRITE);
        version.setContract(contract2);
        version2.setContract(contract);
        tx.commit();

        /**
         * query and check values
         */
        OQLQuery query = odmg.newOQLQuery();
        String sql = "select version from " + org.apache.ojb.broker.Version.class.getName() + " where pk=$1";
        query.create(sql);
        query.bind("version1");
        tx.begin();
        ManageableCollection results = (ManageableCollection) query.execute();
        // Iterator over the restricted articles objects
        java.util.Iterator it = results.ojbIterator();
        Version ver1 = null;
        while (it.hasNext())
        {
            ver1 = (Version) it.next();
            if (!ver1.getContract().getPk().equals(contract2.getPk()))
            {
                fail(ver1.getPk() + " should have pointed to contract2 instead it pointed to: " + ver1.getContract().getPk());
            }
        }
        tx.commit();

        OQLQuery query2 = odmg.newOQLQuery();
        String sql2 = "select version from " + org.apache.ojb.broker.Version.class.getName() + " where pk=$1";
        query2.create(sql2);
        query2.bind("version2");
        tx.begin();
        results = (ManageableCollection) query2.execute();
        // Iterator over the restricted articles objects
        java.util.Iterator it2 = results.ojbIterator();
        Version ver2 = null;
        while (it2.hasNext())
        {
            ver2 = (Version) it2.next();
            if (!ver2.getContract().getPk().equals(contract.getPk()))
            {
                fail(ver2.getPk() + " should have pointed to contract instead it pointed to: " + ver2.getContract().getPk());
            }
        }
        tx.commit();

        /**
         * clean up
         */
        tx.begin();
        database.deletePersistent(eff2);
        database.deletePersistent(eff);
        tx.commit();
        tx.begin();
        database.deletePersistent(version2);
        database.deletePersistent(version);
        tx.commit();
        tx.begin();
        database.deletePersistent(contract2);
        database.deletePersistent(contract);
        tx.commit();
    }
View Full Code Here

    /**
     * test that we can create 2 objects that have a bidirectional association in ODMG API
     */
    public void createWithUpdate() throws ODMGException
    {
        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();

        ObjectA a = new ObjectA();
        a.setPk("A" + currentTime);
        ObjectB b = new ObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        database.makePersistent(a);
        database.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 " + ObjectA.class.getName() + " where pk=$1");
        query.bind("A"+currentTime);
        Collection all = (Collection) query.execute();
        Iterator it = all.iterator();
        while (it.hasNext())
        {
            i++;
            a = (ObjectA) 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 " + ObjectB.class.getName() + " where pk=$1");
        query.bind("B"+currentTime);
        all = (Collection) query.execute();
        it = all.iterator();
        while (it.hasNext())
        {
            i++;
            b = (ObjectB) 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);
        tx.commit();
    }
View Full Code Here

    {
        if(log.isDebugEnabled()) log.debug("storeObjects");

        /* One possibility of storing objects is to use the current transaction
         associated with the container */
        Transaction tx = odmg.currentTransaction();
        for (Iterator iterator = objects.iterator(); iterator.hasNext();)
        {
            tx.lock(iterator.next(), Transaction.WRITE);
        }
        return objects;
    }
View Full Code Here

     * this test doesn't work as OJB won't do the insert then execute the update.
     * @throws ODMGException
     */
    public void testCreateWithoutUpdate() throws ODMGException
    {
        Transaction tx = odmg.newTransaction();
        long currentTime = System.currentTimeMillis();
        ObjectA a = new ObjectA();
        a.setPk("A" + currentTime);
        ObjectB b = new ObjectB();
        b.setPk("B" + currentTime);

        tx.begin();
        b.setRelatedA(a);
        a.setRelatedB(b);
        // we use a FK from ObjectB to ObjectA, thus we
        // make persistent B
        database.makePersistent(b);
        // not needed
        //database.makePersistent(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 " + ObjectA.class.getName() + " where pk=$1");
        query.bind("A"+currentTime);
         Collection all = (Collection) query.execute();
View Full Code Here

        createWithUpdate();

        OQLQuery query = odmg.newOQLQuery();
        int i = 0;
        query.create("select allA from " + ObjectA.class.getName());
        Transaction tx = odmg.newTransaction();
        tx.begin();
        Collection all = (Collection) query.execute();
        Iterator it = all.iterator();
        ObjectA temp = null;
        while (it.hasNext())
        {
            temp = (ObjectA) it.next();
            if (temp.getRelatedB() == null)
                fail("should have relatedB");
            i++;
        }
        tx.commit();
        if (i == 0)
            fail("Should have found at least 1  bidirectionalAssociationObjectA object");
    }
View Full Code Here

TOP

Related Classes of org.odmg.Transaction

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.