dk.eobjects.metamodel.query.Query类的使用及代码示例

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

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

Query介绍

[英]Represents a query to retrieve data by. A query is made up of six clauses, equivalent to the SQL standard:

  • the SELECT clause, which define the wanted columns of the resulting DataSet
  • the FROM clause, which define where to retrieve the data from
  • the WHERE clause, which define filters on the retrieved data
  • the GROUP BY clause, which define if the result should be grouped and aggregated according to some columns acting as categories
  • the HAVING clause, which define filters on the grouped data
  • the ORDER BY clause, which define sorting of the resulting dataset
    Queries are executed using the DataContext.executeQuery method or can alternatively be used directly in JDBC by using the toString() method.
    [中]表示用于检索数据的查询。查询由六个子句组成,相当于SQL标准:
    *SELECT子句,用于定义结果数据集所需的列
    *FROM子句定义从何处检索数据
    *WHERE子句,用于定义检索到的数据的过滤器
    *GROUP BY子句,它定义是否应根据充当类别的某些列对结果进行分组和聚合
    *HAVING子句定义分组数据的过滤器
    *ORDER BY子句,用于定义结果数据集的排序
    使用DataContext执行查询。executeQuery方法,也可以通过使用toString()方法直接在JDBC中使用。

代码示例

代码示例来源:origin: dk.eobjects.datacleaner/DataCleaner-core

/**
 * Convenience method to create a base query for matrix values based on a
 * specific column (where only the columns content is of interest).
 */
protected Query getBaseQuery(Column column) {
  return new Query().from(column.getTable()).select(
      new SelectItem(column)).selectCount().groupBy(column);
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }
  if (obj instanceof Query) {
    Query that = (Query) obj;
    EqualsBuilder eb = new EqualsBuilder();
    eb.append(this.getMaxRows(), that.getMaxRows());
    eb.append(this.getSelectClause(), that.getSelectClause());
    eb.append(this.getFromClause(), that.getFromClause());
    eb.append(this.getWhereClause(), that.getWhereClause());
    eb.append(this.getGroupByClause(), that.getGroupByClause());
    eb.append(this.getHavingClause(), that.getHavingClause());
    eb.append(this.getOrderByClause(), that.getOrderByClause());
    return eb.isEquals();
  }
  return false;
}

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-querypostprocessor

@Override
public DataSet materializeMainSchemaTable(Table table,
    Column[] columns, int maxRows) {
  DataContext dc = getDataContext(table);
  Query q = new Query().select(columns).from(table);
  if (maxRows >= 0) {
    q.setMaxRows(maxRows);
  }
  return dc.executeQuery(q);
}

代码示例来源:origin: dk.eobjects.datacleaner/DataCleaner-core

