org.apache.metamodel.query.Query.setMaxRows()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.apache.metamodel.query.Query.setMaxRows方法的一些代码示例,展示了Query.setMaxRows的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setMaxRows方法的具体详情如下:
包路径:org.apache.metamodel.query.Query
类名称:Query
方法名:setMaxRows

Query.setMaxRows介绍

[英]Sets the maximum number of rows to be queried. If the result of the query yields more rows they should be discarded.
[中]设置要查询的最大行数。如果查询结果产生更多行,则应丢弃这些行。

代码示例

代码示例来源:origin: org.apache.metamodel/MetaModel-core

@Override
public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
  _query.setMaxRows(maxRows);
  return this;
}

代码示例来源:origin: org.apache.metamodel/MetaModel-core

@Override
public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
  _query.setMaxRows(maxRows);
  return this;
}

代码示例来源:origin: apache/metamodel

@Override
public SatisfiedQueryBuilder<GroupedQueryBuilder> limit(int maxRows) {
  _query.setMaxRows(maxRows);
  return this;
}

代码示例来源:origin: apache/metamodel

@Override
public SatisfiedQueryBuilder<GroupedQueryBuilder> maxRows(int maxRows) {
  _query.setMaxRows(maxRows);
  return this;
}

代码示例来源:origin: org.apache.metamodel/MetaModel-core

private void parseLimitClause(Query query, String limitClause) {
  limitClause = limitClause.trim();
  if (!limitClause.isEmpty()) {
    try {
      int limit = Integer.parseInt(limitClause);
      query.setMaxRows(limit);
    } catch (NumberFormatException e) {
      throw new QueryParserException("Could not parse LIMIT value: " + limitClause);
    }
  }
}

代码示例来源:origin: apache/metamodel

private void parseLimitClause(Query query, String limitClause) {
  limitClause = limitClause.trim();
  if (!limitClause.isEmpty()) {
    try {
      int limit = Integer.parseInt(limitClause);
      query.setMaxRows(limit);
    } catch (NumberFormatException e) {
      throw new QueryParserException("Could not parse LIMIT value: " + limitClause);
    }
  }
}

代码示例来源:origin: org.eobjects.analyzerbeans/AnalyzerBeans-core

@Override
public Query optimizeQuery(Query q, Category category) {
  if (category == Category.VALID) {
    q.setMaxRows(maxRows);
    if (firstRow > 1) {
      q.setFirstRow(firstRow);
    }
    if (orderColumn != null) {
      Column physicalColumn = orderColumn.getPhysicalColumn();
      q.orderBy(physicalColumn);
    }
  } else {
    throw new IllegalStateException("Can only optimize the VALID max rows category");
  }
  return q;
}

代码示例来源:origin: org.apache.metamodel/MetaModel-core

@Override
protected DataSet materializeMainSchemaTable(Table table, List<Column> columns,
    int maxRows) {
  // find the appropriate datacontext to execute a simple
  // table materialization query
  final DataContext dc = _dataContextRetrievalFunction.apply(table);
  final Query q = new Query().select(columns).from(table);
  if (maxRows >= 0) {
    q.setMaxRows(maxRows);
  }
  return dc.executeQuery(q);
}

代码示例来源:origin: apache/metamodel

@Override
protected DataSet materializeMainSchemaTable(Table table, List<Column> columns,
    int maxRows) {
  // find the appropriate datacontext to execute a simple
  // table materialization query
  final DataContext dc = _dataContextRetrievalFunction.apply(table);
  final Query q = new Query().select(columns).from(table);
  if (maxRows >= 0) {
    q.setMaxRows(maxRows);
  }
  return dc.executeQuery(q);
}

代码示例来源:origin: datacleaner/DataCleaner

