Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.Query


        assertEquals("SELECT a.foo AS f FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo ORDER BY a.foo ASC",
                q.toSql());
    }

    public void testSelectEverythingFromTable() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
        assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
    }
View Full Code Here


        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl");
        assertEquals("SELECT tbl.foo, tbl.bar, tbl.baz FROM sch.tbl", q.toSql());
    }

    public void testSelectEverythingFromJoin() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT * FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals(
                "SELECT a.foo, a.bar, a.baz, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());

        q = MetaModelHelper.parseQuery(dc, "SELECT a.foo, b.* FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo");
        assertEquals("SELECT a.foo, b.foo, b.bar, b.baz FROM sch.tbl a INNER JOIN sch.tbl b ON a.foo = b.foo",
                q.toSql());
    }
View Full Code Here

    public void testSelectColumnWithDotInName() throws Exception {
        MutableColumn col = (MutableColumn) dc.getTableByQualifiedLabel("tbl").getColumn(0);
        col.setName("fo.o");

        Query q = MetaModelHelper.parseQuery(dc, "SELECT fo.o AS f FROM sch.tbl");
        assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
    }
View Full Code Here

        Query q = MetaModelHelper.parseQuery(dc, "SELECT fo.o AS f FROM sch.tbl");
        assertEquals("SELECT tbl.fo.o AS f FROM sch.tbl", q.toSql());
    }

    public void testSelectAlias() throws Exception {
        Query q = MetaModelHelper.parseQuery(dc, "SELECT foo AS f FROM sch.tbl");
        assertEquals("SELECT tbl.foo AS f FROM sch.tbl", q.toSql());

        q = MetaModelHelper.parseQuery(dc, "SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'");
        assertEquals("SELECT a.foo AS foobarbaz FROM sch.tbl a WHERE foobarbaz = '123'", q.toSql());
    }
View Full Code Here

    Table[] tables = schema.getTables();
        Table table1 = tables[0];
        Table table2 = tables[2];
        assertNotSame(table1, table2);

    Query q = composite
        .query()
        .from(table1)
        .leftJoin(table2)
        .on(table1.getColumnByName("foo"),
            table2.getColumnByName("foo"))
        .select(table1.getColumnByName("foo"),
            table2.getColumnByName("foo"),
            table1.getColumnByName("bar"),
            table2.getColumnByName("baz")).toQuery();
    assertEquals(
        "SELECT table.foo, table.foo, table.bar, table.baz "
            + "FROM schema.table LEFT JOIN schema.table ON table.foo = table.foo",
        q.toSql());

    DataSet ds = composite.executeQuery(q);
    assertTrue(ds.next());
    assertEquals("Row[values=[1, 1, hello, world]]", ds.getRow().toString());
    assertTrue(ds.next());
View Full Code Here

    Schema[] schemas = dc.getSchemas();
    assertEquals("[Schema[name=mysql], Schema[name=performance_schema], Schema[name=portal], "
        + "Schema[name=sakila], Schema[name=world]]", Arrays.toString(schemas));

    Table table = dc.getSchemaByName("sakila").getTableByName("film");
    Query q = new Query().from(table).select(table.getColumns());
    DataSet data = dc.executeQuery(q);
    TableModel tableModel = new DataSetTableModel(data);
    assertEquals(13, tableModel.getColumnCount());
    assertEquals(1000, tableModel.getRowCount());
  }
View Full Code Here

        "[Column[name=actor_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
            + "Column[name=film_id,columnNumber=1,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
            + "Column[name=last_update,columnNumber=2,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
        Arrays.toString(filmActorJoinTable.getColumns()));

    Query q = new Query();
    q.from(new FromItem(actorTable).setAlias("a"));
    q.select(actorTable.getColumns());
    q.getSelectClause().getItem(0).setAlias("foo-bar");
    assertEquals(
        "SELECT a.`actor_id` AS foo-bar, a.`first_name`, a.`last_name`, a.`last_update` FROM sakila.`actor` a",
        q.toString());
    FilterItem f1 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 5);
    FilterItem f2 = new FilterItem(q.getSelectClause().getItem(0), OperatorType.EQUALS_TO, 8);
    q.where(new FilterItem(f1, f2));

    DataSet dataSet = dc.executeQuery(q);
    TableModel tableModel = new DataSetTableModel(dataSet);
    assertEquals(4, tableModel.getColumnCount());
    assertEquals(2, tableModel.getRowCount());
    assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));

    q.setMaxRows(1);
    dataSet = dc.executeQuery(q);
    tableModel = new DataSetTableModel(dataSet);
    assertEquals(4, tableModel.getColumnCount());
    assertEquals(1, tableModel.getRowCount());
    assertEquals("LOLLOBRIGIDA", tableModel.getValueAt(0, 2));
   
    q.setMaxRows(1);
    q.setFirstRow(2);
        dataSet = dc.executeQuery(q);
        tableModel = new DataSetTableModel(dataSet);
        assertEquals(4, tableModel.getColumnCount());
        assertEquals(1, tableModel.getRowCount());
        assertEquals("JOHANSSON", tableModel.getValueAt(0, 2));

    q.getWhereClause().removeItems();
    q.setMaxRows(25);
    q.setFirstRow(1);
    dataSet = dc.executeQuery(q);
    tableModel = new DataSetTableModel(dataSet);
    assertEquals(4, tableModel.getColumnCount());
    assertEquals(25, tableModel.getRowCount());
    assertEquals("GUINESS", tableModel.getValueAt(0, 2).toString());
View Full Code Here

            return input.select(table.getColumnByName("bar"));

          }
        });

    DataSet ds = dc.executeQuery(new Query().from(table));
    assertEquals("[table.foo, table.bar]", Arrays.toString(ds.getSelectItems()));
  }
View Full Code Here

            return;
        }
       
    DataContext dc = new JdbcDataContext(getConnection());
    Table table = dc.getDefaultSchema().getTableByName("film");
    Query q = new Query().select(table.getColumns()).from(table).setMaxRows(400);
    dc.executeQuery(q);
  }
View Full Code Here

    assertNotNull(paymentTable);
    Column countryColumn = staffListTable.getColumnByName("country");
    assertNotNull(countryColumn);
    Column paymentColumn = paymentTable.getColumns()[0];
    assertNotNull(paymentColumn);
    Query q = new Query().from(staffListTable, "sl").from(paymentTable, "e").select(countryColumn, paymentColumn);
    assertEquals("SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e",
        q.toString());

    QuerySplitter qs = new QuerySplitter(dc, q);
    assertEquals(32098, qs.getRowCount());
    List<Query> splitQueries = qs.setMaxRows(8000).splitQuery();
    assertEquals(7, splitQueries.size());
View Full Code Here

TOP

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

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.