Package org.apache.ojb.broker

Examples of org.apache.ojb.broker.Contract


    }

    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);
        try
        {
            // 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.makePersistent(obj2);
            //database.deletePersistent(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());
            obj2 = (Contract) result.iterator().next();
            if (obj2 == null)
            {
                fail("Contract not found");
            }
            else if (obj2.getContractValue2() != 2)
            {
                fail("Wrong contract found");
            }

            // 2. Delete, then insert object with the same identity
View Full Code Here


    {
        for (int i = 0; i < COUNT; i++)
        {
            Transaction tx = _kit.getTransaction(_conn);
            tx.begin();
            Contract contract = new Contract();
            contract.setPk("C" + TIME);
            contract.setContractValue1("contractvalue1");
            contract.setContractValue2(1);
            contract.setContractValue3("contractvalue3");
            contract.setContractValue4(new Timestamp(TIME));
            _conn.makePersistent(contract);
            tx.commit();
            tx = _kit.getTransaction(_conn);
            tx.begin();
            Version version = new Version();
View Full Code Here

//        Implementation odmg = OJB.getInstance();
        Transaction tx = odmg.newTransaction();
        for (int i = 0; i < COUNT; i++)
        {
            tx.begin();
            Contract contract = new Contract();
            contract.setPk("C" + i + System.currentTimeMillis());
            contract.setContractValue1("contractvalue1");
            contract.setContractValue2(1);
            contract.setContractValue3("contractvalue3");
            contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
            db.makePersistent(contract);

            Version version = new Version();
            version.setPk("V" + i + 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);

        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

    {
        for (int i = 0; i < COUNT; i++)
        {
            Transaction tx = _kit.getTransaction(_conn);
            tx.begin();
            Contract contract = new Contract();
            contract.setPk("C" + TIME);
            contract.setContractValue1("contractvalue1");
            contract.setContractValue2(1);
            contract.setContractValue3("contractvalue3");
            contract.setContractValue4(new Timestamp(TIME));
            _conn.makePersistent(contract);
            tx.commit();
            tx = _kit.getTransaction(_conn);
            tx.begin();
            Version version = new Version();
View Full Code Here

//        Implementation odmg = OJB.getInstance();
        Transaction tx = odmg.newTransaction();
        for (int i = 0; i < COUNT; i++)
        {
            tx.begin();
            Contract contract = new Contract();
            contract.setPk("C" + i + System.currentTimeMillis());
            contract.setContractValue1("contractvalue1");
            contract.setContractValue2(1);
            contract.setContractValue3("contractvalue3");
            contract.setContractValue4(new Timestamp(System.currentTimeMillis()));
            db.makePersistent(contract);

            Version version = new Version();
            version.setPk("V" + i + System.currentTimeMillis());
            version.setVersionValue1("versionvalue1");
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.