Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.QueryResults


        }

        public void performQuery() {

            OQLQuery oql;
            QueryResults r;

            boolean firstObject = true;
            Object o;
            Vector properties = null;
            _model = new DefaultTableModel();

            try {
                _statusBar.setText("performing Query");
                // clear results
                clearTabs();

                //ResultScrollpane.getViewport().remove(
                //    ResultScrollpane.getViewport().getComponent(0));
                // create a new conec
                Database db = _jdo.getDatabase();
                db.begin();

                 /**
                    * add query to the history,
                    * maybe it's important lo loglso querys that won't work
                    * for this reason it's logged before creation
                    */
                _qhistory.addQuery(_oqlquery.getText());


                oql = db.getOQLQuery(_oqlquery.getText());


                // and execute it
                Date starttime = new Date();
                r = oql.execute(Database.READONLY);
                Date endtime = new Date();
                // write the status bar
                _statusBar.setText("Query successful, Time: "
                        + (endtime.getTime() - starttime.getTime()) + " ms");

                // get SQL statement via backdoor
                _sqlPane.setText(((OQLQueryImpl) oql).getSQL());


                while (r.hasMore()) {
                    o = r.next();
                    if (firstObject) {
                        properties = getProperties(o);
                        fillTableHeader(properties, _model);
                        firstObject = false;
                    }
View Full Code Here


        db.begin();
       
        OQLQuery query = db.getOQLQuery("SELECT entity FROM "
                + Entity.class.getName() + " entity WHERE id = $1");
        query.bind(new Integer(1));
        QueryResults results = query.execute();
       
        Entity entity = (Entity) results.next();

        assertNotNull(entity);
        assertEquals(new Integer(1), entity.getId());
       
        db.commit();
View Full Code Here

        testOQL();
    }

    public void testOQL() throws Exception {
        OQLQuery            oql;
        QueryResults        enumeration;
        UserTransaction     ut;
       
        try {  
            //obtain the UserTransaction from JNDI
            //this has been created in the JDOJ2EECategory
            ut = (UserTransaction) _context.lookup("java:/UserTransaction");
            //begin the transaction
            ut.begin();
            //get database - this should be bound to the transaction above
            _db = _category.getDatabase(_verbose);
            //execute some test OQL
            oql = _db.getOQLQuery(
                    "SELECT master FROM " + Master.class.getName() + " master");   
            enumeration = oql.execute();
            while (enumeration.hasMore()) { enumeration.next(); }
            //commit the transaction
            ut.commit();
        } catch (TransactionNotInProgressException e) {
            LOG.error (e.getClass().getName(), e);
            //if this exception occurs, the JDO
View Full Code Here

    public void runTest() throws PersistenceException, SQLException {
        _db.begin();
       
        OQLQuery query = _db.getOQLQuery(
                "select o from " + Sample.class.getName() + " o");
        QueryResults result = query.execute();
        while (result.hasMore()) { _db.remove(result.next()); }
        result.close();
        _db.commit();
       
        _synchronizables.clear();
       
        // create a default TestObject
View Full Code Here

    public void testQueryEntityOne() throws Exception {
        Database db = _category.getDatabase();
        db.begin();
        OQLQuery aquery = db.getOQLQuery(
                "SELECT c FROM " + Container.class.getName() + " c");
        QueryResults aresults = aquery.execute();
        int i = 1;
        while (aresults.hasMore()) {
            Container container = (Container) aresults.next();
            assertNotNull(container);
            assertEquals(new Integer(i), container.getId());
           
            List containerItems = container.getProp();
            assertNotNull(containerItems);
View Full Code Here

            if ((i % 4) == 0) {
                _db.begin();
                OQLQuery oql = _db.getOQLQuery("SELECT object FROM "
                        + _className + " object WHERE id = $1");
                oql.bind(i);
                QueryResults enumeration = oql.execute();
                if (enumeration.hasMore()) {
                    Race tr = (Race) enumeration.next();
                    tr.incValue1();
                    _db.commit();
                    return true;
                }
                LOG.error("Error: element not found!! missed in cache?\n");
                rollback(_db);
                throw new NoSuchElementException("No element found (a).");
            } else if ((i % 4) == 1) {
                _db.begin();
                OQLQuery oql = _db.getOQLQuery("SELECT object FROM "
                        + _className + " object WHERE id = $1");
                oql.bind(i);
                Enumeration enumeration = oql.execute();
                if (enumeration.hasMoreElements()) {
                    Race tr = (Race) enumeration.nextElement();
                    tr.incValue1();
                    _db.commit();
                    return true;
                }
                LOG.error("Error: element not found!! missed in cache?\n");
View Full Code Here

        _db.close();
    }
   
    private void delete() throws PersistenceException {
        OQLQuery oql;
        QueryResults qres;
        int cnt;

        LOG.debug("Delete everything");
        _db.begin();
        oql = _db.getOQLQuery(
                "SELECT master FROM " + MasterKeyGen.class.getName() + " master");
        qres = oql.execute();

        for (cnt = 0; qres.hasMore(); cnt++) {
            _db.remove(qres.next());
        }
        oql.close();
        LOG.debug("Deleting " + cnt + " master objects");

        oql = _db.getOQLQuery("SELECT group FROM " + Group.class.getName() + " group");
        qres = oql.execute();
        for (cnt = 0; qres.hasMore(); cnt++) {
            _db.remove(qres.nextElement());
        }
        oql.close();
        LOG.debug("Deleting " + cnt + " group objects");
        _db.commit();
    }
View Full Code Here

    private void change() throws PersistenceException {
        MasterKeyGen master;
        DetailKeyGen detail6, detail7, detail8, detail9;
        int detailId8, detailId9;
        OQLQuery oql;
        QueryResults qres;

        LOG.debug("Attempt to change details");
        _db.begin();
        master = (MasterKeyGen) _db.load(MasterKeyGen.class, new Integer(_masterId));
        if (master == null) {
            LOG.error("failed to find master with details group");
            fail("failed to find master with details group");
        }
        // remove detail with id == 5
        master.getDetails().remove(
                master.getDetails().indexOf(master.findDetail(_detailId5)));
        // remove detail with id == 6 explicitly
        detail6 = master.findDetail(_detailId6);
        master.getDetails().remove(master.getDetails().indexOf(detail6));
        // add new detail
        detail8 = new DetailKeyGen();
        master.addDetail(detail8);
        // add new detail and create it explicitely
        detail9 = new DetailKeyGen();
        master.addDetail(detail9);
        // delete, then create detail with id == 7 explicitly
        detail7 = master.findDetail(_detailId7);
        master.getDetails().remove(master.getDetails().indexOf(detail7));
        master.addDetail(detail7);
        _db.commit();
       
        detailId8 = detail8.getId();
        detailId9 = detail9.getId();

        _db.begin();
        master = (MasterKeyGen) _db.load(MasterKeyGen.class, new Integer(_masterId));
        if (master != null) {
            if (master.getDetails().size() == 0
                    || master.getDetails().contains(new DetailKeyGen(_detailId5))
                    || master.getDetails().contains(new DetailKeyGen(_detailId6))
                    || !master.getDetails().contains(new DetailKeyGen(_detailId7))
                    || !master.getDetails().contains(new DetailKeyGen(detailId8))
                    || !master.getDetails().contains(new DetailKeyGen(detailId9))) {
                LOG.error("loaded master has wrong set of details: " + master);
                fail("loaded master has wrong set of details: " + master);
            } else {
                LOG.debug("Details changed correctly: " + master);
            }
        } else {
            LOG.error("master not found");
            fail("master not found");
        }
        _db.commit();

        LOG.debug("Test OQL query");
        _db.begin();
        oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
                + " master WHERE master.details.value1=$1");
        oql.bind(Detail.DEFAULT_VALUE);
        qres = oql.execute();
        if (qres.hasMore()) {
            LOG.debug("OK: correct result of query 1 ");
        } else {
            LOG.error("incorrect result of query 1 ");
            fail("incorrect result of query 1");
        }
        oql.bind(Detail.DEFAULT_VALUE + "*");
        qres = oql.execute();
        if (qres.hasMore()) {
            LOG.error("incorrect result of query 2 ");
            fail("incorrect result of query 2");
        } else {
            LOG.debug("OK: correct result of query 2 ");
        }
        oql.close();
        oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
                + " master WHERE master.details.details2.value1=$1");
        oql.bind(DetailKeyGen2.DEFAULT_VALUE);
        qres = oql.execute();
        if (qres.hasMore()) {
            LOG.debug("OK: correct result of query 3 ");
        } else {
            LOG.error("incorrect result of query 3 ");
            fail("incorrect result of query 3");
        }
        oql.bind(DetailKeyGen2.DEFAULT_VALUE + "*");
        qres = oql.execute();
        if (qres.hasMore()) {
            LOG.error("incorrect result of query 4 ");
            fail("incorrect result of query 4");
        } else {
            LOG.debug("OK: correct result of query 4 ");
        }
        oql.close();
        oql = _db.getOQLQuery("SELECT master FROM " + MasterKeyGen.class.getName()
                + " master WHERE master.group=$1");
        oql.bind(Group.DEFAULT_ID);
        qres = oql.execute();
        if (qres.hasMore()) {
            LOG.debug("OK: correct result of query 5 ");
        } else {
            LOG.error("incorrect result of query 5 ");
            fail("incorrect result of query 5");
        }
View Full Code Here

       
        long begin = System.currentTimeMillis();
       
        OQLQuery query = db.getOQLQuery(
                "SELECT o FROM " + Service.class.getName() + " o order by o.id");
        QueryResults results = query.execute();
       
        long result = System.currentTimeMillis();
       
        int count = 0;
        while (results.hasMore()) {
            results.next();
            count++;
        }
       
        long iterate = System.currentTimeMillis();
       
View Full Code Here

       
        long begin = System.currentTimeMillis();
       
        OQLQuery query = db.getOQLQuery(
                "SELECT o FROM " + Service.class.getName() + " o order by o.id");
        QueryResults results = query.execute();
       
        long result = System.currentTimeMillis();
       
        int count = 0;
        while (results.hasMore()) {
            results.next();
            count++;
        }
       
        long iterate = System.currentTimeMillis();
       
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.QueryResults

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.