Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.Column


    }

    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());

        DataContext dc = getDataContext();
View Full Code Here


    }

    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);
        assertEquals("SELECT SUM(r.project_id) FROM MetaModelSchema.role r GROUP BY r.name ORDER BY r.name ASC",
                q.toString());
View Full Code Here

    }

    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());

        DataContext dc = getDataContext();
View Full Code Here

    }

    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");
        q.select(new SelectItem(roleColumn), countSelectItem);
        q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 1));
View Full Code Here

    }

    public void testHavingFunctionNotSelected() 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");
        q.select(new SelectItem(roleColumn));
        q.having(new FilterItem(countSelectItem, OperatorType.GREATER_THAN, 3));
View Full Code Here

                    // checking if the query is a primary key lookup query
                    if (whereItems.size() == 1) {
                        final FilterItem whereItem = whereItems.get(0);
                        final SelectItem selectItem = whereItem.getSelectItem();
                        if (!whereItem.isCompoundFilter() && selectItem != null && selectItem.getColumn() != null) {
                            final Column column = selectItem.getColumn();
                            if (column.isPrimaryKey() && whereItem.getOperator() == OperatorType.EQUALS_TO) {
                                logger.debug("Query is a primary key lookup query. Trying executePrimaryKeyLookupQuery(...)");
                                final Object operand = whereItem.getOperand();
                                final Row row = executePrimaryKeyLookupQuery(table, selectItems, column, operand);
                                if (row == null) {
                                    logger.debug("DataContext did not return any primary key lookup query results. Proceeding with manual lookup.");
View Full Code Here

            query.put("$or", orList);

        } else {

            final Column column = item.getSelectItem().getColumn();
            final String columnName = column.getName();
            final Object operand = item.getOperand();
            final String operatorName = getOperatorName(item);

            final BasicDBObject existingFilterObject = (BasicDBObject) query.get(columnName);
            if (existingFilterObject == null) {
View Full Code Here

        assertEquals("baz.buuh", dc.getColumnByQualifiedLabel("\"foo\".bar.\"baz.buuh\"").getName());
    }

    public void testGetColumnByQualifiedLabel() throws Exception {
        MyDataContext dc = new MyDataContext();
        Column result;

        result = dc.getColumnByQualifiedLabel("foobar.tab.le.col1");
        result = dc.getColumnByQualifiedLabel("blabla.tab.le.col4");
        result = dc.getColumnByQualifiedLabel("FOOBAR.TABLE.COL3");
        assertNull(result);

        result = dc.getColumnByQualifiedLabel("foobar.table.col1");
        assertEquals("col1", result.getName());
        assertEquals("table", result.getTable().getName());
        assertEquals("foobar", result.getTable().getSchema().getName());

        result = dc.getColumnByQualifiedLabel("foo.bar.table.col1");
        assertEquals("col1", result.getName());
        assertEquals("table", result.getTable().getName());
        assertEquals("foo.bar", result.getTable().getSchema().getName());

        result = dc.getColumnByQualifiedLabel("foobar.tab.le.col3");
        assertEquals("col3", result.getName());
        assertEquals("tab.le", result.getTable().getName());
        assertEquals("foobar", result.getTable().getSchema().getName());

        result = dc.getColumnByQualifiedLabel("FOO.BAR.tab.le.col3");
        assertEquals("col3", result.getName());
        assertEquals("tab.le", result.getTable().getName());
        assertEquals("foo.bar", result.getTable().getSchema().getName());

        result = dc.getColumnByQualifiedLabel("tab.le.col3");
        assertEquals("col3", result.getName());
        assertEquals("tab.le", result.getTable().getName());
        assertEquals("foobar", result.getTable().getSchema().getName());
    }
View Full Code Here

        assertEquals("SELECT COUNT(*) FROM MetaModelSchema.contributor", q.toString());
    }

    public void testCloneGroupBy() throws Exception {
        Table table = _schema.getTableByName(TABLE_PROJECT);
        Column column = table.getColumnByName(COLUMN_PROJECT_NAME);
        Query q = new Query().from(table).selectCount().select(column).groupBy(column);
        assertEquals(q.toString(), q.clone().toString());

        q.having(new FilterItem(SelectItem.getCountAllItem(), OperatorType.GREATER_THAN, 20));
        assertEquals(q.toString(), q.clone().toString());
View Full Code Here

    }

    public void testFromItemAlias() throws Exception {
        Query q = new Query();
        Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
        Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
        Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);

        FromItem fromContributor = new FromItem(contributorTable);
        q.from(fromContributor);
        q.select(nameColumn, countryColumn);
        assertEquals("SELECT contributor.name, contributor.country FROM MetaModelSchema.contributor", q.toString());

        fromContributor.setAlias("c");

        assertEquals("SELECT c.name, c.country FROM MetaModelSchema.contributor c", q.toString());

        q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(nameColumn)));
        q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(countryColumn)));
        q.select(new SelectItem(FunctionType.COUNT, "*", "total"));
        assertEquals(2, q.getGroupByClause().getItems().size());
        assertEquals(
                "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c GROUP BY c.name, c.country",
                q.toString());

        Column contributorIdColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID);
        q.where(contributorIdColumn, OperatorType.EQUALS_TO, 1);
        assertEquals(
                "SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 GROUP BY c.name, c.country",
                q.toString());

View Full Code Here

TOP

Related Classes of org.apache.metamodel.schema.Column

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.