提交 16b47879 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Move MIN and MAX constants to ValueLong

上级 ec489730
...@@ -3186,7 +3186,7 @@ public class Parser { ...@@ -3186,7 +3186,7 @@ public class Parser {
.compareTo(ValueLong.MIN_BD) == 0) { .compareTo(ValueLong.MIN_BD) == 0) {
// convert Long.MIN_VALUE to type 'long' // convert Long.MIN_VALUE to type 'long'
// (Long.MAX_VALUE+1 is of type 'decimal') // (Long.MAX_VALUE+1 is of type 'decimal')
r = ValueExpression.get(ValueLong.get(Long.MIN_VALUE)); r = ValueExpression.get(ValueLong.MIN);
} }
read(); read();
} else { } else {
...@@ -3813,7 +3813,7 @@ public class Parser { ...@@ -3813,7 +3813,7 @@ public class Parser {
checkLiterals(false); checkLiterals(false);
if (!containsE && sub.indexOf('.') < 0) { if (!containsE && sub.indexOf('.') < 0) {
BigInteger bi = new BigInteger(sub); BigInteger bi = new BigInteger(sub);
if (bi.compareTo(ValueLong.MAX) <= 0) { if (bi.compareTo(ValueLong.MAX_BI) <= 0) {
// parse constants like "10000000L" // parse constants like "10000000L"
if (chars[i] == 'L') { if (chars[i] == 'L') {
parseIndex++; parseIndex++;
......
...@@ -66,12 +66,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex { ...@@ -66,12 +66,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
@Override @Override
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min = mainIndex.getKey(first, ValueLong min = mainIndex.getKey(first, ValueLong.MIN, ValueLong.MIN);
MVPrimaryIndex.MIN, MVPrimaryIndex.MIN); // ifNull is MIN as well, because the column is never NULL
// ifNull is MIN_VALUE as well, because the column is never NULL
// so avoid returning all rows (returning one row is OK) // so avoid returning all rows (returning one row is OK)
ValueLong max = mainIndex.getKey(last, ValueLong max = mainIndex.getKey(last, ValueLong.MAX, ValueLong.MIN);
MVPrimaryIndex.MAX, MVPrimaryIndex.MIN);
return mainIndex.find(session, min, max); return mainIndex.find(session, min, max);
} }
......
...@@ -37,16 +37,6 @@ import org.h2.value.ValueNull; ...@@ -37,16 +37,6 @@ import org.h2.value.ValueNull;
*/ */
public class MVPrimaryIndex extends BaseIndex { public class MVPrimaryIndex extends BaseIndex {
/**
* The minimum long value.
*/
static final ValueLong MIN = ValueLong.get(Long.MIN_VALUE);
/**
* The maximum long value.
*/
static final ValueLong MAX = ValueLong.get(Long.MAX_VALUE);
private final MVTable mvTable; private final MVTable mvTable;
private final String mapName; private final String mapName;
private final TransactionMap<Value, Value> dataMap; private final TransactionMap<Value, Value> dataMap;
...@@ -172,7 +162,7 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -172,7 +162,7 @@ public class MVPrimaryIndex extends BaseIndex {
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min, max; ValueLong min, max;
if (first == null) { if (first == null) {
min = MIN; min = ValueLong.MIN;
} else if (mainIndexColumn < 0) { } else if (mainIndexColumn < 0) {
min = ValueLong.get(first.getKey()); min = ValueLong.get(first.getKey());
} else { } else {
...@@ -184,7 +174,7 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -184,7 +174,7 @@ public class MVPrimaryIndex extends BaseIndex {
} }
} }
if (last == null) { if (last == null) {
max = MAX; max = ValueLong.MAX;
} else if (mainIndexColumn < 0) { } else if (mainIndexColumn < 0) {
max = ValueLong.get(last.getKey()); max = ValueLong.get(last.getKey());
} else { } else {
......
...@@ -140,7 +140,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -140,7 +140,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
Value[] array = rowData.getList(); Value[] array = rowData.getList();
// don't change the original value // don't change the original value
array = array.clone(); array = array.clone();
array[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE); array[keyColumns - 1] = ValueLong.MIN;
ValueArray unique = ValueArray.get(array); ValueArray unique = ValueArray.get(array);
SearchRow row = convertToSearchRow(rowData); SearchRow row = convertToSearchRow(rowData);
if (!mayHaveNullDuplicates(row)) { if (!mayHaveNullDuplicates(row)) {
...@@ -194,7 +194,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -194,7 +194,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
if (indexType.isUnique()) { if (indexType.isUnique()) {
// this will detect committed entries only // this will detect committed entries only
unique = convertToKey(row); unique = convertToKey(row);
unique.getList()[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE); unique.getList()[keyColumns - 1] = ValueLong.MIN;
if (mayHaveNullDuplicates(row)) { if (mayHaveNullDuplicates(row)) {
// No further unique checks required // No further unique checks required
unique = null; unique = null;
...@@ -261,7 +261,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex { ...@@ -261,7 +261,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) { private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) {
ValueArray min = convertToKey(first); ValueArray min = convertToKey(first);
if (min != null) { if (min != null) {
min.getList()[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE); min.getList()[keyColumns - 1] = ValueLong.MIN;
} }
TransactionMap<Value, Value> map = getMap(session); TransactionMap<Value, Value> map = getMap(session);
if (bigger && min != null) { if (bigger && min != null) {
......
...@@ -18,10 +18,20 @@ import org.h2.message.DbException; ...@@ -18,10 +18,20 @@ import org.h2.message.DbException;
*/ */
public class ValueLong extends Value { public class ValueLong extends Value {
/**
* The smallest {@code ValueLong} value.
*/
public static final ValueLong MIN = get(Long.MIN_VALUE);
/**
* The largest {@code ValueLong} value.
*/
public static final ValueLong MAX = get(Long.MAX_VALUE);
/** /**
* The largest Long value, as a BigInteger. * The largest Long value, as a BigInteger.
*/ */
public static final BigInteger MAX = BigInteger.valueOf(Long.MAX_VALUE); public static final BigInteger MAX_BI = BigInteger.valueOf(Long.MAX_VALUE);
/** /**
* The smallest Long value, as a BigDecimal. * The smallest Long value, as a BigDecimal.
...@@ -39,7 +49,7 @@ public class ValueLong extends Value { ...@@ -39,7 +49,7 @@ public class ValueLong extends Value {
*/ */
public static final int DISPLAY_SIZE = 20; public static final int DISPLAY_SIZE = 20;
private static final BigInteger MIN = BigInteger.valueOf(Long.MIN_VALUE); private static final BigInteger MIN_BI = BigInteger.valueOf(Long.MIN_VALUE);
private static final int STATIC_SIZE = 100; private static final int STATIC_SIZE = 100;
private static final ValueLong[] STATIC_CACHE; private static final ValueLong[] STATIC_CACHE;
...@@ -128,7 +138,7 @@ public class ValueLong extends Value { ...@@ -128,7 +138,7 @@ public class ValueLong extends Value {
BigInteger bv = BigInteger.valueOf(value); BigInteger bv = BigInteger.valueOf(value);
BigInteger bo = BigInteger.valueOf(other.value); BigInteger bo = BigInteger.valueOf(other.value);
BigInteger br = bv.multiply(bo); BigInteger br = bv.multiply(bo);
if (br.compareTo(MIN) < 0 || br.compareTo(MAX) > 0) { if (br.compareTo(MIN_BI) < 0 || br.compareTo(MAX_BI) > 0) {
throw getOverflow(); throw getOverflow();
} }
return ValueLong.get(br.longValue()); return ValueLong.get(br.longValue());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论