private DataSet getPreviewData(final Resource resource) {
  if (!isPreviewDataAvailable()) {
    logger.info("Not displaying preview table because isPreviewDataAvailable() returned false");
    return null;
  }
  logger.info("Attempting to fetch preview data from resource: {}", resource);
  final D datastore = getPreviewDatastore(resource);
  try (DatastoreConnection con = datastore.openConnection()) {
    final DataContext dc = con.getDataContext();
    final Table table = getPreviewTable(dc);
    if (table == null) {
      logger.info("Not displaying preview because getPreviewTable(..) returned null");
      return null;
    }
    List<Column> columns = table.getColumns();
    if (columns.size() > getPreviewColumns()) {
      // include max 10 columns
      columns = columns.stream().limit(getPreviewColumns()).collect(Collectors.toList());
    }
    final Query q = dc.query().from(table).select(columns).toQuery();
    q.setMaxRows(PREVIEW_ROWS);
    return dc.executeQuery(q);
  }
}

代码示例来源:origin: datacleaner/DataCleaner

private DataSet getPreviewData(final String filename) {
  if (!isPreviewDataAvailable()) {
    logger.info("Not displaying preview table because isPreviewDataAvailable() returned false");
    return null;
  }
  final D datastore = getPreviewDatastore(filename);
  try (DatastoreConnection con = datastore.openConnection()) {
    final DataContext dc = con.getDataContext();
    final Table table = getPreviewTable(dc);
    List<Column> columns = table.getColumns();
    if (columns.size() > getPreviewColumns()) {
      // include max 10 columns
      columns = columns.stream().limit(getPreviewColumns()).collect(Collectors.toList());
    }
    final Query q = dc.query().from(table).select(columns).toQuery();
    q.setMaxRows(7);
    return dc.executeQuery(q);
  }
}

代码示例来源:origin: org.apache.metamodel/MetaModel-core

query.setMaxRows(sampleSize);

代码示例来源:origin: datacleaner/DataCleaner

@Override
  public void actionPerformed(final ActionEvent event) {
    final String queryString = _queryTextArea.getText();
    logger.debug("Query being parsed: {}", queryString);
    try (DatastoreConnection con = _datastore.openConnection()) {
      final DataContext dataContext = con.getDataContext();
      final Query q = dataContext.parseQuery(queryString);
      logger.info("Parsed query: {}", q);
      final String limitString = _limitTextField.getText();
      if (!StringUtils.isNullOrEmpty(limitString)) {
        final int limit = Integer.parseInt(limitString);
        q.setMaxRows(limit);
      }
      final DataSet dataSet = dataContext.executeQuery(q);
      _centerPanel.setVisible(true);
      _table.setModel(new DataSetTableModel(dataSet));
    } catch (final MetaModelException e) {
      WidgetUtils.showErrorMessage("Failed to execute query", e.getMessage(), e);
    }
  }
});

代码示例来源:origin: org.eobjects.analyzerbeans/AnalyzerBeans-core

private void compileLookupQuery() {
  try {
    final Column[] queryOutputColumns = getQueryOutputColumns(false);
    final Column queryOutputColumn = queryOutputColumns[0];
    final Table table = queryOutputColumn.getTable();
    Query query = new Query().from(table).select(queryOutputColumns);
    if (!isCarthesianProductMode()) {
      final Column[] queryConditionColumns = getQueryConditionColumns();
      for (int i = 0; i < queryConditionColumns.length; i++) {
        query = query.where(queryConditionColumns[i], OperatorType.EQUALS_TO, new QueryParameter());
      }
    }
    if (joinSemantic == JoinSemantic.LEFT_JOIN_MAX_ONE) {
      query = query.setMaxRows(1);
    }
    lookupQuery = datastoreConnection.getDataContext().compileQuery(query);
  } catch (RuntimeException e) {
    logger.error("Error occurred while compiling lookup query", e);
    throw e;
  }
}

代码示例来源:origin: datacleaner/DataCleaner

