本文整理了Java中dk.eobjects.metamodel.query.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:dk.eobjects.metamodel.query.Query
类名称:Query
[英]Represents a query to retrieve data by. A query is made up of six clauses, equivalent to the SQL standard:
代码示例来源: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, "")));
内容来源于网络,如有侵权,请联系作者删除!