Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.SelectItem


        q1.select(table1.getColumns());

        Query q2 = new Query();
        FromItem fromItem = new FromItem(q1);
        q2.from(fromItem);
        SelectItem selectItem = new SelectItem(q1.getSelectClause().getItems().get(1), fromItem);
        selectItem.setAlias("e");
        q2.select(selectItem);
        assertEquals(
                "SELECT name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor)",
                q2.toString());

        fromItem.setAlias("c");
        assertEquals(
                "SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c",
                q2.toString());

        DataContext dc = getDataContext();
        DataSet data = dc.executeQuery(q2);
        assertEquals(1, data.getSelectItems().length);
        assertTrue(data.next());
        assertEquals("Row[values=[kasper]]", data.getRow().toString());
        assertTrue(data.next());
        assertEquals("Row[values=[asbjorn]]", data.getRow().toString());
        assertTrue(data.next());
        assertEquals("Row[values=[johny]]", data.getRow().toString());
        assertTrue(data.next());
        assertEquals("Row[values=[daniel]]", data.getRow().toString());
        assertTrue(data.next());
        assertEquals("Row[values=[sasidhar]]", data.getRow().toString());
        assertTrue(data.next());
        assertEquals("Row[values=[jesper]]", data.getRow().toString());
        assertFalse(data.next());

        // Create a sub-query for a sub-query
        Query q3 = new Query();
        fromItem = new FromItem(q2);
        q3.from(fromItem);
        selectItem = new SelectItem(q2.getSelectClause().getItems().get(0), fromItem);
        selectItem.setAlias("f");
        q3.select(selectItem);
        fromItem.setAlias("d");
        assertEquals(
                "SELECT d.e AS f FROM (SELECT c.name AS e FROM (SELECT contributor.contributor_id, contributor.name, contributor.country FROM MetaModelSchema.contributor) c) d",
                q3.toString());
View Full Code Here


    @Override
    protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue) {
        final DBCollection collection = _mongoDb.getCollection(table.getName());

        List<FilterItem> whereItems = new ArrayList<FilterItem>();
        SelectItem selectItem = new SelectItem(primaryKeyColumn);
        FilterItem primaryKeyWhereItem = new FilterItem(selectItem, OperatorType.EQUALS_TO, keyValue);
        whereItems.add(primaryKeyWhereItem);
        final DBObject query = createMongoDbQuery(table, whereItems);
        final DBObject resultDBObject = collection.findOne(query);
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) {
View Full Code Here

        }

        final int size = header.size();
        final Object[] values = new Object[size];
        for (int i = 0; i < values.length; i++) {
            final SelectItem selectItem = header.getSelectItem(i);
            final String key = selectItem.getColumn().getName();
            final Object value = dbObject.get(key);
            values[i] = toValue(selectItem.getColumn(), value);
        }
        return new DefaultRow(header, values);
    }
View Full Code Here

        final Date date = DateUtils.get(2013, Month.JANUARY, 23);
        final Timestamp dateTime = new Timestamp(0l);

        final List<FilterItem> children = new ArrayList<FilterItem>();
        children.add(new FilterItem(new SelectItem(new MutableColumn("foo")), OperatorType.EQUALS_TO, "hello\n 'world'"));
        children.add(new FilterItem(new SelectItem(new MutableColumn("bar")), OperatorType.EQUALS_TO, 123));
        children.add(new FilterItem(new SelectItem(new MutableColumn("baz").setType(ColumnType.DATE)),
                OperatorType.EQUALS_TO, date));
        children.add(new FilterItem(new SelectItem(new MutableColumn("saz").setType(ColumnType.TIMESTAMP)),
                OperatorType.EQUALS_TO, dateTime));

        final FilterItem filterItem = new FilterItem(children);

        SalesforceDataContext.rewriteFilterItem(sb, filterItem);
View Full Code Here

        Schema schema = strategy.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

public class RowPublisherDataSetTest extends TestCase {

  public void testMaxSize() throws Exception {
    SelectItem[] selectItems = new SelectItem[2];
    selectItems[0] = new SelectItem(new MutableColumn("foos"));
    selectItems[1] = new SelectItem(new MutableColumn("bars"));
    DataSet ds = new RowPublisherDataSet(selectItems, 5,
        new Action<RowPublisher>() {
          @Override
          public void run(RowPublisher publisher) throws Exception {
View Full Code Here

    ds.close();
  }

  public void testExceptionInAction() throws Exception {
    SelectItem[] selectItems = new SelectItem[2];
    selectItems[0] = new SelectItem(new MutableColumn("foos"));
    selectItems[1] = new SelectItem(new MutableColumn("bars"));
    DataSet ds = new RowPublisherDataSet(selectItems, 5,
        new Action<RowPublisher>() {
          @Override
          public void run(RowPublisher publisher) throws Exception {
            publisher.publish(new Object[] { "foo0", "bar0" });
View Full Code Here

import org.apache.metamodel.schema.Table;

public class MetaModelHelperTest extends MetaModelTestCase {

    public void testLeftJoin() throws Exception {
        SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
        SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
        SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
        SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
        SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
        SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
        SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
        List<Object[]> data1 = new ArrayList<Object[]>();
        data1.add(new Object[] { 1, "peter", 18, 1 });
        data1.add(new Object[] { 2, "tom", 19, 2 });
        data1.add(new Object[] { 3, "betty", 19, null });
        data1.add(new Object[] { 4, "barbara", 17, 3 });
View Full Code Here

        assertEquals("[5, susie, 18, 4, 4, trying harder, try]", Arrays.toString(objectArrays.get(4)));
        assertEquals(5, objectArrays.size());
    }

    public void testRightJoin() throws Exception {
        SelectItem si1 = new SelectItem(new MutableColumn("person_id", ColumnType.INTEGER));
        SelectItem si2 = new SelectItem(new MutableColumn("person_name", ColumnType.VARCHAR));
        SelectItem si3 = new SelectItem(new MutableColumn("person_age", ColumnType.INTEGER));
        SelectItem si4 = new SelectItem(new MutableColumn("person_role_id", ColumnType.INTEGER));
        SelectItem si5 = new SelectItem(new MutableColumn("role_id", ColumnType.INTEGER));
        SelectItem si6 = new SelectItem(new MutableColumn("role_name", ColumnType.VARCHAR));
        SelectItem si7 = new SelectItem(new MutableColumn("role_code", ColumnType.VARCHAR));
        List<Object[]> data1 = new ArrayList<Object[]>();
        data1.add(new Object[] { 1, "peter", 18, 1 });
        data1.add(new Object[] { 2, "tom", 19, 2 });
        data1.add(new Object[] { 3, "betty", 19, null });
        data1.add(new Object[] { 4, "barbara", 17, 3 });
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.