Package org.apache.metamodel.query

Examples of org.apache.metamodel.query.SelectItem


  public FunctionSelectBuilderImpl(FunctionType functionType, Column column,
      Query query, GroupedQueryBuilder queryBuilder) {
    super(queryBuilder);

    this.selectItem = new SelectItem(functionType, column);

    query.select(selectItem);
  }
View Full Code Here


  private SelectItem selectItem;

  public ColumnSelectBuilderImpl(Column column, Query query,
      GroupedQueryBuilder queryBuilder) {
    super(queryBuilder);
    this.selectItem = new SelectItem(column);

    query.select(selectItem);
  }
View Full Code Here

        if (right == null) {
            throw new IllegalArgumentException("right cannot be null");
        }
        getQuery().getFromClause().removeItem(leftItem);

        SelectItem[] leftOn = new SelectItem[] { new SelectItem(left) };
        SelectItem[] rightOn = new SelectItem[] { new SelectItem(right) };
        FromItem fromItem = new FromItem(joinType, leftItem, rightItem, leftOn, rightOn);

        getQuery().from(fromItem);

        return this;
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

            if (selectClause.isDistinct()) {
                sb.append("DISTINCT ");
            }
            List<SelectItem> items = selectClause.getItems();
            for (int i = 0; i < items.size(); i++) {
                SelectItem item = items.get(i);
                if (i != 0) {
                    sb.append(AbstractQueryClause.DELIM_COMMA);
                }
                sb.append(rewriteSelectItem(query, item));
            }
View Full Code Here

            final FromItem subQuerySelectItem = new FromItem(innerQuery).setAlias("metamodel_subquery");
            outerQuery.from(subQuerySelectItem);

            final List<SelectItem> innerSelectItems = innerQuery.getSelectClause().getItems();
            for (SelectItem selectItem : innerSelectItems) {
                outerQuery.select(new SelectItem(selectItem, subQuerySelectItem));
            }

            final String rewrittenOrderByClause = rewriteOrderByClause(innerQuery, innerQuery.getOrderByClause());
            final String rowOver = "ROW_NUMBER() " + "OVER(" + rewrittenOrderByClause + ")";
            innerQuery.select(new SelectItem(rowOver, "metamodel_row_number"));
            innerQuery.getOrderByClause().removeItems();

            final String baseQueryString = rewriteQuery(outerQuery);

            if (maxRows == null) {
View Full Code Here

        }
    }

    @Override
    public String rewriteFilterItem(FilterItem item) {
        SelectItem _selectItem = item.getSelectItem();
        Object _operand = item.getOperand();
        OperatorType _operator = item.getOperator();
        if (null != _selectItem && _operand != null) {
            ColumnType columnType = _selectItem.getExpectedColumnType();
            if (columnType != null) {
                if (columnType.isTimeBased()) {
                    // special logic for DB2 based time operands.

                    StringBuilder sb = new StringBuilder();
                    sb.append(_selectItem.getSameQueryAlias(true));
                    final Object operand = FilterItem.appendOperator(sb, _operand, _operator);

                    if (operand instanceof SelectItem) {
                        final String selectItemString = ((SelectItem) operand).getSameQueryAlias(true);
                        sb.append(selectItemString);
View Full Code Here

    private DataSet buildDataSet(final Column[] columns, int maxRows, final String relationshipId,
            final XSSFReader xssfReader) throws Exception {

        List<SelectItem> selectItems = new ArrayList<SelectItem>(columns.length);
        for (Column column : columns) {
            selectItems.add(new SelectItem(column));
        }
        final XlsxRowPublisherAction publishAction = new XlsxRowPublisherAction(_configuration, columns,
                relationshipId, xssfReader);

        return new RowPublisherDataSet(selectItems.toArray(new SelectItem[selectItems.size()]), maxRows, publishAction);
View Full Code Here

                        // multiplicity)
                        boolean uniqueForeignKeys = true;

                        Column[] foreignColumns = foreignKeyRelationship.getForeignColumns();

                        SelectItem countAllItem = SelectItem.getCountAllItem();
                        Query q = new Query().select(foreignColumns).select(countAllItem).from(table).groupBy(foreignColumns);
                        DataSet data = executeQuery(q);
                        Comparable<Object> comparable = NumberComparator.getComparable(1);
                        while (data.next()) {
                            Object value = data.getRow().getValue(countAllItem);
View Full Code Here

    public void testApproximatedCountSmallFile() throws Exception {
        DataContext dc = new CsvDataContext(new File("src/test/resources/csv_people.csv"));

        Table table = dc.getDefaultSchema().getTables()[0];
        Query q = dc.query().from(table).selectCount().toQuery();
        SelectItem selectItem = q.getSelectClause().getItem(0);
        selectItem.setFunctionApproximationAllowed(true);

        DataSet ds = dc.executeQuery(q);
        assertTrue(ds.next());
        Object[] values = ds.getRow().getValues();
        assertEquals(1, values.length);
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.