Package org.apache.metamodel.query

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


    public void testExecuteQueryInPublicSchema() throws Exception {
        DataContext dc = new JdbcDataContext(_connection);
        Query q = new Query();
        Schema schema = dc.getSchemaByName("public");
        Table productsTable = schema.getTableByName("products");
        q.from(productsTable);

        Column titleColumn = productsTable.getColumnByName("title");
        Column productPriceColumn = productsTable.getColumnByName("price");
        q.select(titleColumn, productPriceColumn);
        q.getSelectClause().getItem(0).setAlias("product-title");
View Full Code Here


        Column prodIdColumn = productsTable.getColumnByName("prod_id");
        Table orderlinesTable = schema.getTableByName("orderlines");
        Column commonProdIdColumn = orderlinesTable.getColumnByName("prod_id");
        Column quantityColumn = orderlinesTable.getColumnByName("quantity");

        q.from(orderlinesTable);
        q.where(new FilterItem(new SelectItem(prodIdColumn), OperatorType.EQUALS_TO, new SelectItem(commonProdIdColumn)));
        q.groupBy(titleColumn);
        q.getSelectClause().removeItem(q.getSelectClause().getSelectItem(productPriceColumn));
        SelectItem quantitySum = new SelectItem(FunctionType.SUM, quantityColumn).setAlias("orderAmount");
        q.select(quantitySum);
View Full Code Here

        DataContext dc = new JdbcDataContext(_connection);
        Query q = new Query();
        Schema schema = dc.getSchemaByName("public");
        Table productsTable = schema.getTableByName("products");
        Table customerTable = schema.getTableByName("customers");
        q.from(productsTable, "p").from(customerTable, "c");

        Column titleColumn = productsTable.getColumnByName("title");
        Column priceColumn = productsTable.getColumnByName("price");
        Column cityColumn = customerTable.getColumnByName("city");
        Column ageColumn = customerTable.getColumnByName("age");
View Full Code Here

    public void testGroupByQuery() throws Exception {
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));
        Table table = dc.getDefaultSchema().getTableByName("csv_people.csv");

        Query q = new Query();
        q.from(table);
        q.groupBy(table.getColumnByName("gender"));
        q.select(new SelectItem(table.getColumnByName("gender")),
                new SelectItem(FunctionType.MAX, table.getColumnByName("age")),
                new SelectItem(FunctionType.MIN, table.getColumnByName("age")), new SelectItem(FunctionType.COUNT, "*",
                        "total"), new SelectItem(FunctionType.MIN, table.getColumnByName("id")).setAlias("firstId"));
View Full Code Here

        MockDataContext dc = new MockDataContext("sch", "tab", "1");

        Table table = dc.getDefaultSchema().getTables()[0];

        Query q = new Query();
        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());
View Full Code Here

        Table table = dc.getDefaultSchema().getTables()[0];

        Query q = new Query();
        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());
View Full Code Here

        dataSet.close();
    }

    public void testOrderByWithoutSelecting() throws Exception {
        Query q = new Query();
        q.from(new FromItem(table2).setAlias("r"));
        Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
        Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
        q.select(new SelectItem(projectIdColumn));
        q.orderBy(roleColumn);
        assertEquals("SELECT r.project_id FROM MetaModelSchema.role r ORDER BY r.name ASC", q.toString());
View Full Code Here

        assertEquals(1, tableModel.getValueAt(7, 0));
    }

    public void testGroupByWithoutSelecting() throws Exception {
        Query q = new Query();
        q.from(new FromItem(table2).setAlias("r"));
        Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
        Column projectIdColumn = table2.getColumnByName(COLUMN_ROLE_PROJECT_ID);
        q.select(new SelectItem(FunctionType.SUM, projectIdColumn));
        q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
        q.orderBy(roleColumn);
View Full Code Here

        assertEquals("founder", tableModel.getValueAt(2, 0));
    }

    public void testSimpleGroupBy() throws Exception {
        Query q = new Query();
        q.from(new FromItem(table2).setAlias("r"));
        Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
        q.select(new SelectItem(roleColumn));
        q.groupBy(new GroupByItem(new SelectItem(roleColumn)));
        assertEquals("SELECT r.name FROM MetaModelSchema.role r GROUP BY r.name", q.toString());
View Full Code Here

        assertEquals(7.0, tableModel.getValueAt(0, 2));
    }

    public void testSimpleHaving() throws Exception {
        Query q = new Query();
        q.from(table2, "c");
        Column roleColumn = table2.getColumnByName(COLUMN_ROLE_ROLE_NAME);
        Column contributorIdColumn = table2.getColumnByName(COLUMN_ROLE_CONTRIBUTOR_ID);

        q.groupBy(roleColumn);
        SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, contributorIdColumn).setAlias("my_count");
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.