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

Merge compareTypeSafe() and compareSecure() methods of Value

上级 ad92b287
...@@ -265,16 +265,6 @@ public abstract class Value { ...@@ -265,16 +265,6 @@ public abstract class Value {
public abstract void set(PreparedStatement prep, int parameterIndex) public abstract void set(PreparedStatement prep, int parameterIndex)
throws SQLException; throws SQLException;
/**
* Compare the value with another value of the same type.
*
* @param v the other value
* @param mode the compare mode
* @return 0 if both values are equal, -1 if the other value is smaller, and
* 1 otherwise
*/
protected abstract int compareSecure(Value v, CompareMode mode);
@Override @Override
public abstract int hashCode(); public abstract int hashCode();
...@@ -1157,9 +1147,7 @@ public abstract class Value { ...@@ -1157,9 +1147,7 @@ public abstract class Value {
* @return 0 if both values are equal, -1 if the other value is smaller, and * @return 0 if both values are equal, -1 if the other value is smaller, and
* 1 otherwise * 1 otherwise
*/ */
public final int compareTypeSafe(Value v, CompareMode mode) { public abstract int compareTypeSafe(Value v, CompareMode mode);
return compareSecure(v, mode);
}
/** /**
* Compare this value against another value using the specified compare * Compare this value against another value using the specified compare
...@@ -1194,7 +1182,7 @@ public abstract class Value { ...@@ -1194,7 +1182,7 @@ public abstract class Value {
v = v.convertTo(dataType, databaseMode); v = v.convertTo(dataType, databaseMode);
} }
} }
return l.compareSecure(v, compareMode); return l.compareTypeSafe(v, compareMode);
} }
public int getScale() { public int getScale() {
......
...@@ -11,7 +11,6 @@ import java.sql.SQLException; ...@@ -11,7 +11,6 @@ import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Mode;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
...@@ -99,7 +98,7 @@ public class ValueArray extends Value { ...@@ -99,7 +98,7 @@ public class ValueArray extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueArray v = (ValueArray) o; ValueArray v = (ValueArray) o;
if (values == v.values) { if (values == v.values) {
return 0; return 0;
......
...@@ -66,9 +66,8 @@ public class ValueBoolean extends Value { ...@@ -66,9 +66,8 @@ public class ValueBoolean extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueBoolean v = (ValueBoolean) o; return Boolean.compare(value, ((ValueBoolean) o).value);
return Boolean.compare(value, v.value);
} }
@Override @Override
......
...@@ -108,9 +108,8 @@ public class ValueByte extends Value { ...@@ -108,9 +108,8 @@ public class ValueByte extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueByte v = (ValueByte) o; return Integer.compare(value, ((ValueByte) o).value);
return Integer.compare(value, v.value);
} }
@Override @Override
......
...@@ -94,7 +94,7 @@ public class ValueBytes extends Value { ...@@ -94,7 +94,7 @@ public class ValueBytes extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
byte[] v2 = ((ValueBytes) v).value; byte[] v2 = ((ValueBytes) v).value;
if (mode.isBinaryUnsigned()) { if (mode.isBinaryUnsigned()) {
return Bits.compareNotNullUnsigned(value, v2); return Bits.compareNotNullUnsigned(value, v2);
......
...@@ -113,7 +113,7 @@ public class ValueDate extends Value { ...@@ -113,7 +113,7 @@ public class ValueDate extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
return Long.compare(dateValue, ((ValueDate) o).dateValue); return Long.compare(dateValue, ((ValueDate) o).dateValue);
} }
......
...@@ -127,9 +127,8 @@ public class ValueDecimal extends Value { ...@@ -127,9 +127,8 @@ public class ValueDecimal extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueDecimal v = (ValueDecimal) o; return value.compareTo(((ValueDecimal) o).value);
return value.compareTo(v.value);
} }
@Override @Override
......
...@@ -101,9 +101,8 @@ public class ValueDouble extends Value { ...@@ -101,9 +101,8 @@ public class ValueDouble extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueDouble v = (ValueDouble) o; return Double.compare(value, ((ValueDouble) o).value);
return Double.compare(value, v.value);
} }
@Override @Override
...@@ -180,7 +179,7 @@ public class ValueDouble extends Value { ...@@ -180,7 +179,7 @@ public class ValueDouble extends Value {
if (!(other instanceof ValueDouble)) { if (!(other instanceof ValueDouble)) {
return false; return false;
} }
return compareSecure((ValueDouble) other, null) == 0; return compareTypeSafe((ValueDouble) other, null) == 0;
} }
} }
...@@ -33,7 +33,7 @@ public class ValueEnumBase extends Value { ...@@ -33,7 +33,7 @@ public class ValueEnumBase extends Value {
} }
@Override @Override
protected int compareSecure(final Value v, final CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
return Integer.compare(getInt(), v.getInt()); return Integer.compare(getInt(), v.getInt());
} }
......
...@@ -102,9 +102,8 @@ public class ValueFloat extends Value { ...@@ -102,9 +102,8 @@ public class ValueFloat extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueFloat v = (ValueFloat) o; return Float.compare(value, ((ValueFloat) o).value);
return Float.compare(value, v.value);
} }
@Override @Override
...@@ -180,7 +179,7 @@ public class ValueFloat extends Value { ...@@ -180,7 +179,7 @@ public class ValueFloat extends Value {
if (!(other instanceof ValueFloat)) { if (!(other instanceof ValueFloat)) {
return false; return false;
} }
return compareSecure((ValueFloat) other, null) == 0; return compareTypeSafe((ValueFloat) other, null) == 0;
} }
} }
...@@ -243,9 +243,8 @@ public class ValueGeometry extends Value { ...@@ -243,9 +243,8 @@ public class ValueGeometry extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
Geometry g = ((ValueGeometry) v).getGeometryNoCopy(); return getGeometryNoCopy().compareTo(((ValueGeometry) v).getGeometryNoCopy());
return getGeometryNoCopy().compareTo(g);
} }
@Override @Override
......
...@@ -141,9 +141,8 @@ public class ValueInt extends Value { ...@@ -141,9 +141,8 @@ public class ValueInt extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueInt v = (ValueInt) o; return Integer.compare(value, ((ValueInt) o).value);
return Integer.compare(value, v.value);
} }
@Override @Override
......
...@@ -102,7 +102,7 @@ public class ValueJavaObject extends ValueBytes { ...@@ -102,7 +102,7 @@ public class ValueJavaObject extends ValueBytes {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
Object o1 = getObject(); Object o1 = getObject();
Object o2 = v.getObject(); Object o2 = v.getObject();
......
...@@ -515,7 +515,7 @@ public class ValueLob extends Value { ...@@ -515,7 +515,7 @@ public class ValueLob extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
return compare(this, v); return compare(this, v);
} }
...@@ -613,7 +613,7 @@ public class ValueLob extends Value { ...@@ -613,7 +613,7 @@ public class ValueLob extends Value {
public boolean equals(Object other) { public boolean equals(Object other) {
if (other instanceof ValueLob) { if (other instanceof ValueLob) {
ValueLob o = (ValueLob) other; ValueLob o = (ValueLob) other;
return valueType == o.valueType && compareSecure(o, null) == 0; return valueType == o.valueType && compareTypeSafe(o, null) == 0;
} }
return false; return false;
} }
......
...@@ -375,7 +375,7 @@ public class ValueLobDb extends Value { ...@@ -375,7 +375,7 @@ public class ValueLobDb extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
if (v instanceof ValueLobDb) { if (v instanceof ValueLobDb) {
ValueLobDb v2 = (ValueLobDb) v; ValueLobDb v2 = (ValueLobDb) v;
if (v == this) { if (v == this) {
...@@ -511,7 +511,7 @@ public class ValueLobDb extends Value { ...@@ -511,7 +511,7 @@ public class ValueLobDb extends Value {
ValueLobDb otherLob = (ValueLobDb) other; ValueLobDb otherLob = (ValueLobDb) other;
if (hashCode() != otherLob.hashCode()) if (hashCode() != otherLob.hashCode())
return false; return false;
return compareSecure((Value) other, null) == 0; return compareTypeSafe((Value) other, null) == 0;
} }
@Override @Override
......
...@@ -161,9 +161,8 @@ public class ValueLong extends Value { ...@@ -161,9 +161,8 @@ public class ValueLong extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueLong v = (ValueLong) o; return Long.compare(value, ((ValueLong) o).value);
return Long.compare(value, v.value);
} }
@Override @Override
......
...@@ -139,7 +139,7 @@ public class ValueNull extends Value { ...@@ -139,7 +139,7 @@ public class ValueNull extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
throw DbException.throwInternalError("compare null"); throw DbException.throwInternalError("compare null");
} }
......
...@@ -116,7 +116,7 @@ public class ValueResultSet extends Value { ...@@ -116,7 +116,7 @@ public class ValueResultSet extends Value {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
return this == v ? 0 : super.toString().compareTo(v.toString()); return this == v ? 0 : super.toString().compareTo(v.toString());
} }
......
...@@ -108,9 +108,8 @@ public class ValueShort extends Value { ...@@ -108,9 +108,8 @@ public class ValueShort extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueShort v = (ValueShort) o; return Integer.compare(value, ((ValueShort) o).value);
return Integer.compare(value, v.value);
} }
@Override @Override
......
...@@ -45,10 +45,8 @@ public class ValueString extends Value { ...@@ -45,10 +45,8 @@ public class ValueString extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
// compatibility: the other object could be another type return mode.compareString(value, ((ValueString) o).value, false);
ValueString v = (ValueString) o;
return mode.compareString(value, v.value, false);
} }
@Override @Override
......
...@@ -27,9 +27,8 @@ public class ValueStringIgnoreCase extends ValueString { ...@@ -27,9 +27,8 @@ public class ValueStringIgnoreCase extends ValueString {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueStringIgnoreCase v = (ValueStringIgnoreCase) o; return mode.compareString(value, ((ValueStringIgnoreCase) o).value, true);
return mode.compareString(value, v.value, true);
} }
@Override @Override
......
...@@ -181,7 +181,7 @@ public class ValueTime extends Value { ...@@ -181,7 +181,7 @@ public class ValueTime extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
return Long.compare(nanos, ((ValueTime) o).nanos); return Long.compare(nanos, ((ValueTime) o).nanos);
} }
......
...@@ -235,7 +235,7 @@ public class ValueTimestamp extends Value { ...@@ -235,7 +235,7 @@ public class ValueTimestamp extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueTimestamp t = (ValueTimestamp) o; ValueTimestamp t = (ValueTimestamp) o;
int c = Long.compare(dateValue, t.dateValue); int c = Long.compare(dateValue, t.dateValue);
if (c != 0) { if (c != 0) {
......
...@@ -224,7 +224,7 @@ public class ValueTimestampTimeZone extends Value { ...@@ -224,7 +224,7 @@ public class ValueTimestampTimeZone extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
ValueTimestampTimeZone t = (ValueTimestampTimeZone) o; ValueTimestampTimeZone t = (ValueTimestampTimeZone) o;
// Maximum time zone offset is +/-18 hours so difference in days between local // Maximum time zone offset is +/-18 hours so difference in days between local
// and UTC cannot be more than one day // and UTC cannot be more than one day
......
...@@ -163,7 +163,7 @@ public class ValueUuid extends Value { ...@@ -163,7 +163,7 @@ public class ValueUuid extends Value {
} }
@Override @Override
protected int compareSecure(Value o, CompareMode mode) { public int compareTypeSafe(Value o, CompareMode mode) {
if (o == this) { if (o == this) {
return 0; return 0;
} }
...@@ -176,7 +176,7 @@ public class ValueUuid extends Value { ...@@ -176,7 +176,7 @@ public class ValueUuid extends Value {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return other instanceof ValueUuid && compareSecure((Value) other, null) == 0; return other instanceof ValueUuid && compareTypeSafe((Value) other, null) == 0;
} }
@Override @Override
......
...@@ -371,7 +371,7 @@ public class TestCustomDataTypesHandler extends TestDb { ...@@ -371,7 +371,7 @@ public class TestCustomDataTypesHandler extends TestDb {
} }
@Override @Override
protected int compareSecure(Value v, CompareMode mode) { public int compareTypeSafe(Value v, CompareMode mode) {
return val.compare((ComplexNumber) v.getObject()); return val.compare((ComplexNumber) v.getObject());
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论