Package org.apache.torque.criteria

Examples of org.apache.torque.criteria.Criteria


     * tests whether AsColumns produce valid SQL code
     * @throws Exception if the test fails
     */
    public void testAsColumn() throws Exception
    {
        Criteria criteria = new Criteria();
        criteria.addAsColumn("ALIASNAME", AuthorPeer.NAME);
        // we need an additional column to select from,
        // to indicate the table we want use
        criteria.addSelectColumn(AuthorPeer.AUTHOR_ID);
        BasePeer.doSelect(criteria, new DoNothingMapper());
    }
View Full Code Here


        book.setTitle("Name");
        book.setAuthor(author);
        book.setIsbn("unknown");
        book.save();

        Criteria criteria = new Criteria();
        criteria.addJoin(BookPeer.TITLE, AuthorPeer.NAME);
        BookPeer.addSelectColumns(criteria);
        AuthorPeer.addSelectColumns(criteria);
        // basically a BaseBookPeer.setDbName(criteria);
        // and BasePeer.doSelect(criteria);
        CompositeMapper mapper = new CompositeMapper();
View Full Code Here

        if (defaultAdapter instanceof MssqlAdapter) {
            log.error("testLargePk(): "
                    + "MSSQL does not support inserting defined PK values");
                return;
        }
        BigintTypePeer.doDelete(new Criteria());

        long longId = 8771507845873286l;
        BigintType bigintType = new BigintType();
        bigintType.setId(longId);
        bigintType.save();

        List<BigintType> bigintTypeList = BigintTypePeer.doSelect(new Criteria());
        BigintType readBigintType = bigintTypeList.get(0);
        assertEquals(bigintType.getId(), readBigintType.getId());
        assertEquals(longId, readBigintType.getId());
    }
View Full Code Here

     * tests whether large bigint values are inserted and read correctly
     * @throws Exception if the test fails
     */
    public void testLargeValue() throws Exception
    {
        BigintTypePeer.doDelete(new Criteria());

        long longValue = 8771507845873286l;
        BigintType bigintType = new BigintType();
        bigintType.setBigintValue(longValue);
        bigintType.save();

        List<BigintType> bigintTypeList = BigintTypePeer.doSelect(new Criteria());
        BigintType readBigintType = bigintTypeList.get(0);
        assertEquals(bigintType.getId(), readBigintType.getId());
        assertEquals(longValue, readBigintType.getBigintValue());
    }
View Full Code Here

        author = new Author();
        author.setName("Name");
        author.save();

        Criteria criteria = new Criteria();
        int count = new CountHelper().count(
                criteria,
                null,
                AuthorPeer.AUTHOR_ID);

        if (count != 3) {
            fail("counted " + count + " datasets, should be 3 ");
        }

        criteria = new Criteria();
        criteria.setDistinct();
        count = new CountHelper().count(criteria, null, AuthorPeer.NAME);

        if (count != 2) {
            fail("counted " + count + " distinct datasets, should be 2 ");
        }

        criteria = new Criteria();
        criteria.where(AuthorPeer.NAME, "Name2");
        count = new CountHelper().count(criteria);

        if (count != 1) {
            fail("counted " + count + " datasets with name Name2,"
                 + " should be 1 ");
View Full Code Here

        compPkContainsFk.setId1(oIntegerPk.getId());
        compPkContainsFk.setId2("test");
        compPkContainsFk.save();

        List<CompPkContainsFk> selectedList
                = CompPkContainsFkPeer.doSelect(new Criteria());
        assertEquals(1, selectedList.size());
        CompPkContainsFk selected = selectedList.get(0);
        assertEquals(oIntegerPk.getId(), selected.getId1());
        assertEquals("test", selected.getId2());
    }
