提交 b82d4ff0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Change return type of Value.getBoolean() to boolean (unwrapped)

上级 c27bcf5a
...@@ -3390,7 +3390,7 @@ public class Parser { ...@@ -3390,7 +3390,7 @@ public class Parser {
private boolean readBooleanSetting() { private boolean readBooleanSetting() {
if (currentTokenType == VALUE) { if (currentTokenType == VALUE) {
boolean result = currentValue.getBoolean().booleanValue(); boolean result = currentValue.getBoolean();
read(); read();
return result; return result;
} }
......
...@@ -78,8 +78,7 @@ public class Delete extends Prepared { ...@@ -78,8 +78,7 @@ public class Delete extends Prepared {
int count = 0; int count = 0;
while (limitRows != 0 && targetTableFilter.next()) { while (limitRows != 0 && targetTableFilter.next()) {
setCurrentRowNumber(rows.size() + 1); setCurrentRowNumber(rows.size() + 1);
if (condition == null || Boolean.TRUE.equals( if (condition == null || condition.getBooleanValue(session)) {
condition.getBooleanValue(session))) {
Row row = targetTableFilter.get(); Row row = targetTableFilter.get();
boolean done = false; boolean done = false;
if (table.fireRow()) { if (table.fireRow()) {
......
...@@ -195,13 +195,7 @@ public class Select extends Query { ...@@ -195,13 +195,7 @@ public class Select extends Query {
private boolean isHavingNullOrFalse(Value[] row) { private boolean isHavingNullOrFalse(Value[] row) {
if (havingIndex >= 0) { if (havingIndex >= 0) {
Value v = row[havingIndex]; return !row[havingIndex].getBoolean();
if (v == ValueNull.INSTANCE) {
return true;
}
if (!Boolean.TRUE.equals(v.getBoolean())) {
return true;
}
} }
return false; return false;
} }
...@@ -281,8 +275,7 @@ public class Select extends Query { ...@@ -281,8 +275,7 @@ public class Select extends Query {
} }
boolean isConditionMet() { boolean isConditionMet() {
return condition == null || return condition == null || condition.getBooleanValue(session);
Boolean.TRUE.equals(condition.getBooleanValue(session));
} }
private void queryGroup(int columnCount, LocalResult result) { private void queryGroup(int columnCount, LocalResult result) {
......
...@@ -112,8 +112,7 @@ public class Update extends Prepared { ...@@ -112,8 +112,7 @@ public class Update extends Prepared {
if (limitRows >= 0 && count >= limitRows) { if (limitRows >= 0 && count >= limitRows) {
break; break;
} }
if (condition == null || if (condition == null || condition.getBooleanValue(session)) {
Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row oldRow = targetTableFilter.get(); Row oldRow = targetTableFilter.get();
Row newRow = table.getTemplateRow(); Row newRow = table.getTemplateRow();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
......
...@@ -20,6 +20,8 @@ import org.h2.table.Column; ...@@ -20,6 +20,8 @@ import org.h2.table.Column;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.value.Value;
import org.h2.value.ValueNull;
/** /**
* A check constraint. * A check constraint.
...@@ -92,15 +94,16 @@ public class ConstraintCheck extends Constraint { ...@@ -92,15 +94,16 @@ public class ConstraintCheck extends Constraint {
return; return;
} }
filter.set(newRow); filter.set(newRow);
Boolean b; boolean b;
try { try {
b = expr.getValue(session).getBoolean(); Value v = expr.getValue(session);
b = v == ValueNull.INSTANCE || v.getBoolean();
} catch (DbException ex) { } catch (DbException ex) {
throw DbException.get(ErrorCode.CHECK_CONSTRAINT_INVALID, ex, throw DbException.get(ErrorCode.CHECK_CONSTRAINT_INVALID, ex,
getShortDescription()); getShortDescription());
} }
// Both TRUE and NULL are ok // Both TRUE and NULL are ok
if (Boolean.FALSE.equals(b)) { if (!b) {
throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1,
getShortDescription()); getShortDescription());
} }
......
...@@ -95,8 +95,7 @@ class AggregateDataDefault extends AggregateData { ...@@ -95,8 +95,7 @@ class AggregateDataDefault extends AggregateData {
if (value == null) { if (value == null) {
value = v; value = v;
} else { } else {
value = ValueBoolean.get(value.getBoolean().booleanValue() && value = ValueBoolean.get(value.getBoolean() && v.getBoolean());
v.getBoolean().booleanValue());
} }
break; break;
case Aggregate.BOOL_OR: case Aggregate.BOOL_OR:
...@@ -104,8 +103,7 @@ class AggregateDataDefault extends AggregateData { ...@@ -104,8 +103,7 @@ class AggregateDataDefault extends AggregateData {
if (value == null) { if (value == null) {
value = v; value = v;
} else { } else {
value = ValueBoolean.get(value.getBoolean().booleanValue() || value = ValueBoolean.get(value.getBoolean() || v.getBoolean());
v.getBoolean().booleanValue());
} }
break; break;
case Aggregate.BIT_AND: case Aggregate.BIT_AND:
......
...@@ -87,11 +87,11 @@ public class ConditionAndOr extends Condition { ...@@ -87,11 +87,11 @@ public class ConditionAndOr extends Condition {
Value r; Value r;
switch (andOrType) { switch (andOrType) {
case AND: { case AND: {
if (Boolean.FALSE.equals(l.getBoolean())) { if (l != ValueNull.INSTANCE && !l.getBoolean()) {
return l; return l;
} }
r = right.getValue(session); r = right.getValue(session);
if (Boolean.FALSE.equals(r.getBoolean())) { if (r != ValueNull.INSTANCE && !r.getBoolean()) {
return r; return r;
} }
if (l == ValueNull.INSTANCE) { if (l == ValueNull.INSTANCE) {
...@@ -103,11 +103,11 @@ public class ConditionAndOr extends Condition { ...@@ -103,11 +103,11 @@ public class ConditionAndOr extends Condition {
return ValueBoolean.get(true); return ValueBoolean.get(true);
} }
case OR: { case OR: {
if (Boolean.TRUE.equals(l.getBoolean())) { if (l.getBoolean()) {
return l; return l;
} }
r = right.getValue(session); r = right.getValue(session);
if (Boolean.TRUE.equals(r.getBoolean())) { if (r.getBoolean()) {
return r; return r;
} }
if (l == ValueNull.INSTANCE) { if (l == ValueNull.INSTANCE) {
...@@ -212,30 +212,30 @@ public class ConditionAndOr extends Condition { ...@@ -212,30 +212,30 @@ public class ConditionAndOr extends Condition {
switch (andOrType) { switch (andOrType) {
case AND: case AND:
if (l != null) { if (l != null) {
if (Boolean.FALSE.equals(l.getBoolean())) { if (l != ValueNull.INSTANCE && !l.getBoolean()) {
return ValueExpression.get(l); return ValueExpression.get(l);
} else if (Boolean.TRUE.equals(l.getBoolean())) { } else if (l.getBoolean()) {
return right; return right;
} }
} else if (r != null) { } else if (r != null) {
if (Boolean.FALSE.equals(r.getBoolean())) { if (r != ValueNull.INSTANCE && !r.getBoolean()) {
return ValueExpression.get(r); return ValueExpression.get(r);
} else if (Boolean.TRUE.equals(r.getBoolean())) { } else if (r.getBoolean()) {
return left; return left;
} }
} }
break; break;
case OR: case OR:
if (l != null) { if (l != null) {
if (Boolean.TRUE.equals(l.getBoolean())) { if (l.getBoolean()) {
return ValueExpression.get(l); return ValueExpression.get(l);
} else if (Boolean.FALSE.equals(l.getBoolean())) { } else if (l != ValueNull.INSTANCE) {
return right; return right;
} }
} else if (r != null) { } else if (r != null) {
if (Boolean.TRUE.equals(r.getBoolean())) { if (r.getBoolean()) {
return ValueExpression.get(r); return ValueExpression.get(r);
} else if (Boolean.FALSE.equals(r.getBoolean())) { } else if (r != ValueNull.INSTANCE) {
return left; return left;
} }
} }
......
...@@ -168,13 +168,13 @@ public abstract class Expression { ...@@ -168,13 +168,13 @@ public abstract class Expression {
/** /**
* Get the value in form of a boolean expression. * Get the value in form of a boolean expression.
* Returns true, false, or null. * Returns true or false.
* In this database, everything can be a condition. * In this database, everything can be a condition.
* *
* @param session the session * @param session the session
* @return the result * @return the result
*/ */
public Boolean getBooleanValue(Session session) { public boolean getBooleanValue(Session session) {
return getValue(session).getBoolean(); return getValue(session).getBoolean();
} }
......
...@@ -989,8 +989,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -989,8 +989,7 @@ public class Function extends Expression implements FunctionCall {
} }
case CASEWHEN: { case CASEWHEN: {
Value v; Value v;
if (v0 == ValueNull.INSTANCE || if (!v0.getBoolean()) {
!v0.getBoolean().booleanValue()) {
v = getNullOrValue(session, args, values, 2); v = getNullOrValue(session, args, values, 2);
} else { } else {
v = getNullOrValue(session, args, values, 1); v = getNullOrValue(session, args, values, 1);
...@@ -1067,8 +1066,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1067,8 +1066,7 @@ public class Function extends Expression implements FunctionCall {
// (null, when, then, when, then, else) // (null, when, then, when, then, else)
for (int i = 1, len = args.length - 1; i < len; i += 2) { for (int i = 1, len = args.length - 1; i < len; i += 2) {
Value when = args[i].getValue(session); Value when = args[i].getValue(session);
if (!(when == ValueNull.INSTANCE) && if (when.getBoolean()) {
when.getBoolean().booleanValue()) {
then = args[i + 1]; then = args[i + 1];
break; break;
} }
......
...@@ -81,7 +81,7 @@ public class ValueExpression extends Expression { ...@@ -81,7 +81,7 @@ public class ValueExpression extends Expression {
@Override @Override
public void createIndexConditions(Session session, TableFilter filter) { public void createIndexConditions(Session session, TableFilter filter) {
if (value.getType() == Value.BOOLEAN) { if (value.getType() == Value.BOOLEAN) {
boolean v = ((ValueBoolean) value).getBoolean().booleanValue(); boolean v = ((ValueBoolean) value).getBoolean();
if (!v) { if (!v) {
filter.addIndexCondition(IndexCondition.get(Comparison.FALSE, null, this)); filter.addIndexCondition(IndexCondition.get(Comparison.FALSE, null, this));
} }
......
...@@ -586,9 +586,7 @@ public class JdbcConnection extends TraceObject ...@@ -586,9 +586,7 @@ public class JdbcConnection extends TraceObject
getReadOnly = prepareCommand("CALL READONLY()", getReadOnly); getReadOnly = prepareCommand("CALL READONLY()", getReadOnly);
ResultInterface result = getReadOnly.executeQuery(0, false); ResultInterface result = getReadOnly.executeQuery(0, false);
result.next(); result.next();
boolean readOnly = result.currentRow()[0].getBoolean() return result.currentRow()[0].getBoolean();
.booleanValue();
return readOnly;
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
...@@ -548,8 +548,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -548,8 +548,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public boolean getBoolean(int columnIndex) throws SQLException { public boolean getBoolean(int columnIndex) throws SQLException {
try { try {
debugCodeCall("getBoolean", columnIndex); debugCodeCall("getBoolean", columnIndex);
Boolean v = get(columnIndex).getBoolean(); return get(columnIndex).getBoolean();
return v == null ? false : v.booleanValue();
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
...@@ -567,8 +566,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS ...@@ -567,8 +566,7 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
public boolean getBoolean(String columnLabel) throws SQLException { public boolean getBoolean(String columnLabel) throws SQLException {
try { try {
debugCodeCall("getBoolean", columnLabel); debugCodeCall("getBoolean", columnLabel);
Boolean v = get(columnLabel).getBoolean(); return get(columnLabel).getBoolean();
return v == null ? false : v.booleanValue();
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
} }
......
...@@ -192,8 +192,7 @@ public class ValueDataType implements DataType { ...@@ -192,8 +192,7 @@ public class ValueDataType implements DataType {
int type = v.getType(); int type = v.getType();
switch (type) { switch (type) {
case Value.BOOLEAN: case Value.BOOLEAN:
buff.put((byte) (v.getBoolean().booleanValue() ? buff.put((byte) (v.getBoolean() ? BOOLEAN_TRUE : BOOLEAN_FALSE));
BOOLEAN_TRUE : BOOLEAN_FALSE));
break; break;
case Value.BYTE: case Value.BYTE:
buff.put((byte) type).put(v.getByte()); buff.put((byte) type).put(v.getByte());
......
...@@ -418,8 +418,7 @@ public class Data { ...@@ -418,8 +418,7 @@ public class Data {
int type = v.getType(); int type = v.getType();
switch (type) { switch (type) {
case Value.BOOLEAN: case Value.BOOLEAN:
writeByte((byte) (v.getBoolean().booleanValue() ? writeByte((byte) (v.getBoolean() ? BOOLEAN_TRUE : BOOLEAN_FALSE));
BOOLEAN_TRUE : BOOLEAN_FALSE));
break; break;
case Value.BYTE: case Value.BYTE:
writeByte((byte) type); writeByte((byte) type);
......
...@@ -362,7 +362,7 @@ public class Column { ...@@ -362,7 +362,7 @@ public class Column {
v = checkConstraint.getValue(session); v = checkConstraint.getValue(session);
} }
// Both TRUE and NULL are ok // Both TRUE and NULL are ok
if (Boolean.FALSE.equals(v.getBoolean())) { if (v != ValueNull.INSTANCE && !v.getBoolean()) {
throw DbException.get( throw DbException.get(
ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, ErrorCode.CHECK_CONSTRAINT_VIOLATED_1,
checkConstraint.getSQL()); checkConstraint.getSQL());
......
...@@ -577,10 +577,7 @@ public class TableFilter implements ColumnResolver { ...@@ -577,10 +577,7 @@ public class TableFilter implements ColumnResolver {
* @return true if yes * @return true if yes
*/ */
boolean isOk(Expression condition) { boolean isOk(Expression condition) {
if (condition == null) { return condition == null || condition.getBooleanValue(session);
return true;
}
return Boolean.TRUE.equals(condition.getBooleanValue(session));
} }
/** /**
......
...@@ -342,7 +342,7 @@ public class Transfer { ...@@ -342,7 +342,7 @@ public class Transfer {
break; break;
} }
case Value.BOOLEAN: case Value.BOOLEAN:
writeBoolean(v.getBoolean().booleanValue()); writeBoolean(v.getBoolean());
break; break;
case Value.BYTE: case Value.BYTE:
writeByte(v.getByte()); writeByte(v.getByte());
......
...@@ -423,7 +423,7 @@ public abstract class Value { ...@@ -423,7 +423,7 @@ public abstract class Value {
softCache = null; softCache = null;
} }
public Boolean getBoolean() { public boolean getBoolean() {
return ((ValueBoolean) convertTo(Value.BOOLEAN)).getBoolean(); return ((ValueBoolean) convertTo(Value.BOOLEAN)).getBoolean();
} }
...@@ -630,7 +630,7 @@ public abstract class Value { ...@@ -630,7 +630,7 @@ public abstract class Value {
case BYTE: { case BYTE: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueByte.get(getBoolean().booleanValue() ? (byte) 1 : (byte) 0); return ValueByte.get(getBoolean() ? (byte) 1 : (byte) 0);
case SHORT: case SHORT:
return ValueByte.get(convertToByte(getShort(), column)); return ValueByte.get(convertToByte(getShort(), column));
case ENUM: case ENUM:
...@@ -655,7 +655,7 @@ public abstract class Value { ...@@ -655,7 +655,7 @@ public abstract class Value {
case SHORT: { case SHORT: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueShort.get(getBoolean().booleanValue() ? (short) 1 : (short) 0); return ValueShort.get(getBoolean() ? (short) 1 : (short) 0);
case BYTE: case BYTE:
return ValueShort.get(getByte()); return ValueShort.get(getByte());
case ENUM: case ENUM:
...@@ -680,7 +680,7 @@ public abstract class Value { ...@@ -680,7 +680,7 @@ public abstract class Value {
case INT: { case INT: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueInt.get(getBoolean().booleanValue() ? 1 : 0); return ValueInt.get(getBoolean() ? 1 : 0);
case BYTE: case BYTE:
return ValueInt.get(getByte()); return ValueInt.get(getByte());
case ENUM: case ENUM:
...@@ -706,7 +706,7 @@ public abstract class Value { ...@@ -706,7 +706,7 @@ public abstract class Value {
case LONG: { case LONG: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueLong.get(getBoolean().booleanValue() ? 1 : 0); return ValueLong.get(getBoolean() ? 1 : 0);
case BYTE: case BYTE:
return ValueLong.get(getByte()); return ValueLong.get(getByte());
case SHORT: case SHORT:
...@@ -737,8 +737,7 @@ public abstract class Value { ...@@ -737,8 +737,7 @@ public abstract class Value {
case DECIMAL: { case DECIMAL: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueDecimal.get(BigDecimal.valueOf( return ValueDecimal.get(BigDecimal.valueOf(getBoolean() ? 1 : 0));
getBoolean().booleanValue() ? 1 : 0));
case BYTE: case BYTE:
return ValueDecimal.get(BigDecimal.valueOf(getByte())); return ValueDecimal.get(BigDecimal.valueOf(getByte()));
case SHORT: case SHORT:
...@@ -774,7 +773,7 @@ public abstract class Value { ...@@ -774,7 +773,7 @@ public abstract class Value {
case DOUBLE: { case DOUBLE: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueDouble.get(getBoolean().booleanValue() ? 1 : 0); return ValueDouble.get(getBoolean() ? 1 : 0);
case BYTE: case BYTE:
return ValueDouble.get(getByte()); return ValueDouble.get(getByte());
case SHORT: case SHORT:
...@@ -797,7 +796,7 @@ public abstract class Value { ...@@ -797,7 +796,7 @@ public abstract class Value {
case FLOAT: { case FLOAT: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueFloat.get(getBoolean().booleanValue() ? 1 : 0); return ValueFloat.get(getBoolean() ? 1 : 0);
case BYTE: case BYTE:
return ValueFloat.get(getByte()); return ValueFloat.get(getByte());
case SHORT: case SHORT:
......
...@@ -30,10 +30,10 @@ public class ValueBoolean extends Value { ...@@ -30,10 +30,10 @@ public class ValueBoolean extends Value {
private static final Object TRUE = new ValueBoolean(true); private static final Object TRUE = new ValueBoolean(true);
private static final Object FALSE = new ValueBoolean(false); private static final Object FALSE = new ValueBoolean(false);
private final Boolean value; private final boolean value;
private ValueBoolean(boolean value) { private ValueBoolean(boolean value) {
this.value = Boolean.valueOf(value); this.value = value;
} }
@Override @Override
...@@ -48,24 +48,23 @@ public class ValueBoolean extends Value { ...@@ -48,24 +48,23 @@ public class ValueBoolean extends Value {
@Override @Override
public String getString() { public String getString() {
return value.booleanValue() ? "TRUE" : "FALSE"; return value ? "TRUE" : "FALSE";
} }
@Override @Override
public Value negate() { public Value negate() {
return (ValueBoolean) (value.booleanValue() ? FALSE : TRUE); return (ValueBoolean) (value ? FALSE : TRUE);
} }
@Override @Override
public Boolean getBoolean() { public boolean getBoolean() {
return value; return value;
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { protected int compareSecure(Value o, CompareMode mode) {
boolean v2 = ((ValueBoolean) o).value.booleanValue(); ValueBoolean v = (ValueBoolean) o;
boolean v = value.booleanValue(); return Boolean.compare(value, v.value);
return (v == v2) ? 0 : (v ? 1 : -1);
} }
@Override @Override
...@@ -75,7 +74,7 @@ public class ValueBoolean extends Value { ...@@ -75,7 +74,7 @@ public class ValueBoolean extends Value {
@Override @Override
public int hashCode() { public int hashCode() {
return value.booleanValue() ? 1 : 0; return value ? 1 : 0;
} }
@Override @Override
...@@ -86,7 +85,7 @@ public class ValueBoolean extends Value { ...@@ -86,7 +85,7 @@ public class ValueBoolean extends Value {
@Override @Override
public void set(PreparedStatement prep, int parameterIndex) public void set(PreparedStatement prep, int parameterIndex)
throws SQLException { throws SQLException {
prep.setBoolean(parameterIndex, value.booleanValue()); prep.setBoolean(parameterIndex, value);
} }
/** /**
......
...@@ -63,8 +63,8 @@ public class ValueNull extends Value { ...@@ -63,8 +63,8 @@ public class ValueNull extends Value {
} }
@Override @Override
public Boolean getBoolean() { public boolean getBoolean() {
return null; return false;
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论