@Override
protected List<IMatrix> getResultMatrices() {
  ArrayList<IMatrix> result = new ArrayList<IMatrix>();
  for (int i = 0; i < _columns.length; i++) {
    Column column = _columns[i];
    Map<String, Long> valueMap = _repeatedValues.get(column);
    MatrixBuilder mb = new MatrixBuilder();
    mb.addColumn(column.getName() + " count");
    mb.addColumn(column.getName() + " %");
    for (Entry<String, Long> entry : valueMap.entrySet()) {
      Long repeatCount = entry.getValue();
      String value = entry.getKey();
      int repeatPercentage = (int) (repeatCount * 100 / _totalCount);
      if (repeatPercentage >= _significanceRate) {
        MatrixValue[] matrixValues = mb.addRow(value, repeatCount,
            repeatPercentage + "%");
        matrixValues[0].setDetailSource(new Query().from(
            column.getTable()).select(_columns).where(
            new FilterItem(new SelectItem(column),
                OperatorType.EQUALS_TO, value)));
      }
    }
    if (!mb.isEmpty()) {
      mb.sortColumn(0, MatrixBuilder.DESCENDING);
      result.add(mb.getMatrix());
    }
  }
  return result;
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

@Override
  public Query clone() {
    Query q = new Query();
    q.setMaxRows(_maxRows);
    q.getSelectClause().setDistinct(_selectClause.isDistinct());
    for (FromItem item : _fromClause.getItems()) {
      q.from(item.clone());
    }
    for (SelectItem item : _selectClause.getItems()) {
      q.select(item.clone());
    }
    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: dk.eobjects.commons/MetaModel

private long getRowCount(Query q) {
  q = q.clone();
  SelectItem countAllItem = SelectItem.getCountAllItem();
  if (q.getGroupByClause().getItemCount() > 0) {
    q = new Query().from(new FromItem(q).setAlias("sq")).select(
        countAllItem);
  } else {
    q.getSelectClause().removeItems();
    q.select(countAllItem);
  }
  Row row = MetaModelHelper.executeSingleRowQuery(_dataContext, q);
  Number count = (Number) row.getValue(countAllItem);
  return count.longValue();
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

Query q = new Query();
q.select(primaryColumns.toArray(new Column[primaryColumns.size()]));
q.select(foreignColumns.toArray(new Column[foreignColumns.size()]));
q.from(new FromItem(JoinType.LEFT, relationship));
if (_log.isDebugEnabled()) {
  _log.debug("Setting table data for '" + primaryTable.getName()
      + "' to query result: " + q.toString());

代码示例来源:origin: dk.eobjects.datacleaner/DataCleaner-core

/**
 * Convenience method to create a base query for matrix values based on the
 * configured columns (where the other columns are of interest).
 */
protected Query getBaseQuery() {
  if (_columns.length > 0) {
    Table table = _columns[0].getTable();
    Query q = new Query().select(table.getColumns()).from(table);
    return q;
  }
  return null;
}

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-jdbc

/**
 * Determines if a query is of a complex type which may be error-prone to
 * execute on some databases and therefore should be tried to execute with a
 * query postprocessing strategy
 */
private boolean isComplexQuery(Query q) {
  if (q.getWhereClause().getItemCount() > 0) {
    return true;
  }
  if (q.getGroupByClause().getItemCount() > 0) {
    return true;
  }
  if (q.getHavingClause().getItemCount() > 0) {
    return true;
  }
  if (q.getOrderByClause().getItemCount() > 0) {
    return true;
  }
  return false;
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

private List<Query> splitQueryBasedOnSubQueries(int fromItemIndex) {
  Query subQuery = _query.getFromClause().getItem(fromItemIndex)
      .getSubQuery();
  QuerySplitter subQuerySplitter = new QuerySplitter(_dataContext,
      subQuery);
  subQuerySplitter.setMaxRows(_maxRows);
  List<Query> splitQueries = subQuerySplitter.splitQuery();
  List<Query> result = new ArrayList<Query>(splitQueries.size());
  for (Query splitQuery : splitQueries) {
    Query newQuery = _query.clone();
    FromClause fromClause = newQuery.getFromClause();
    String alias = fromClause.getItem(fromItemIndex).getAlias();
    fromClause.removeItem(fromItemIndex);
    newQuery.from(new FromItem(splitQuery).setAlias(alias));
    result.add(newQuery);
  }
  return result;
}

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-querypostprocessor

if (query != null) {
  List<SelectItem> selectItems = collectSelectItems(query
      .getSelectClause().getItems(), query.getWhereClause()
      .getEvaluatedSelectItems(), query.getHavingClause()
      .getEvaluatedSelectItems());
  List<Column> colsToMaterialize = new ArrayList<Column>();

代码示例来源:origin: dk.eobjects.commons/MetaModel

@Override
protected Query beforeRewrite(JdbcDataContextStrategy strategy, Query query) {
  query = query.clone();
  if (strategy != null) {
    String identifierQuoteString = strategy.getIdentifierQuoteString();
    if (identifierQuoteString != null) {
      List<SelectItem> selectItems = query.getSelectClause()
          .getItems();
      for (SelectItem item : selectItems) {
        String alias = item.getAlias();
        if (needsQuoting(alias, identifierQuoteString)) {
          item.setAlias(identifierQuoteString + alias
              + identifierQuoteString);
        }
      }
      List<FromItem> fromItems = query.getFromClause().getItems();
      for (FromItem item : fromItems) {
        String alias = item.getAlias();
        if (needsQuoting(alias, identifierQuoteString)) {
          item.setAlias(identifierQuoteString + alias
              + identifierQuoteString);
        }
      }
    }
  }
  return query;
}

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-jdbc

private List<Column> getSplitColumns() {
  List<Column> result = new ArrayList<Column>();
  if (_query.getGroupByClause().getItemCount() != 0) {
    List<GroupByItem> groupByItems = _query.getGroupByClause()
        .getItems();
    for (GroupByItem groupByItem : groupByItems) {
    List<FromItem> fromItems = _query.getFromClause().getItems();
    for (FromItem fromItem : fromItems) {
      if (fromItem.getTable() != null) {

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-jdbc

queryString = _queryRewriter.rewriteQuery(this, query);
} else {
  queryString = query.toString();
Integer maxRows = query.getMaxRows();
if (maxRows != null) {
  try {

代码示例来源:origin: dk.eobjects.commons/MetaModel

/**
 * Examines a query and extracts an array of FromItem's that refer
 * (directly) to tables (hence Joined FromItems and SubQuery FromItems are
 * traversed but not included).
 * 
 * @param q
 *            the query to examine
 * @return
 */
public static FromItem[] getTableFromItems(Query q) {
  List<FromItem> result = new ArrayList<FromItem>();
  List<FromItem> items = q.getFromClause().getItems();
  for (FromItem item : items) {
    result.addAll(getTableFromItems(item));
  }
  return result.toArray(new FromItem[result.size()]);
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

public Query selectCount() {
  return select(SelectItem.getCountAllItem());
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

public JdbcDataSetStrategy(Query query, Statement statement,
    ResultSet resultSet) {
  if (query == null || statement == null || resultSet == null) {
    throw new IllegalArgumentException("Arguments cannot be null");
  }
  List<SelectItem> items = query.getSelectClause().getItems();
  _selectItems = items.toArray(new SelectItem[items.size()]);
  _statement = statement;
  _resultSet = resultSet;
}

代码示例来源:origin: dk.eobjects.commons/MetaModel

public static boolean isSplittable(Query q) {
  if (q.getOrderByClause().getItemCount() != 0) {
    return false;
  }
  return true;
}

代码示例来源:origin: dk.eobjects.metamodel/MetaModel-jdbc

/**
   * If the maxrows property of the query is set, then we will use MySQLs
   * LIMIT function.
   */
  @Override
  public String rewriteQuery(JdbcDataContextStrategy strategy, Query query) {
    String queryString = super.rewriteQuery(strategy, query);
    Integer maxRows = query.getMaxRows();
    if (maxRows != null && maxRows > 0) {
      queryString = queryString + " LIMIT " + maxRows;
    }
    return queryString;
  }
}

代码示例来源:origin: dk.eobjects.datacleaner/DataCleaner-core

values[1].setDetailSource(new Query().from(column.getTable())
    .select(_columns).where(
        new FilterItem(new SelectItem(column),
            OperatorType.EQUALS_TO, null)));
  values[2].setDetailSource(new Query().from(
      column.getTable()).select(_columns).where(
      new FilterItem(new SelectItem(column),
          OperatorType.EQUALS_TO, "")));

相关文章