Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.SelectItem


        Schema schema = dc.getSchemaByName("Sales");
        Table customersTable = schema.getTableByName("CUSTOMER");

        Query q = new Query().from(customersTable, "cus-tomers").select(
                new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
        q.setMaxRows(5);

        assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());

        String queryString = queryRewriter.rewriteQuery(q);
View Full Code Here


        Schema schema = dataContext.getDefaultSchema();
    Table departmentTable = schema.getTableByName("DEPARTMENT");
    Table employeeTable = schema.getTableByName("EMPLOYEE");
    Query q = new Query().from(new FromItem(JoinType.INNER, departmentTable.getRelationships(employeeTable)[0]));
    q.select(departmentTable.getColumns()[1]);
    q.select(new SelectItem(employeeTable.getColumns()[4]).setAlias("hire-date"));
    assertEquals(
        "SELECT \"DEPARTMENT\".\"DEPARTMENT\", \"EMPLOYEE\".\"HIRE_DATE\" AS hire-date FROM \"EMPLOYEE\" INNER JOIN \"DEPARTMENT\" ON \"EMPLOYEE\".\"EMP_NO\" = \"DEPARTMENT\".\"MNGR_NO\"",
        q.toString());

    DataSet data = dataContext.executeQuery(q);
View Full Code Here

        List<Object[]> data1 = new ArrayList<Object[]>();
        data1.add(new Object[] { "f" });
        data1.add(new Object[] { "o" });
        data1.add(new Object[] { "o" });
        DataSet dataSet1 = createDataSet(
                new SelectItem[] { new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR)) }, data1);
        return dataSet1;
    }
View Full Code Here

    private DataSet createDataSet2() {
        List<Object[]> data2 = new ArrayList<Object[]>();
        data2.add(new Object[] { "b" });
        data2.add(new Object[] { "a" });
        data2.add(new Object[] { "r" });
        DataSet dataSet2 = createDataSet(new SelectItem[] { new SelectItem("bar", "bar") }, data2);
        return dataSet2;
    }
View Full Code Here

    private DataSet createDataSet3() {
        List<Object[]> data3 = new ArrayList<Object[]>();
        data3.add(new Object[] { "w00p", true });
        data3.add(new Object[] { "yippie", false });
        DataSet dataSet3 = createDataSet(new SelectItem[] { new SelectItem("expression", "e"),
                new SelectItem("webish?", "w") }, data3);
        return dataSet3;
    }
View Full Code Here

        return dataSet3;
    }

    private DataSet createDataSet4() {
        List<Object[]> data4 = new ArrayList<Object[]>();
        DataSet dataSet4 = createDataSet(new SelectItem[] { new SelectItem("abc", "abc") }, data4);
        return dataSet4;
    }
View Full Code Here

        assertEquals("[MetaModelSchema.contributor, MetaModelSchema.project, MetaModelSchema.project_contributor]",
                Arrays.toString(fromItems));
    }

    public void testGetSelectionNoRows() throws Exception {
        SelectItem item1 = new SelectItem("foo", "f");
        SelectItem item2 = new SelectItem("bar", "b");
        SelectItem item3 = new SelectItem("baz", "bz");
        List<SelectItem> selectItems1 = Arrays.asList(item1, item2, item3);
        List<SelectItem> selectItems2 = Arrays.asList(item2, item1);

        DataSet ds = MetaModelHelper.getSelection(selectItems2, new EmptyDataSet(selectItems1));
        assertEquals(SubSelectionDataSet.class, ds.getClass());
View Full Code Here

        assertEquals("[bar AS b, foo AS f]", Arrays.toString(ds.getSelectItems()));
    }

    public void testLeftJoinNoRowsOrSingleRow() throws Exception {
        SelectItem item1 = new SelectItem("foo", "f");
        SelectItem item2 = new SelectItem("bar", "b");
        SelectItem item3 = new SelectItem("baz", "z");
        List<SelectItem> selectItems1 = Arrays.asList(item1, item2);
        List<SelectItem> selectItems2 = Arrays.asList(item3);

        DataSet ds1 = new EmptyDataSet(selectItems1);
        DataSet ds2 = new EmptyDataSet(selectItems2);
View Full Code Here

public class RowTest extends MetaModelTestCase {

    public void testRow() throws Exception {
        Schema schema = getExampleSchema();
        Table projectTable = schema.getTableByName(TABLE_PROJECT);
        SelectItem item = new SelectItem(projectTable.getColumns()[0]);
        SelectItem[] items = { item };
        DataSetHeader header = new CachingDataSetHeader(items);
        Object[] values = { "foobar" };
        Row row = new DefaultRow(header, values);
        assertEquals("Row[values=[foobar]]", row.toString());
View Full Code Here

    }

    public void testGetSubSelection() throws Exception {
        Schema schema = getExampleSchema();
        Table projectTable = schema.getTableByName(TABLE_PROJECT);
        SelectItem item1 = new SelectItem(projectTable.getColumns()[0]);
        SelectItem item2 = new SelectItem(projectTable.getColumns()[0]);
        SelectItem[] items = { item1, item2 };
        DataSetHeader header = new CachingDataSetHeader(items);
        Object[] values = { "foo", "bar" };
        Row row = new DefaultRow(header, values);
        row = row.getSubSelection(new SimpleDataSetHeader(new SelectItem[] { item1 }));
View Full Code Here

TOP

Related Classes of org.apache.metamodel.query.SelectItem

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.