Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.Contract


         * 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");
View Full Code Here


         * 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");
View Full Code Here

        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();
View Full Code Here

        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();
View Full Code Here

     * 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();
View Full Code Here

    }

    public void testInsertAfterDelete() throws Exception
    {
        final String contractPk = "The Contract_" + System.currentTimeMillis();
        Contract obj1 = new Contract();
        Contract obj2 = new Contract();

        obj1.setPk(contractPk);
        obj1.setContractValue2(1);

        obj2.setPk(contractPk);
        obj2.setContractValue2(2);

        // 1. Insert object
        Transaction tx = odmg.newTransaction();
        tx.begin();
        /*
        arminw:
        seems to have problems when within a tx a object
        was stored/deleted.
        Without obj1 test pass
        TODO: fix this
        */
        database.makePersistent(obj1);
        database.deletePersistent(obj2);
        database.makePersistent(obj1);
        /*
         thma: I checked this, and don't see a problem here.
        obj1 and obj2 have the same Identity. Thus the
        calls database.makePersistent(obj1); and database.makePersistent(obj2);
        will only register one instance to the transaction.
        The second call does not add a second instance, but just marks the
        existing instance as dirty a second time.
        So it's no wonder why after deletePersistent(obj1); no contract is found.
        Works as designed.
        The Lesson to learn: never let business objects have the same primary key values!
         * */
        tx.commit();
        Collection result = getContract(contractPk, odmg);
        assertEquals("We should found exact one contract", 1, result.size());
        Contract newObj = (Contract) result.iterator().next();
        assertNotNull("Object not found", newObj);
        assertEquals(1, newObj.getContractValue2());

        // 2. Delete, then insert object with the same identity
        tx.begin();
        database.deletePersistent(newObj);
        database.makePersistent(obj2);
        tx.commit();
        assertEquals(2, obj2.getContractValue2());

        result = getContract(contractPk, odmg);
        assertEquals("We should found exact one contract", 1, result.size());
        newObj = (Contract) result.iterator().next();
        assertNotNull("Object not found", newObj);
        assertEquals(2, newObj.getContractValue2());

        // 3. Delete
        tx.begin();
        database.deletePersistent(obj1);
        tx.commit();
View Full Code Here

TOP

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

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.