本文整理了Java中org.apache.metamodel.query.Query.getFromClause
方法的一些代码示例,展示了Query.getFromClause
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getFromClause
方法的具体详情如下:
包路径:org.apache.metamodel.query.Query
类名称:Query
方法名:getFromClause
暂无
代码示例来源:origin: org.apache.metamodel/MetaModel-core
/**
* 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 an array of FromItem's that refer directly to tables
*/
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: apache/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 an array of FromItem's that refer directly to tables
*/
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: apache/metamodel
private Integer getSubQueryFromItemIndex() {
List<FromItem> fromItems = _query.getFromClause().getItems();
for (int i = 0; i < fromItems.size(); i++) {
Query subQuery = fromItems.get(i).getSubQuery();
if (subQuery != null) {
if (isSplittable(subQuery)) {
return i;
}
}
}
return null;
}
代码示例来源:origin: org.apache.metamodel/MetaModel-core
/**
* Select all available select items from all currently available FROM
* items. Equivalent of the expression "SELECT * FROM ..." in SQL.
*
* @return
*/
public Query selectAll() {
List<FromItem> items = getFromClause().getItems();
for (FromItem fromItem : items) {
selectAll(fromItem);
}
return this;
}
代码示例来源:origin: org.apache.metamodel/MetaModel-jdbc
private Integer getSubQueryFromItemIndex() {
List<FromItem> fromItems = _query.getFromClause().getItems();
for (int i = 0; i < fromItems.size(); i++) {
Query subQuery = fromItems.get(i).getSubQuery();
if (subQuery != null) {
if (isSplittable(subQuery)) {
return i;
}
}
}
return null;
}
代码示例来源:origin: apache/metamodel
/**
* Select all available select items from all currently available FROM
* items. Equivalent of the expression "SELECT * FROM ..." in SQL.
*
* @return
*/
public Query selectAll() {
List<FromItem> items = getFromClause().getItems();
for (FromItem fromItem : items) {
selectAll(fromItem);
}
return this;
}
代码示例来源:origin: apache/metamodel
private void replaceParametersInFromClause(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
Query newQuery) {
final List<FromItem> fromItems = originalQuery.getFromClause().getItems();
int i = 0;
for (FromItem fromItem : fromItems) {
final Query subQuery = fromItem.getSubQuery();
if (subQuery != null) {
final Query newSubQuery = newQuery.getFromClause().getItem(i).getSubQuery();
replaceParametersInQuery(values, parameterIndex, subQuery, newSubQuery);
newQuery.getFromClause().removeItem(i);
newQuery.getFromClause().addItem(i, new FromItem(newSubQuery).setAlias(fromItem.getAlias()));
}
i++;
}
}
代码示例来源:origin: org.apache.metamodel/MetaModel-core
private void replaceParametersInFromClause(Object[] values, AtomicInteger parameterIndex, Query originalQuery,
Query newQuery) {
final List<FromItem> fromItems = originalQuery.getFromClause().getItems();
int i = 0;
for (FromItem fromItem : fromItems) {
final Query subQuery = fromItem.getSubQuery();
if (subQuery != null) {
final Query newSubQuery = newQuery.getFromClause().getItem(i).getSubQuery();
replaceParametersInQuery(values, parameterIndex, subQuery, newSubQuery);
newQuery.getFromClause().removeItem(i);
newQuery.getFromClause().addItem(i, new FromItem(newSubQuery).setAlias(fromItem.getAlias()));
}
i++;
}
}
代码示例来源:origin: apache/metamodel
public String rewriteQuery(Query query) {
query = beforeRewrite(query);
final StringBuilder sb = new StringBuilder();
sb.append(rewriteSelectClause(query, query.getSelectClause()));
sb.append(rewriteFromClause(query, query.getFromClause()));
sb.append(rewriteWhereClause(query, query.getWhereClause()));
sb.append(rewriteGroupByClause(query, query.getGroupByClause()));
sb.append(rewriteHavingClause(query, query.getHavingClause()));
sb.append(rewriteOrderByClause(query, query.getOrderByClause()));
return sb.toString();
}
代码示例来源:origin: org.apache.metamodel/MetaModel-jdbc
public String rewriteQuery(Query query) {
query = beforeRewrite(query);
final StringBuilder sb = new StringBuilder();
sb.append(rewriteSelectClause(query, query.getSelectClause()));
sb.append(rewriteFromClause(query, query.getFromClause()));
sb.append(rewriteWhereClause(query, query.getWhereClause()));
sb.append(rewriteGroupByClause(query, query.getGroupByClause()));
sb.append(rewriteHavingClause(query, query.getHavingClause()));
sb.append(rewriteOrderByClause(query, query.getOrderByClause()));
return sb.toString();
}
代码示例来源:origin: org.apache.metamodel/MetaModel-core
private void buildParameterListInFromClause(List<QueryParameter> parameters, Query query) {
List<FromItem> fromItems = query.getFromClause().getItems();
for (FromItem fromItem : fromItems) {
Query subQuery = fromItem.getSubQuery();
if (subQuery != null) {
buildParameterListInFromClause(parameters, subQuery);
buildParameterListInWhereClause(parameters, subQuery);
}
}
}
代码示例来源:origin: apache/metamodel
private void buildParameterListInFromClause(List<QueryParameter> parameters, Query query) {
List<FromItem> fromItems = query.getFromClause().getItems();
for (FromItem fromItem : fromItems) {
Query subQuery = fromItem.getSubQuery();
if (subQuery != null) {
buildParameterListInFromClause(parameters, subQuery);
buildParameterListInWhereClause(parameters, subQuery);
}
}
}
代码示例来源:origin: apache/metamodel
/**
* Creates a clone of the {@link SelectItem} for use within a cloned {@link Query}.
*
* @param clonedQuery a new {@link Query} object that represents the clone-to-be of a query. It is expected that
* {@link FromItem}s have already been cloned in this {@link Query}.
* @return
*/
protected SelectItem clone(Query clonedQuery) {
final SelectItem subQuerySelectItem = (_subQuerySelectItem == null ? null : _subQuerySelectItem.clone());
final FromItem fromItem;
if (_fromItem == null) {
fromItem = null;
} else if (clonedQuery != null && _query != null) {
final int indexOfFromItem = _query.getFromClause().indexOf(_fromItem);
if (indexOfFromItem != -1) {
fromItem = clonedQuery.getFromClause().getItem(indexOfFromItem);
} else {
fromItem = _fromItem.clone();
}
} else {
fromItem = _fromItem.clone();
}
final SelectItem s = new SelectItem(_column, fromItem, _function, _functionParameters, _expression,
subQuerySelectItem, _alias, _functionApproximationAllowed);
return s;
}
代码示例来源:origin: org.apache.metamodel/MetaModel-core
/**
* Creates a clone of the {@link SelectItem} for use within a cloned {@link Query}.
*
* @param clonedQuery a new {@link Query} object that represents the clone-to-be of a query. It is expected that
* {@link FromItem}s have already been cloned in this {@link Query}.
* @return
*/
protected SelectItem clone(Query clonedQuery) {
final SelectItem subQuerySelectItem = (_subQuerySelectItem == null ? null : _subQuerySelectItem.clone());
final FromItem fromItem;
if (_fromItem == null) {
fromItem = null;
} else if (clonedQuery != null && _query != null) {
final int indexOfFromItem = _query.getFromClause().indexOf(_fromItem);
if (indexOfFromItem != -1) {
fromItem = clonedQuery.getFromClause().getItem(indexOfFromItem);
} else {
fromItem = _fromItem.clone();
}
} else {
fromItem = _fromItem.clone();
}
final SelectItem s = new SelectItem(_column, fromItem, _function, _functionParameters, _expression,
subQuerySelectItem, _alias, _functionApproximationAllowed);
return s;
}
代码示例来源:origin: org.apache.metamodel/MetaModel-core
@Override
public SatisfiedFromBuilder on(Column left, Column right) throws IllegalArgumentException {
if (left == null) {
throw new IllegalArgumentException("left cannot be null");
}
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;
}
代码示例来源:origin: org.apache.metamodel/MetaModel-jdbc
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: apache/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: apache/metamodel
@Override
public SatisfiedFromBuilder on(Column left, Column right) throws IllegalArgumentException {
if (left == null) {
throw new IllegalArgumentException("left cannot be null");
}
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;
}
代码示例来源:origin: apache/metamodel
@Override
protected Query beforeRewrite(Query query) {
query = query.clone();
JdbcDataContext dataContext = getDataContext();
if (dataContext != null) {
String identifierQuoteString = dataContext.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: org.apache.metamodel/MetaModel-jdbc
@Override
protected Query beforeRewrite(Query query) {
query = query.clone();
JdbcDataContext dataContext = getDataContext();
if (dataContext != null) {
String identifierQuoteString = dataContext.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;
}
内容来源于网络,如有侵权,请联系作者删除!