本文整理了Java中org.h2.command.dml.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.h2.command.dml.Query
类名称:Query
[英]Represents a SELECT statement (simple, or union).
[中]表示SELECT语句(简单或联合)。
代码示例来源:origin: com.h2database/h2
@Override
public void init() {
if (SysProperties.CHECK && checkInit) {
DbException.throwInternalError();
}
checkInit = true;
left.init();
right.init();
int len = left.getColumnCount();
if (len != right.getColumnCount()) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
ArrayList<Expression> le = left.getExpressions();
// set the expressions to get the right column count and names,
// but can't validate at this time
expressions = New.arrayList();
for (int i = 0; i < len; i++) {
Expression l = le.get(i);
expressions.add(l);
}
}
代码示例来源:origin: com.h2database/h2
return q;
if (!q.allowGlobalConditions()) {
return q;
if ((mask & IndexCondition.EQUALITY) != 0) {
Parameter param = new Parameter(firstIndexParam + i);
q.addGlobalCondition(param, idx, Comparison.EQUAL_NULL_SAFE);
i++;
q.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
i++;
q.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
i++;
q.addGlobalCondition(param, idx, Comparison.SPATIAL_INTERSECTS);
i++;
String sql = q.getPlanSQL();
q = prepareSubQuery(sql, session, masks, filters, filter, sortOrder);
return q;
代码示例来源:origin: com.h2database/h2
if (isUnion()) {
return queryWithoutCacheLazyCheck(limit, target);
fireBeforeSelectTriggers();
if (noCache || !session.getDatabase().getOptimizeReuseResults() ||
session.isLazyQueryExecution()) {
return queryWithoutCacheLazyCheck(limit, target);
Value[] params = getParameterValues();
long now = session.getDatabase().getModificationDataId();
if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
if (lastResult != null && !lastResult.isClosed() &&
limit == lastLimit) {
if (sameResultAsLast(session, params, lastParameters,
lastEvaluated)) {
lastResult = lastResult.createShallowCopy(session);
closeLastResult();
ResultInterface r = queryWithoutCacheLazyCheck(limit, target);
lastResult = r;
this.lastEvaluated = now;
代码示例来源:origin: com.h2database/h2
private Expression getExpression() {
if (expression == null) {
ArrayList<Expression> expressions = query.getExpressions();
int columnCount = query.getColumnCount();
if (columnCount == 1) {
expression = expressions.get(0);
} else {
Expression[] list = new Expression[columnCount];
for (int i = 0; i < columnCount; i++) {
list[i] = expressions.get(i);
}
expression = new ExpressionList(list);
}
}
return expression;
}
代码示例来源:origin: com.h2database/h2
@Override
public Expression optimize(Session session) {
left = left.optimize(session);
query.setRandomAccessResult(true);
session.optimizeQueryExpression(query);
if (query.getColumnCount() != 1) {
throw DbException.get(ErrorCode.SUBQUERY_IS_NOT_SINGLE_COLUMN);
}
// Can not optimize: the data may change
return this;
}
代码示例来源:origin: com.eventsourcing/h2
fireBeforeSelectTriggers();
if (noCache || !session.getDatabase().getOptimizeReuseResults()) {
return queryWithoutCache(limit, target);
Value[] params = getParameterValues();
long now = session.getDatabase().getModificationDataId();
if (isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR)) {
if (lastResult != null && !lastResult.isClosed() &&
limit == lastLimit) {
if (sameResultAsLast(session, params, lastParameters,
lastEvaluated)) {
lastResult = lastResult.createShallowCopy(session);
closeLastResult();
LocalResult r = queryWithoutCache(limit, target);
lastResult = r;
this.lastEvaluated = now;
代码示例来源:origin: com.h2database/h2
try {
Query compiledQuery = compileViewQuery(session, querySQL, literalsChecked, getName());
this.querySQL = compiledQuery.getPlanSQL();
tables = new ArrayList<>(compiledQuery.getTables());
ArrayList<Expression> expressions = compiledQuery.getExpressions();
ArrayList<Column> list = New.arrayList();
ColumnNamer columnNamer = new ColumnNamer(session);
for (int i = 0, count = compiledQuery.getColumnCount(); i < count; i++) {
Expression expr = expressions.get(i);
String name = null;
代码示例来源:origin: com.h2database/h2
Query theQuery, String[] querySQLOutput) {
List<Column> columnTemplateList = new ArrayList<>();
theQuery.prepare();
querySQLOutput[0] = StringUtils.cache(theQuery.getPlanSQL());
ColumnNamer columnNamer = new ColumnNamer(theQuery.getSession());
ArrayList<Expression> withExpressions = theQuery.getExpressions();
for (int i = 0; i < withExpressions.size(); ++i) {
Expression columnExp = withExpressions.get(i);
代码示例来源:origin: com.h2database/h2
left.prepare();
right.prepare();
int len = left.getColumnCount();
ArrayList<Expression> le = left.getExpressions();
ArrayList<Expression> re = right.getExpressions();
ColumnNamer columnNamer= new ColumnNamer(session);
for (int i = 0; i < len; i++) {
代码示例来源:origin: com.h2database/h2
/**
* Create a temporary view out of the given query.
*
* @param session the session
* @param owner the owner of the query
* @param name the view name
* @param query the query
* @param topQuery the top level query
* @return the view table
*/
public static TableView createTempView(Session session, User owner,
String name, Query query, Query topQuery) {
Schema mainSchema = session.getDatabase().getSchema(Constants.SCHEMA_MAIN);
String querySQL = query.getPlanSQL();
TableView v = new TableView(mainSchema, 0, name,
querySQL, query.getParameters(), null /* column templates */, session,
false/* allow recursive */, true /* literals have already been checked when parsing original query */,
false /* is table expression */, false/* is persistent*/);
if (v.createException != null) {
throw v.createException;
}
v.setTopQuery(topQuery);
v.setOwner(owner);
v.setTemporary(true);
return v;
}
代码示例来源:origin: com.h2database/h2
query.prepare();
if (query.getColumnCount() != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
代码示例来源:origin: com.h2database/h2
private boolean sameResultAsLast(Session s, Value[] params,
Value[] lastParams, long lastEval) {
if (!cacheableChecked) {
long max = getMaxDataModificationId();
noCache = max == Long.MAX_VALUE;
cacheableChecked = true;
}
if (noCache) {
return false;
}
Database db = s.getDatabase();
for (int i = 0; i < params.length; i++) {
Value a = lastParams[i], b = params[i];
if (a.getType() != b.getType() || !db.areEqual(a, b)) {
return false;
}
}
if (!isEverything(ExpressionVisitor.DETERMINISTIC_VISITOR) ||
!isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
return false;
}
if (db.getModificationDataId() > lastEval &&
getMaxDataModificationId() > lastEval) {
return false;
}
return true;
}
代码示例来源:origin: com.h2database/com.springsource.org.h2
public LocalResult query(int limit) throws SQLException {
if (!session.getDatabase().getOptimizeReuseResults()) {
return queryWithoutCache(limit);
}
Value[] params = getParameterValues();
long now = session.getDatabase().getModificationDataId();
if (lastResult != null && !lastResult.isClosed() && limit == lastLimit) {
if (sameResultAsLast(session, params, lastParameters, lastEvaluated)) {
lastResult = lastResult.createShallowCopy(session);
if (lastResult != null) {
lastResult.reset();
return lastResult;
}
}
}
lastParameters = params;
closeLastResult();
lastResult = queryWithoutCache(limit);
this.lastEvaluated = now;
lastLimit = limit;
return lastResult;
}
代码示例来源:origin: com.h2database/com.springsource.org.h2
columns[i] = col;
int mask = masks[idx];
int nextParamIndex = query.getParameters().size();
if ((mask & IndexCondition.EQUALITY) != 0) {
Parameter param = new Parameter(nextParamIndex);
query.addGlobalCondition(param, idx, Comparison.EQUAL);
} else {
if ((mask & IndexCondition.START) != 0) {
Parameter param = new Parameter(nextParamIndex);
query.addGlobalCondition(param, idx, Comparison.BIGGER_EQUAL);
query.addGlobalCondition(param, idx, Comparison.SMALLER_EQUAL);
return 10;
String sql = query.getPlanSQL();
query = (Query) session.prepare(sql);
double cost = query.getCost();
cachedCost = new CostElement();
cachedCost.evaluatedAt = System.currentTimeMillis();
代码示例来源:origin: com.h2database/h2
@Override
public String getPlanSQL() {
return query == null ? null : query.getPlanSQL();
}
代码示例来源:origin: com.h2database/h2
@Override
public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder,
HashSet<Column> allColumnsSet) {
return recursive ? 1000 : query.getCost();
}
代码示例来源:origin: com.h2database/h2
if (sort == null && !distinct && maxRows == 0 &&
offsetExpr == null && limitExpr == null) {
left.query(0, target);
right.query(0, target);
return null;
int columnCount = left.getColumnCount();
if (session.isLazyQueryExecution() && unionType == UnionType.UNION_ALL && !distinct &&
sort == null && !randomAccessResult && !isForUpdate &&
left.setDistinct(true);
right.setDistinct(true);
result.setDistinct();
case UNION:
case EXCEPT:
left.setDistinct(true);
right.setDistinct(true);
result.setDistinct();
break;
break;
case INTERSECT:
left.setDistinct(true);
right.setDistinct(true);
break;
default:
DbException.throwInternalError("type=" + unionType);
代码示例来源:origin: com.h2database/com.springsource.org.h2
try {
Query query = recompileQuery(session);
tables = new ObjectArray(query.getTables());
ObjectArray expressions = query.getExpressions();
ObjectArray list = new ObjectArray();
for (int i = 0; i < query.getColumnCount(); i++) {
Expression expr = (Expression) expressions.get(i);
String name = null;
代码示例来源:origin: apache/ignite
/**
* @param qry Query.
* @param expCol Expression column.
* @param validate Query validation flag.
* @return {@code true} It it is an affinity column.
*/
private static boolean isAffinityColumn(Query qry, ExpressionColumn expCol, boolean validate) {
if (qry.isUnion()) {
SelectUnion union = (SelectUnion)qry;
return isAffinityColumn(union.getLeft(), expCol, validate) && isAffinityColumn(union.getRight(), expCol, validate);
}
Expression exp = qry.getExpressions().get(expCol.getColumn().getColumnId()).getNonAliasExpression();
if (exp instanceof ExpressionColumn) {
expCol = (ExpressionColumn)exp;
return isAffinityColumn(expCol.getTableFilter(), expCol, validate);
}
return false;
}
代码示例来源:origin: com.h2database/h2
public final Value[] getParameterValues() {
ArrayList<Parameter> list = getParameters();
if (list == null) {
list = New.arrayList();
}
int size = list.size();
Value[] params = new Value[size];
for (int i = 0; i < size; i++) {
Value v = list.get(i).getParamValue();
params[i] = v;
}
return params;
}
内容来源于网络,如有侵权,请联系作者删除!