Package org.apache.metamodel.query

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


                ageColumn.toString());

        Query q = dc.query().from(table).selectCount().and(FunctionType.MAX, ageColumn).and(FunctionType.MIN, ageColumn)
                .toQuery();
        assertEquals("SELECT COUNT(*), MAX(\"TEST_TABLE\".\"AGE\"), MIN(\"TEST_TABLE\".\"AGE\") FROM PUBLIC.\"TEST_TABLE\"",
                q.toSql());

        assertEquals(1, dc.getFetchSizeCalculator().getFetchSize(q));

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


        int minAge = ((Number) row.getValue(2)).intValue();
        assertTrue("Minimum age was: " + minAge, minAge < 10 && minAge >= 0);

        q = dc.query().from(table).as("t").select(ageColumn).selectCount().where(ageColumn).greaterThan(50).groupBy(ageColumn)
                .toQuery();
        assertEquals("SELECT t.\"AGE\", COUNT(*) FROM PUBLIC.\"TEST_TABLE\" t WHERE t.\"AGE\" > 50 GROUP BY t.\"AGE\"", q.toSql());

        ds = dc.executeQuery(q);
        List<Object[]> objectArrays = ds.toObjectArrays();
        assertTrue(objectArrays.size() <= 50);
        assertTrue(objectArrays.size() > 40);
View Full Code Here

        query.where(new SelectItem(table.getColumnByName("bar"), query.getFromClause().getItem(0)), OperatorType.EQUALS_TO,
                "hello");

        assertEquals(
                "SELECT a.\"FOO\", b.\"FOO\" FROM PUBLIC.\"TEST_TABLE\" a, PUBLIC.\"TEST_TABLE\" b WHERE a.\"BAR\" = 'hello'",
                query.toSql());

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

        assertEquals(5, dc.getFetchSizeCalculator().getFetchSize(q));

        assertEquals(
                "SELECT \"CUSTOMERS\".\"CUSTOMERNUMBER\" FROM APP.\"CUSTOMERS\" WHERE \"CUSTOMERS\".\"ADDRESSLINE2\" IS NOT NULL",
                q.toSql());

        DataSet dataSet = dc.executeQuery(q);
        assertEquals("[\"CUSTOMERS\".\"CUSTOMERNUMBER\"]", Arrays.toString(dataSet.getSelectItems()));
        assertTrue(dataSet.next());
        assertEquals("Row[values=[114]]", dataSet.getRow().toString());
View Full Code Here

        File file = new File("src/test/resources/csv_people.csv");
        QueryPostprocessDataContext dc = new CsvDataContext(file, new CsvConfiguration(1, true, true));
        Table table = dc.getDefaultSchema().getTableByName("csv_people.csv");

        Query q = dc.query().from(table).as("t").select("name").and("age").where("age").in("18", "20").toQuery();
        assertEquals("SELECT t.name, t.age FROM resources.csv_people.csv t WHERE t.age IN ('18' , '20')", q.toSql());

        DataSet ds = dc.executeQuery(q);
        assertTrue(ds.next());
        assertEquals("Row[values=[mike, 18]]", ds.getRow().toString());
        assertTrue(ds.next());
View Full Code Here

        dc = Converters.addTypeConverters(dc, converters);

        Table table = dc.getDefaultSchema().getTables()[0];
        MutableColumn col = (MutableColumn) table.getColumns()[0];
        Query q = dc.query().from(table).select(col).toQuery();
        assertEquals("SELECT csv_only_number_one.csv.number FROM resources.csv_only_number_one.csv", q.toSql());

        DataSet ds = dc.executeQuery(q);
        while (ds.next()) {
            assertEquals(true, ds.getRow().getValue(0));
        }
View Full Code Here

        String[] columnNames = table.getColumnNames();
        assertEquals("[A, B, C, D]", Arrays.toString(columnNames));

        Query q = dc.query().from(table).select(table.getColumnByName("A")).toQuery();
        assertEquals("SELECT xls_people.A FROM xls_people.xls.xls_people", q.toSql());

        DataSet dataSet = dc.executeQuery(q);
        assertTrue(dataSet.next());
        assertEquals("id", dataSet.getRow().getValue(0));
        for (int i = 1; i <= 9; i++) {
View Full Code Here

        String[] columnNames = table.getColumnNames();
        assertEquals("[1, mike, male, 18]", Arrays.toString(columnNames));

        Query q = dc.query().from(table).select(table.getColumnByName("1")).toQuery();
        assertEquals("SELECT xls_people.1 FROM xls_people.xls.xls_people", q.toSql());

        DataSet dataSet = dc.executeQuery(q);
        assertTrue(dataSet.next());
        assertEquals("2", dataSet.getRow().getValue(0));
        for (int i = 3; i <= 9; i++) {
View Full Code Here

        dc = Converters.addTypeConverters(dc, converters);

        Table table = dc.getDefaultSchema().getTables()[0];
        MutableColumn col = (MutableColumn) table.getColumns()[0];
        Query q = dc.query().from(table).select(col).toQuery();
        assertEquals("SELECT csv_only_number_one.csv.number FROM resources.csv_only_number_one.csv", q.toSql());

        DataSet ds = dc.executeQuery(q);
        while (ds.next()) {
            assertEquals(true, ds.getRow().getValue(0));
        }
View Full Code Here

        MockDataContext dc = new MockDataContext("sch", "tab", "1");
        Table table = dc.getDefaultSchema().getTables()[0];
        Column[] columns = table.getColumns();

        Query query = dc.query().from(table).select(FunctionType.MAX, columns[0]).and(columns[1]).toQuery();
        assertEquals("SELECT MAX(tab.foo), tab.bar FROM sch.tab", query.toSql());

        DataSet ds = dc.executeQuery(query);
        assertTrue(ds.next());
        assertEquals("Row[values=[4, hello]]", ds.getRow().toString());
        assertTrue(ds.next());
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.