提交 7387be71 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

add toString() for debugging purposes

上级 54efc692
/* /*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, and the
* and the EPL 1.0 (http://h2database.com/html/license.html). * EPL 1.0 (http://h2database.com/html/license.html). Initial Developer: H2
* Initial Developer: H2 Group * Group
*/ */
package org.h2.index; package org.h2.index;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -110,7 +111,8 @@ public class IndexCondition { ...@@ -110,7 +111,8 @@ public class IndexCondition {
*/ */
public static IndexCondition getInList(ExpressionColumn column, public static IndexCondition getInList(ExpressionColumn column,
List<Expression> list) { List<Expression> list) {
IndexCondition cond = new IndexCondition(Comparison.IN_LIST, column, null); IndexCondition cond = new IndexCondition(Comparison.IN_LIST, column,
null);
cond.expressionList = list; cond.expressionList = list;
return cond; return cond;
} }
...@@ -124,7 +126,8 @@ public class IndexCondition { ...@@ -124,7 +126,8 @@ public class IndexCondition {
* @return the index condition * @return the index condition
*/ */
public static IndexCondition getInQuery(ExpressionColumn column, Query query) { public static IndexCondition getInQuery(ExpressionColumn column, Query query) {
IndexCondition cond = new IndexCondition(Comparison.IN_QUERY, column, null); IndexCondition cond = new IndexCondition(Comparison.IN_QUERY, column,
null);
cond.expressionQuery = query; cond.expressionQuery = query;
return cond; return cond;
} }
...@@ -186,7 +189,7 @@ public class IndexCondition { ...@@ -186,7 +189,7 @@ public class IndexCondition {
} }
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
buff.append(column.getSQL()); buff.append(column.getSQL());
switch(compareType) { switch (compareType) {
case Comparison.EQUAL: case Comparison.EQUAL:
buff.append(" = "); buff.append(" = ");
break; break;
...@@ -222,7 +225,7 @@ public class IndexCondition { ...@@ -222,7 +225,7 @@ public class IndexCondition {
buff.append(" && "); buff.append(" && ");
break; break;
default: default:
DbException.throwInternalError("type="+compareType); DbException.throwInternalError("type=" + compareType);
} }
if (expression != null) { if (expression != null) {
buff.append(expression.getSQL()); buff.append(expression.getSQL());
...@@ -335,8 +338,7 @@ public class IndexCondition { ...@@ -335,8 +338,7 @@ public class IndexCondition {
/** /**
* Check if this index condition is of the type equality. * Check if this index condition is of the type equality.
* *
* @param constantExpression if the inner node * @param constantExpression if the inner node is a constant expression
* is a constant expression
* @return true if this is a equality condition * @return true if this is a equality condition
*/ */
public boolean isEquality(boolean constantExpression) { public boolean isEquality(boolean constantExpression) {
...@@ -369,7 +371,8 @@ public class IndexCondition { ...@@ -369,7 +371,8 @@ public class IndexCondition {
*/ */
public boolean isEvaluatable() { public boolean isEvaluatable() {
if (expression != null) { if (expression != null) {
return expression.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR); return expression
.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR);
} }
if (expressionList != null) { if (expressionList != null) {
for (Expression e : expressionList) { for (Expression e : expressionList) {
...@@ -379,7 +382,43 @@ public class IndexCondition { ...@@ -379,7 +382,43 @@ public class IndexCondition {
} }
return true; return true;
} }
return expressionQuery.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR); return expressionQuery
.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR);
}
/**
* for display in the debugger
*/
public String toString() {
return "column=" + column + ", compareType="
+ compareTypeToString(compareType) + ", expression="
+ expression + ", expressionList=" + expressionList.toString()
+ ", expressionQuery=" + expressionQuery;
}
private static String compareTypeToString(int i) {
StatementBuilder s = new StatementBuilder();
if ((i & EQUALITY) == EQUALITY) {
s.appendExceptFirst("&");
s.append("EQUALITY");
}
if ((i & START) == START) {
s.appendExceptFirst("&");
s.append("START");
}
if ((i & END) == END) {
s.appendExceptFirst("&");
s.append("END");
}
if ((i & ALWAYS_FALSE) == ALWAYS_FALSE) {
s.appendExceptFirst("&");
s.append("ALWAYS_FALSE");
}
if ((i & SPATIAL_INTERSECTS) == SPATIAL_INTERSECTS) {
s.appendExceptFirst("&");
s.append("SPATIAL_INTERSECTS");
}
return s.toString();
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论