Examples of FromItem


Examples of org.apache.metamodel.query.FromItem

        for (Query splitQuery : splitQueries) {
            Query newQuery = _query.clone();
            FromClause fromClause = newQuery.getFromClause();
            String alias = fromClause.getItem(fromItemIndex).getAlias();
            fromClause.removeItem(fromItemIndex);
            newQuery.from(new FromItem(splitQuery).setAlias(alias));
            result.add(newQuery);
        }
        return result;
    }
View Full Code Here

Examples of org.apache.metamodel.query.FromItem

    private long getRowCount(Query q) {
        q = q.clone();
        SelectItem countAllItem = SelectItem.getCountAllItem();
        if (q.getGroupByClause().getItemCount() > 0) {
            q = new Query().from(new FromItem(q).setAlias("sq")).select(countAllItem);
        } else {
            q.getSelectClause().removeItems();
            q.select(countAllItem);
        }
        Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
View Full Code Here

Examples of org.apache.metamodel.query.FromItem

            FromItem[] sqItems = getTableFromItems(item.getSubQuery());
            for (int i = 0; i < sqItems.length; i++) {
                result.add(sqItems[i]);
            }
        } else if (item.getJoin() != null) {
            FromItem leftSide = item.getLeftSide();
            result.addAll(getTableFromItems(leftSide));
            FromItem rightSide = item.getRightSide();
            result.addAll(getTableFromItems(rightSide));
        } else {
            throw new IllegalStateException("FromItem was neither of Table type, SubQuery type or Join type: " + item);
        }
        return result;
View Full Code Here

Examples of org.apache.metamodel.query.FromItem

        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

Examples of org.apache.metamodel.query.FromItem

        assertEquals("Row[values=[project_contributor, VIEW, 3, null]]", dataSet.getRow().toString());
        assertFalse(dataSet.next());
        dataSet.close();

        Relationship relationship = tablesTable.getRelationships(columnsTable)[0];
        FromItem joinFromItem = new FromItem(JoinType.INNER, relationship);
        Query q = new Query().select(tablesTable.getColumnByName("name")).select(columnsTable.getColumnByName("name"))
                .select(columnsTable.getBooleanColumns()).from(joinFromItem);

        assertEquals("SELECT tables.name, columns.name, columns.nullable, columns.indexed "
                + "FROM information_schema.tables INNER JOIN information_schema.columns "
View Full Code Here

Examples of org.apache.metamodel.query.FromItem

        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

Examples of org.apache.metamodel.query.FromItem

        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

Examples of org.apache.metamodel.query.FromItem

        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

Examples of org.apache.metamodel.query.FromItem

        final QueryParameter param1 = new QueryParameter();
        final Query subQuery = dc.query().from(table1).select("name").where(COLUMN_CONTRIBUTOR_COUNTRY).eq(param1)
                .toQuery();

        final FromItem subQueryFromItem = new FromItem(subQuery);
        final Query query = new Query().select(new SelectItem(subQuery.getSelectClause().getItem(0), subQueryFromItem))
                .from(subQueryFromItem);

        final CompiledQuery compiledQuery = dc.compileQuery(query);
View Full Code Here

Examples of org.apache.metamodel.query.FromItem

    public void testCarthesianProductWithWhere() throws Exception {
        DataContext dc = getDataContext();

        SelectItem s1 = new SelectItem(table1.getColumnByName(COLUMN_CONTRIBUTOR_NAME));
        SelectItem s2 = new SelectItem(table2.getColumnByName(COLUMN_ROLE_ROLE_NAME));
        FromItem f1 = new FromItem(table1);
        FromItem f2 = new FromItem(table2);

        Query q = new Query();
        q.select(s1);
        q.select(s2);
        q.from(f1);
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.