Package org.odmg

Examples of org.odmg.Transaction


    /**
     *
     */
    public void _testFunctions() throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select anArticle from " +
                Article.class.getName() +
                " where upper(articleName) like \"A%\" ");

        List results = (List) query.execute();
        tx.commit();
        assertTrue(results.size() > 0);
    }
View Full Code Here


    /**
     * ReportQuery returning rows with summed stock and price per article group
     */
    public void testReportQueryGroupBy() throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select p.groupName, p.allArticlesInGroup.stock, p.allArticlesInGroup.price" +
               " from " + ProductGroup.class.getName() +
               " group by groupName, allArticlesInGroup.stock, allArticlesInGroup.price");

//        query.create("select p.groupName, sum(p.allArticlesInGroup.stock), sum(p.allArticlesInGroup.price)" +
//               " from " + ProductGroup.class.getName() +
//               "by groupName, allArticlesInGroup.stock, allArticlesInGroup.price");

        List results = (List) query.execute();
        tx.commit();
        assertTrue(results.size() > 0);
    }
View Full Code Here

    {
        deleteData(Person.class);
        createPersons();

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

        OQLQuery query = odmg.newOQLQuery();
        String sql = "select allPersons from " + Person.class.getName() + " where id != $1 and id > $2";
        query.create(sql);
        query.bind(new Integer(5));
        query.bind(new Integer(id_filter));

        Collection allPersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        Iterator it = allPersons.iterator();
        while (it.hasNext())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==5)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 5");
        }
        tx.commit();

        // now we try to reuse OQLQuery
        tx.begin();

        query.bind(new Integer(8));
        query.bind(new Integer(id_filter));
        allPersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        it = allPersons.iterator();
        while (it.hasNext())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==8)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 8");
        }

        // reuse OQLQuery within same tx
        query.bind(new Integer(9));
        query.bind(new Integer(id_filter));
        allPersons = (Collection) query.execute();
        // Iterator over the restricted articles objects
        it = allPersons.iterator();
        while (it.hasNext())
        {
            /**
             * just make sure it's a string.
             */
            Object result = it.next();
            Person value = (Person) result;
            if (value.getId() <= id_filter || value.getId()==9)
                fail("oql didn't filter, got id (" + value.getId() + " where it should have been over "
                        + id_filter + " and not 9");
        }
        tx.commit();
    }
View Full Code Here

     *
     * test may fail if db does not support sub queries
     */
    public void _testSubQuery1() throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select anArticle from " +
                Article.class.getName() +
                " where " +
                " price >= (select avg(price) from " +
                Article.class.getName() +
                " where articleName like \"A%\") ");

        List results = (List) query.execute();
        tx.commit();
        assertTrue(results.size() > 0);
    }
View Full Code Here

    {
        /**
         * 1. create the article.
         */
        int id = groupID;
        Transaction tx = odmg.newTransaction();
        tx.begin();
        ProductGroup group = new ProductGroup();
        tx.lock(group, Transaction.WRITE);
        group.setId(id);
        group.setGroupName("id" + id);
        for (int i = 0; i < COUNT; i++)
        {
            Article article = createArticle(i);
            group.add(article);
        }
        tx.commit();
        /**
         * 2. query on the article to make sure it is everything we set it up to be.
         */
        OQLQuery query = odmg.newOQLQuery();
        query.create("select productGroup from " + ProductGroup.class.getName() + " where groupName=$1");
View Full Code Here

     * @throws Exception
     */
    public void brokenTestUpdateWithProxy()
            throws Exception
    {
        Transaction tx = odmg.newTransaction();
        tx.begin();
        /**
         * 1. get all articles from groups and add a new article.
         */
        OQLQuery query = odmg.newOQLQuery();
        query.create("select productGroup from " + ProductGroup.class.getName());
        Collection results = (Collection) query.execute();
        Iterator it = results.iterator();
        InterfaceProductGroup temp = null;
        /**
         * to each productgroup add an article with a pre-determined name.
         */

        int i = 2300;
        while (it.hasNext())
        {
            Article article = createArticle(i++);
            article.setArticleName("OneToManyUpdateTest");
            temp = (InterfaceProductGroup) it.next();
            tx.lock(temp, Transaction.WRITE);
            temp.add(article);
            article.setProductGroup(temp);
        }
        tx.commit(); // thma: during this commit no article is persisted! works as designed!

        /**
         * 2. requery and find the articles we added.
         */
        query = odmg.newOQLQuery();
View Full Code Here

        myZoo.addAnimal(elephant);
        myZoo.addAnimal(cat);

        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();
            database.makePersistent(myZoo);
            tx.commit();

            int id = myZoo.getZooId();

            tx = odmg.newTransaction();
            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select zoos from " + ODMGZoo.class.getName() +
                    " where zooId=$1");
            query.bind(new Integer(id));
            List zoos = (List) query.execute();
            assertEquals(1, zoos.size());
            ODMGZoo zoo = (ODMGZoo) zoos.get(0);
            tx.commit();
            assertEquals(3, zoo.getAnimals().size());


        }
        catch (ODMGException e)
View Full Code Here

     */
    public void testFKAssignForProxy()
    {
        try
        {
            Transaction tx = odmg.newTransaction();
            tx.begin();

            //create a TestClassBProxy and persist it
            //so that when loading it again we will
            //get a dynamic proxy object
            TestClassBProxy b = new TestClassBProxy();
            new Identity(b,((HasBroker)tx).getBroker());


            tx.lock(b, Transaction.WRITE);
            tx.commit();
            String bOid = b.getOid();

            //reload the object created in the previous step
            tx = odmg.newTransaction();
            tx.begin();
            OQLQuery query = odmg.newOQLQuery();
            query.create("select bproxies from " + TestClassBProxy.class.getName() +
            " where oid = $1");
            query.bind(bOid);
            List bList = (List) query.execute();
            assertEquals(1, bList.size());

            TestClassBProxyI bI = (TestClassBProxyI) bList.get(0);

            //bI should now be a dynamic proxy
            assertTrue(bI instanceof Proxy);

            TestClassAWithBProxy a = new TestClassAWithBProxy();
            a.setBProxy(bI);
            tx.lock(a, Transaction.WRITE);
            tx.commit();

            //on commit the foreign key in "a" should have been set to
            //bOid
            String aBOid = a.getBoid();

View Full Code Here

        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);

        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(obj_1, Transaction.WRITE);
        tx.lock(obj_2, Transaction.WRITE);
        tx.lock(obj_3, Transaction.WRITE);
        tx.commit();

        Criteria crit = new Criteria();
        crit.addEqualTo("name", name);
        QueryByCriteria query = QueryFactory.newQuery(MainObject.class, crit);
        int result = broker.getCount(query);
View Full Code Here

    private void createData(Database db, Implementation odmg)
            throws Exception
    {
//        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");
            version.setVersionValue2(1);
            version.setVersionValue3(new Timestamp(System.currentTimeMillis()));
            version.setContract(contract);
            db.makePersistent(version);

            Effectiveness eff = new Effectiveness();
            eff.setPk("E" + i + System.currentTimeMillis());
            eff.setEffValue1("effvalue1");
            eff.setEffValue2(1);
            eff.setEffValue3(new Timestamp(System.currentTimeMillis()));
            eff.setVersion(version);
            /**
             * will create all
             */
            db.makePersistent(eff);
            tx.commit();
        }

    }
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.