private void compileLookupQuery() {
  try {
    final Column[] queryOutputColumns = getQueryOutputColumns(false);
    final Column queryOutputColumn = queryOutputColumns[0];
    final Table table = queryOutputColumn.getTable();
    Query query = new Query().from(table).select(queryOutputColumns);
    if (!isCarthesianProductMode()) {
      final Column[] queryConditionColumns = getQueryConditionColumns();
      for (int i = 0; i < queryConditionColumns.length; i++) {
        query = query.where(queryConditionColumns[i], OperatorType.EQUALS_TO, new QueryParameter());
      }
    }
    if (joinSemantic == JoinSemantic.LEFT_JOIN_MAX_ONE) {
      query = query.setMaxRows(1);
    }
    lookupQuery = datastoreConnection.getDataContext().compileQuery(query);
  } catch (final RuntimeException e) {
    logger.error("Error occurred while compiling lookup query", e);
    throw e;
  }
}

代码示例来源:origin: org.eobjects.analyzerbeans/AnalyzerBeans-core

countQuery.setMaxRows(null);
countQuery.setFirstRow(null);
countQuery.getSelectClause().removeItems();

代码示例来源:origin: datacleaner/DataCleaner

countQuery.setMaxRows(null);
countQuery.setFirstRow(null);
countQuery.getSelectClause().removeItems();

代码示例来源:origin: datacleaner/DataCleaner

public PojoTableType createPojoTable(final DataContext dataContext, final Table table, final List<Column> usedColumns,
    final int maxRows) {
  final PojoTableType tableType = new PojoTableType();
  tableType.setName(table.getName());
  // read columns
  final Columns columnsType = new Columns();
  for (final Column column : usedColumns) {
    columnsType.getColumn().add(createPojoColumn(column.getName(), column.getType()));
  }
  tableType.setColumns(columnsType);
  if (maxRows > 0) {
    // read values
    final Query q = dataContext.query().from(table).select(usedColumns).toQuery();
    q.setMaxRows(maxRows);
    final Document document = XmlUtils.createDocument();
    final Rows rowsType = new Rows();
    try (DataSet ds = dataContext.executeQuery(q)) {
      while (ds.next()) {
        final Row row = ds.getRow();
        rowsType.getRow().add(createPojoRow(row, document));
      }
    }
    tableType.setRows(rowsType);
  }
  return tableType;
}

代码示例来源:origin: org.apache.metamodel/MetaModel-core

@Override
  public Query clone() {
    final Query q = new Query();
    q.setMaxRows(_maxRows);
    q.setFirstRow(_firstRow);
    q.getSelectClause().setDistinct(_selectClause.isDistinct());
    for (FromItem item : _fromClause.getItems()) {
      q.from(item.clone());
    }
    for (SelectItem item : _selectClause.getItems()) {
      q.select(item.clone(q));
    }
    for (FilterItem item : _whereClause.getItems()) {
      q.where(item.clone());
    }
    for (GroupByItem item : _groupByClause.getItems()) {
      q.groupBy(item.clone());
    }
    for (FilterItem item : _havingClause.getItems()) {
      q.having(item.clone());
    }
    for (OrderByItem item : _orderByClause.getItems()) {
      q.orderBy(item.clone());
    }
    return q;
  }
}

代码示例来源:origin: apache/metamodel

@Override
  public Query clone() {
    final Query q = new Query();
    q.setMaxRows(_maxRows);
    q.setFirstRow(_firstRow);
    q.getSelectClause().setDistinct(_selectClause.isDistinct());
    for (FromItem item : _fromClause.getItems()) {
      q.from(item.clone());
    }
    for (SelectItem item : _selectClause.getItems()) {
      q.select(item.clone(q));
    }
    for (FilterItem item : _whereClause.getItems()) {
      q.where(item.clone());
    }
    for (GroupByItem item : _groupByClause.getItems()) {
      q.groupBy(item.clone());
    }
    for (FilterItem item : _havingClause.getItems()) {
      q.having(item.clone());
    }
    for (OrderByItem item : _orderByClause.getItems()) {
      q.orderBy(item.clone());
    }
    return q;
  }
}

相关文章