Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.Query.toSql()


        FromItem fromItem1 = q.from(table, "t1").getFromClause().getItem(0);
        FromItem fromItem2 = q.from(table, "t2").getFromClause().getItem(1);
        q.select(table.getColumnByName("foo"), fromItem1);
        q.select(table.getColumnByName("foo"), fromItem2);
        q.where(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, "2");
        assertEquals("SELECT t1.foo, t2.foo FROM sch.tab t1, sch.tab t2 WHERE t1.foo = '2'", q.toSql());

        DataSet ds = dc.executeQuery(q);
        SelectItem[] selectItems = ds.getSelectItems();
        assertEquals(2, selectItems.length);
        assertEquals("t1.foo", selectItems[0].toSql());
View Full Code Here


    public void testQueryInLowerCase() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc,
                "select a.foo as f from sch.tbl a inner join sch.tbl b on a.foo=b.foo order by a.foo asc");
        assertEquals("SELECT a.foo AS f FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo ORDER BY a.foo ASC",
                q.toSql());
    }

    public void testSelectEverythingFromTable() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
        assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
View Full Code Here

                q.toSql());
    }

    public void testSelectEverythingFromTable() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
        assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
    }

    public void testSelectEverythingFromJoin() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals(
View Full Code Here

    public void testSelectEverythingFromJoin() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals(
                "SELECT a.foo, a.bar, a.baz, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());

        q = MetaModelHelper.parseQuery(dc, "SELECT a.foo, b.* FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals("SELECT a.foo, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());
    }
View Full Code Here

                "SELECT a.foo, a.bar, a.baz, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());

        q = MetaModelHelper.parseQuery(dc, "SELECT a.foo, b.* FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals("SELECT a.foo, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());
    }

    public void testSelectColumnWithDotInName() throws Exception {
        MutableColumn col = (MutableColumn) dc.getTableByQualifiedLabel("tbl").getColumn(0);
        col.setName("fo.o");
View Full Code Here

    public void testSelectColumnWithDotInName() throws Exception {
        MutableColumn col = (MutableColumn) dc.getTableByQualifiedLabel("tbl").getColumn(0);
        col.setName("fo.o");

        Query q = MetaModelHelper.parseQuery(dc, "SELECT fo.o AS f FROM sch.tbl");
        assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
    }

    public void testSelectAlias() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo AS f FROM sch.tbl");
        assertEquals("SELECT tbl.foo AS f FROM sch.tbl", q.toSql());
View Full Code Here

        assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
    }

    public void testSelectAlias() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo AS f FROM sch.tbl");
        assertEquals("SELECT tbl.foo AS f FROM sch.tbl", q.toSql());

        q = MetaModelHelper.parseQuery(dc, "SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'");
        assertEquals("SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'", q.toSql());
    }
View Full Code Here

            table1.getColumnByName("bar"),
            table2.getColumnByName("baz")).toQuery();
    assertEquals(
        "SELECT table.foo, table.foo, table.bar, table.baz "
            + "FROM schema.table LEFT JOIN schema.table ON table.foo = table.foo",
        q.toSql());

    DataSet ds = composite.executeQuery(q);
    assertTrue(ds.next());
    assertEquals("Row[values=[1, 1, hello, world]]", ds.getRow().toString());
    assertTrue(ds.next());
View Full Code Here

        Column nameColumn = wikiTable.getColumnByName("name");

        Query q = dc.query().from(wikiTable).select(nameColumn).where(nameColumn).isEquals("m'jello").toQuery();
        assertEquals(16384, dc.getFetchSizeCalculator().getFetchSize(q));

        assertEquals("SELECT wiki.name FROM wiki WHERE wiki.name = 'm'jello'", q.toSql());
        assertEquals("SELECT wiki.name FROM wiki WHERE wiki.name = 'm''jello'", dc.getQueryRewriter().rewriteQuery(q));

        DataSet ds = dc.executeQuery(q);
        assertFalse(ds.next());
    }
View Full Code Here

        Row row = MetaModelHelper.executeSingleRowQuery(dc, q);
        assertEquals(3, ((Number) row.getValue(0)).intValue());

        q = dc.query().from(table).selectCount().where("name").isEquals("m'jello").toQuery();

        assertEquals("SELECT COUNT(*) FROM PUBLIC.\"TESTTABLE\" WHERE \"TESTTABLE\".\"NAME\" = 'm'jello'", q.toSql());
        assertEquals("SELECT COUNT(*) FROM PUBLIC.\"TESTTABLE\" WHERE \"TESTTABLE\".\"NAME\" = 'm''jello'", dc.getQueryRewriter()
                .rewriteQuery(q));

        row = MetaModelHelper.executeSingleRowQuery(dc, q);
        assertEquals(1, ((Number) row.getValue(0)).intValue());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.