View Full Code Here

     * returns an instance of this interface
     * @throws Exception if the test fails
     */
    public void testInterface() throws Exception
    {
        Criteria criteria = new Criteria();
        criteria.where(IfcTablePeer.ID, -1, Criteria.NOT_EQUAL);
        IfcTablePeer.doDelete(criteria);

        IfcTable ifc = new IfcTable();

        assertTrue("IfcTable should be an instance of TestInterface", ifc instanceof TestInterface);

        ifc.setID(1);
        ifc.setName("John Doe");
        ifc.save();

        List<IfcTable> results = IfcTablePeer.doSelect(new Criteria());

        for (IfcTable ifcTable : results)
        {
            assertTrue("IfcTablePeer.doSelect should return"
                    + " instances of TestInterface",
                ifcTable instanceof TestInterface);
        }

        LocalIfcTable localIfc = new LocalIfcTable();

        assertTrue("LocalIfcTable should be an instance of LocalTestInterface",
                localIfc instanceof LocalTestInterface);

        List<LocalIfcTable> results2 = LocalIfcTablePeer.doSelect(new Criteria());

        for (LocalIfcTable readLocalIfcTable : results2)
        {
            assertTrue("IfcTable2Peer.doSelect should return"
                    + " instances of LocalTestInterface",
View Full Code Here

    }

    public void testInheritanceWithKeys() throws Exception
    {
        // make sure that the InheritanceTest table is empty before the test
        Criteria criteria = new Criteria();
        criteria.where(
                InheritanceTestPeer.INHERITANCE_TEST,
                (Object) null,
                Criteria.ISNOTNULL);
        InheritanceTestPeer.doDelete(criteria);
        criteria = new Criteria();
        criteria.where(
                InheritanceTestPeer.INHERITANCE_TEST,
                (Object) null,
                Criteria.ISNOTNULL);
        assertEquals(0,
                new CountHelper().count(criteria));

        // create & save test data
        InheritanceTest inheritanceTest = new InheritanceTest();
        inheritanceTest.setPayload("payload1");
        inheritanceTest.save();
        InheritanceChildB inheritanceChildB = new InheritanceChildB();
        inheritanceChildB.setPayload("payload 2");
        inheritanceChildB.save();
        InheritanceChildC inheritanceChildC = new InheritanceChildC();
        inheritanceChildC.setPayload("payload 3");
        inheritanceChildC.save();
        InheritanceChildD inheritanceChildD = new InheritanceChildD();
        inheritanceChildD.setPayload("payload 4");
        inheritanceChildD.save();

        // Check that all objects are saved into the InheritanceTest table
        criteria = new Criteria();
        criteria.where(
                InheritanceTestPeer.INHERITANCE_TEST,
                null,
                Criteria.ISNOTNULL);
        assertEquals("InheritanceTestTable should contain 4 rows",
                4,
                new CountHelper().count(criteria));
        criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                InheritanceTestPeer.INHERITANCE_TEST);

        // Check that the class of the object is retained when loading
        List<InheritanceTest> inheritanceObjects
                = InheritanceTestPeer.doSelect(criteria);
View Full Code Here

    }

    public void testInheritanceWithClassname() throws Exception
    {
        // make sure that the InheritanceTest table is empty before the test
        Criteria criteria = new Criteria();
        InheritanceClassnameTestPeer.doDelete(criteria);
        criteria = new Criteria();
        criteria.where(
                InheritanceClassnameTestPeer.INHERITANCE_TEST,
                null,
                Criteria.ISNOTNULL);
        assertEquals(0,
                new CountHelper().count(criteria));

        // create & save test data
        InheritanceClassnameTest inheritanceClassnameTest
                = new InheritanceClassnameTest();
        inheritanceClassnameTest.setPayload("0 parent");
        inheritanceClassnameTest.save();
        InheritanceClassnameTestChild1 inheritanceClassnameChild1
                = new InheritanceClassnameTestChild1();
        inheritanceClassnameChild1.setPayload("1 child");
        inheritanceClassnameChild1.save();
        InheritanceClassnameTestChild2 inheritanceClassnameChild2
                = new InheritanceClassnameTestChild2();
        inheritanceClassnameChild2.setPayload("2 child");
        inheritanceClassnameChild2.save();

        // Check that all objects are saved into the InheritanceTest table
        criteria = new Criteria();
        criteria.where(
                InheritanceClassnameTestPeer.INHERITANCE_TEST,
                null,
                Criteria.ISNOTNULL);
        assertEquals("InheritanceClassnameTest table should contain 3 rows",
                3,
                new CountHelper().count(criteria));
        criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                InheritanceClassnameTestPeer.PAYLOAD);

        // Check that the class of the object is retained when loading
        List<InheritanceClassnameTest> inheritanceObjects
                = InheritanceClassnameTestPeer.doSelect(criteria);
View Full Code Here

        cleanBookstore();
        Author author = new Author();
        author.setName("Joshua Bloch");
        author.save();

        Criteria criteria = new Criteria();
        criteria.where(AuthorPeer.AUTHOR_ID, (Object) null, Criteria.NOT_EQUAL);
        criteria.and(new ColumnImpl("name"), "Joshua Bloch", Criteria.EQUAL);
        List<Author> authors = AuthorPeer.doSelect(criteria);
        assertEquals(1, authors.size());
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.criteria.Criteria

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.