Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.Database


    /**
     * Test method.
     * @throws Exception For any exception thrown.
     */
    public void testNamedQuery() throws Exception {
        Database db = _category.getDatabase();
       
        // load all EntityOne instances using a named query
        db.begin();
       
        OQLQuery query = db.getNamedQuery(SELECT_ALL_ENTITY_ONE);       
        QueryResults results = query.execute();
        int i = 0;
        while (results.hasMore()) {
            NQEntity entity = (NQEntity) results.next();
            assertNotNull(entity);
            i++;
        }
        assertTrue(i >= ENTITY_COUNT);
        db.commit();
       
        // load EntityOne with Id=1 from persistent store
        db.begin();
       
        query = db.getNamedQuery(SELECT_ENTITY_ONE_BY_ID);
        query.bind(new Integer(0));
        results = query.execute();
       
        NQEntity entity = (NQEntity) results.next();

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


    /**
     * Test method.
     * @throws Exception For any exception thrown.
     */
    public void testNonExistentNamedQuery() throws Exception {
        Database db = _category.getDatabase();
       
        // try to get non-existent named query
        db.begin();
        OQLQuery query = null;           
        try {
            query = db.getNamedQuery(SELECT_KNIGHTS_WHO_SAY_NI);
            fail("Database.getNamedQuery() should have thrown a QueryException");
        } catch (QueryException e) {
            //  great, this is what we expect
            //  check if it's the correct one
            if (!e.getMessage().startsWith("Cannot find a named query")) {
                throw e;
            }
        } finally {
            if (query != null) {
                query.close();
            }
        }
       
        db.commit();
        db.close();
    }
View Full Code Here

    /**
     * Test method.
     * @throws Exception For any exception thrown.
     */
    public void testBadSyntaxNamedQuery() throws Exception {
        Database db = _category.getDatabase();
       
        // try to load non-existent named query
        db.begin();
        try {
            OQLQuery query = db.getNamedQuery(QUERY_WITH_BAD_SYNTAX);           
            query.close(); //this shouldn't happen
        } catch (QueryException e) {
            // great, this is what we expect
            // check if it's the correct one
            if (!e.getMessage().startsWith("Could not find class")) {
                throw e;
            }
        }
        db.commit();
        db.close();
    }
View Full Code Here

    /**
     * Test method.
     * @throws Exception For any exception thrown.
     */
    public void testNamedQueryIgnoreHint() throws Exception {
        Database db = _category.getDatabase();       
        // load all EntityOne instances using a named query
        // and then use same query but with hints
        db.begin();
       
        OQLQuery query = db.getNamedQuery(SELECT_ALL_ENTITY_ONE);       
        QueryResults results = query.execute();
        int countFirst = 0;
        while (results.hasMore()) {
            NQEntity entity = (NQEntity) results.next();
            assertNotNull(entity);
            countFirst++;
        }
        query = db.getNamedQuery(SELECT_ALL_ENTITY_HINT);       
        results = query.execute();
        int countSecond = 0;
        while (results.hasMore()) {
            NQEntity entity = (NQEntity) results.next();
            assertNotNull(entity);
            countSecond++;
        }
        assertEquals(countFirst, countSecond);
       
        db.commit();    
        db.close();
    }
View Full Code Here

        db.commit();    
        db.close();
    }
   
    public void tearDown() throws Exception {
        Database db = _category.getDatabase();
        db.begin();
        db.getJdbcConnection().prepareStatement("delete from tc3x_nq_entity").executeUpdate();
        db.commit();
        _db.close();
    }
View Full Code Here

     *
     * @throws Exception
     *             if something goes wrong
     */
    public void testLoadFlat() throws Exception {
        Database db = _jdo.getDatabase();
        assertNotNull(db);
        db.begin();

        Flat flat = (Flat) db.load(Flat.class, new Long(1));

        assertNotNull(flat);
        assertEquals(1, flat.getId());

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

     *
     * @throws Exception
     *             if something goes wrong
     */
    public void testLoadHouseOneFlat() throws Exception {
        Database db = _jdo.getDatabase();
        assertNotNull(db);
        db.begin();

        House house = (House) db.load(House.class, new Long(100));
        assertNotNull(house);

        assertEquals(100, house.getId());

        Flat[] flats = house.getFlats();
        assertNotNull(flats);
        assertEquals(1, flats.length);

        Flat flat = house.getFlats()[0];
        assertEquals(1, flat.getId());

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

     *
     * @throws Exception
     *             if something goes wrong
     */
    public void testLoadHouseFlats() throws Exception {
        Database db = _jdo.getDatabase();
        assertNotNull(db);
        db.begin();

        House house = (House) db.load(House.class, new Long(101));
        assertNotNull(house);

        assertEquals(101, house.getId());

        Flat[] flats = house.getFlats();
        assertNotNull(flats);
        assertEquals(2, flats.length);

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

     *
     * @throws Exception
     *             if db setup fails.
     */
    public void testSelectQuery() throws Exception {
        Database db;
        db = _jdo.getDatabase();
        assertNotNull(db);
        db.begin();
        OQLQuery query = db.getOQLQuery("SELECT h FROM "
                + House.class.getName() + " h WHERE h.flats.id = $1");
        query.bind(2);
        QueryResults result = query.execute();
       
        House e = (House) result.next();
        assertEquals(101, e.getId());
        assertEquals(2, e.getFlats().length);
       
        result.close();
        db.commit();
        db.close();
    }
View Full Code Here

    public void testCreateParent () throws Exception {
        Lazy1to1Parent parent = null;
        Lazy1to1Child child = null;
       
        Database db = _category.getDatabase();
       
        db.begin();
        child = (Lazy1to1Child) db.load(Lazy1to1Child.class, new Integer (1));
        parent = new Lazy1to1Parent();
        parent.setId(new Integer(20000));
        parent.setDescription ("parent 20000");
        parent.setChild(child);
        db.create(parent);
        db.commit();
       
        db.begin();
        parent = (Lazy1to1Parent ) db.load(Lazy1to1Parent.class, new Integer (20000));
        child = parent.getChild();
        assertNotNull(child);
        assertEquals(1, child.getId().intValue());
        db.rollback();
       
        db.begin();
        parent = (Lazy1to1Parent) db.load(Lazy1to1Parent.class, new Integer (20000));
        db.remove(parent);
        db.commit();
       
        db.close();
    }
View Full Code Here

TOP

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

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.