Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.OQLQuery


   
    public void testOQLQueryWithParameter () throws Exception {
        Database database = _category.getDatabase();
       
        database.begin();
        OQLQuery query = database.getOQLQuery("SELECT count(laptop.id) FROM "
                + Laptop.class.getName() + " laptop WHERE laptop.resolution = $1");
        query.bind("1024");
        QueryResults results = query.execute();
       
        if (results.hasMore()) {
            Object obj = results.next();
            Long count = null;
            if (obj instanceof Long) {
View Full Code Here


        _db =  _jdo.getDatabase();
        _db.begin();
       
        long begin = System.currentTimeMillis();
       
        OQLQuery query = _db.getOQLQuery(
                "CALL SQL select PTF_LOCKED.ID as ID "
              + "from PTF_LOCKED order by PTF_LOCKED.ID "
              + "AS " + OID.class.getName());
        QueryResults results = query.execute(Database.READONLY);
       
        long result = System.currentTimeMillis();
       
        int count = 0;
        while (results.hasMore()) {
View Full Code Here

    }

    public void testLimitWithOffset() throws PersistenceException {
        getDatabase().begin();

        OQLQuery query = getDatabase().getOQLQuery("select t from "
                + Entity.class.getName() + " t order by id limit $1 offset $2");

        query.bind(LIMIT);
        query.bind(OFFSET);

        QueryResults results = query.execute();
        assertNotNull (results);
        /*size() not available using an Oracle DB
        assertEquals (LIMIT, results.size()); */
        for (int i = 1 + OFFSET; i <= OFFSET + LIMIT; i++) {
            Entity testObject = (Entity) results.next();
View Full Code Here

        check8();
    }

    private void deleteGroups() throws PersistenceException {
        _db.begin();
        OQLQuery oqlclean = _db.getOQLQuery("SELECT object FROM "
                + ManyGroup.class.getName() + " object WHERE object.id < $1");
        oqlclean.bind(Integer.MAX_VALUE);
        QueryResults enumeration = oqlclean.execute();
        while (enumeration.hasMore()) {
            _groupA = (ManyGroup) enumeration.next();
            _stream.println("Retrieved object: " + _groupA);
            _db.remove(_groupA);
            _stream.println("Deleted object: " + _groupA);
View Full Code Here

        _db.commit();
    }

    private void deletePersons() throws PersistenceException {
        _db.begin();
        OQLQuery oqlclean = _db.getOQLQuery("SELECT object FROM "
                + ManyPerson.class.getName() + " object WHERE object.id < $1");
        oqlclean.bind(Integer.MAX_VALUE);
        QueryResults enumeration = oqlclean.execute();
        while (enumeration.hasMore()) {
            _person1 = (ManyPerson) enumeration.next();
            _stream.println("Retrieved object: " + _person1);
            _db.remove(_person1);
            _stream.println("Deleted object: " + _person1);
View Full Code Here

        _db.begin();
       
        // Determine if test object exists, if not create it.
        // If it exists, set the name to some predefined value
        // that this test will later override.
        OQLQuery oql = _db.getOQLQuery("SELECT object FROM "
                + Sample.class.getName() + " object WHERE id = $1");
        oql.bind(Sample.DEFAULT_ID);
       
        QueryResults enumeration = oql.execute();
        Sample    object;
        if (enumeration.hasMore()) {
            object = (Sample) enumeration.next();
            LOG.debug("Updating object: " + object);
        } else {
View Full Code Here

     * TestXXXExtends which use key generator XXX.
     */
    protected final void testOneKeyGen(final Class objClass, final Class extClass)
    throws Exception {

        OQLQuery oql;
        AbstractKeyGenObject object;
        AbstractKeyGenObject ext;
        QueryResults enumeration;

        // Open transaction in order to perform JDO operations
        _db.begin();

        // Create first object
        object = (AbstractKeyGenObject) objClass.newInstance();
        LOG.debug("Creating first object: " + object);
        _db.create(object);
        LOG.debug("Created first object: " + object);

        // Create second object
        ext = (AbstractKeyGenObject) extClass.newInstance();
        LOG.debug("Creating second object: " + ext);
        _db.create(ext);
        LOG.debug("Created second object: " + ext);

        _db.commit();

        _db.begin();

        // Find the first object and remove it
        //object = (TestKeyGenObject) _db.load( objClass, object.getId() );
        oql = _db.getOQLQuery();
        oql.create("SELECT object FROM " + objClass.getName()
                + " object WHERE id = $1");
        oql.bind(object.getId());
        enumeration = oql.execute();
        LOG.debug("Removing first object: " + object);
        if (enumeration.hasMore()) {
            object = (AbstractKeyGenObject) enumeration.next();
            _db.remove(object);
            LOG.debug("OK: Removed");
        } else {
            LOG.error("first object not found");
            fail("first object not found");
        }

        // Find the second object and remove it
        //ext = (TestKeyGenObject) _db.load( extClass, ext.getId() );
        oql = _db.getOQLQuery();
        oql.create("SELECT ext FROM " + extClass.getName()
                + " ext WHERE id = $1");
        oql.bind(ext.getId());
        enumeration = oql.execute();
        LOG.debug("Removing second object: " + ext);
        if (enumeration.hasMore()) {
            ext = (AbstractKeyGenObject) enumeration.next();
            _db.remove(ext);
            LOG.debug("OK: Removed");
View Full Code Here

        // query and delete all product
        database = _category.getDatabase();
        database.begin();
       
        Product pq;
        OQLQuery query = database.getOQLQuery("select p from "
                + ctf.jdo.tc8x.Product.class.getName() + " p order by p.id");
        QueryResults results = query.execute();
       
        pq = (Product) results.next();
        assertEquals(pq, new Product(1, "LCD", KindEnum.MONITOR));
        database.remove(pq);

        pq = (Product) results.next();
        assertEquals(pq, new Product(2, "Laser", KindEnum.PRINTER));
        database.remove(pq);
       
        pq = (Product) results.next();
        assertEquals(pq, new Product(3, "Desktop", KindEnum.COMPUTER));
        database.remove(pq);
       
        pq = (Product) results.next();
        assertEquals(pq, new Product(4, "Notebook", KindEnum.COMPUTER));
        database.remove(pq);
       
        assertFalse(results.hasMore());
        results.close();
        query.close();

        database.commit();
        database.close();
    }
View Full Code Here

    public void test(final Database db) throws Exception {
        db.begin();
        String s = "SELECT e FROM " + Employee.class.getName() + " e "
                 + "WHERE e.holiday > $1";
        OQLQuery qry = db.getOQLQuery(s);
        qry.bind(50.0);
        QueryResults rst = qry.execute();
        while (rst.hasMore()) {
            Employee emp = (Employee) rst.next();
            emp.setHoliday(50.0f);
        }
        rst.close();
        qry.close();
        db.commit();
    }
View Full Code Here

     */
    public void testQueryParent() throws Exception {
        Database db = _category.getDatabase();
        db.begin();
       
        OQLQuery query = db.getOQLQuery("SELECT entity FROM "
                + SelfReferentialParent.class.getName() + " entity WHERE id = $1");
        query.bind(new Integer(1));
        QueryResults results = query.execute();
       
        SelfReferentialParent entity = (SelfReferentialParent) results.next();

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

TOP

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

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.