Unverified 提交 4389e581 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #787 from katzyn/misc

Assorted changes
......@@ -3186,7 +3186,7 @@ public class Parser {
.compareTo(ValueLong.MIN_BD) == 0) {
// convert Long.MIN_VALUE to type 'long'
// (Long.MAX_VALUE+1 is of type 'decimal')
r = ValueExpression.get(ValueLong.get(Long.MIN_VALUE));
r = ValueExpression.get(ValueLong.MIN);
}
read();
} else {
......@@ -3813,7 +3813,7 @@ public class Parser {
checkLiterals(false);
if (!containsE && sub.indexOf('.') < 0) {
BigInteger bi = new BigInteger(sub);
if (bi.compareTo(ValueLong.MAX) <= 0) {
if (bi.compareTo(ValueLong.MAX_BI) <= 0) {
// parse constants like "10000000L"
if (chars[i] == 'L') {
parseIndex++;
......
......@@ -27,19 +27,20 @@ public class Mode {
*/
public enum UniqueIndexNullsHandling {
/**
* Multiple identical indexed columns with at least one {@code NULL} value are
* allowed in unique index.
* Multiple rows with identical values in indexed columns with at least one
* indexed {@code NULL} value are allowed in unique index.
*/
ALLOW_DUPLICATES_WITH_ANY_NULL,
/**
* Multiple identical indexed columns with all {@code NULL} values are allowed
* in unique index.
* Multiple rows with identical values in indexed columns with all indexed
* {@code NULL} values are allowed in unique index.
*/
ALLOW_DUPLICATES_WITH_ALL_NULLS,
/**
* Multiple identical indexed columns are not allowed in unique index.
* Multiple rows with identical values in indexed columns are not allowed in
* unique index.
*/
FORBID_ANY_DUPLICATES;
}
......
......@@ -66,12 +66,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min = mainIndex.getKey(first,
MVPrimaryIndex.MIN, MVPrimaryIndex.MIN);
// ifNull is MIN_VALUE as well, because the column is never NULL
ValueLong min = mainIndex.getKey(first, ValueLong.MIN, ValueLong.MIN);
// ifNull is MIN as well, because the column is never NULL
// so avoid returning all rows (returning one row is OK)
ValueLong max = mainIndex.getKey(last,
MVPrimaryIndex.MAX, MVPrimaryIndex.MIN);
ValueLong max = mainIndex.getKey(last, ValueLong.MAX, ValueLong.MIN);
return mainIndex.find(session, min, max);
}
......
......@@ -37,16 +37,6 @@ import org.h2.value.ValueNull;
*/
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 String mapName;
private final TransactionMap<Value, Value> dataMap;
......@@ -172,7 +162,7 @@ public class MVPrimaryIndex extends BaseIndex {
public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min, max;
if (first == null) {
min = MIN;
min = ValueLong.MIN;
} else if (mainIndexColumn < 0) {
min = ValueLong.get(first.getKey());
} else {
......@@ -184,7 +174,7 @@ public class MVPrimaryIndex extends BaseIndex {
}
}
if (last == null) {
max = MAX;
max = ValueLong.MAX;
} else if (mainIndexColumn < 0) {
max = ValueLong.get(last.getKey());
} else {
......
......@@ -140,7 +140,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
Value[] array = rowData.getList();
// don't change the original value
array = array.clone();
array[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE);
array[keyColumns - 1] = ValueLong.MIN;
ValueArray unique = ValueArray.get(array);
SearchRow row = convertToSearchRow(rowData);
if (!mayHaveNullDuplicates(row)) {
......@@ -194,7 +194,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
if (indexType.isUnique()) {
// this will detect committed entries only
unique = convertToKey(row);
unique.getList()[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE);
unique.getList()[keyColumns - 1] = ValueLong.MIN;
if (mayHaveNullDuplicates(row)) {
// No further unique checks required
unique = null;
......@@ -261,7 +261,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) {
ValueArray min = convertToKey(first);
if (min != null) {
min.getList()[keyColumns - 1] = ValueLong.get(Long.MIN_VALUE);
min.getList()[keyColumns - 1] = ValueLong.MIN;
}
TransactionMap<Value, Value> map = getMap(session);
if (bigger && min != null) {
......
......@@ -890,26 +890,14 @@ public abstract class Value {
});
}
case INT: {
int x = getInt();
return ValueBytes.getNoCopy(new byte[]{
(byte) (x >> 24),
(byte) (x >> 16),
(byte) (x >> 8),
(byte) x
});
byte[] b = new byte[4];
Bits.writeInt(b, 0, getInt());
return ValueBytes.getNoCopy(b);
}
case LONG: {
long x = getLong();
return ValueBytes.getNoCopy(new byte[]{
(byte) (x >> 56),
(byte) (x >> 48),
(byte) (x >> 40),
(byte) (x >> 32),
(byte) (x >> 24),
(byte) (x >> 16),
(byte) (x >> 8),
(byte) x
});
byte[] b = new byte[8];
Bits.writeLong(b, 0, getLong());
return ValueBytes.getNoCopy(b);
}
case ENUM:
case TIMESTAMP_TZ:
......
......@@ -18,10 +18,20 @@ import org.h2.message.DbException;
*/
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.
*/
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.
......@@ -39,7 +49,7 @@ public class ValueLong extends Value {
*/
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 ValueLong[] STATIC_CACHE;
......@@ -128,7 +138,7 @@ public class ValueLong extends Value {
BigInteger bv = BigInteger.valueOf(value);
BigInteger bo = BigInteger.valueOf(other.value);
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();
}
return ValueLong.get(br.longValue());
......
......@@ -127,7 +127,7 @@ public class FunctionMultiReturn {
public static Object[] polar2CartesianArray(Double r, Double alpha) {
double x = r.doubleValue() * Math.cos(alpha.doubleValue());
double y = r.doubleValue() * Math.sin(alpha.doubleValue());
return new Object[]{new Double(x), new Double(y)};
return new Object[]{x, y};
}
/**
......
......@@ -876,7 +876,7 @@ public class TestOptimizations extends TestBase {
case 5:
if (random.nextInt(1000) == 1) {
stat.execute("insert into test values(" + i + ", null)");
map.put(new Integer(i), null);
map.put(i, null);
} else {
int value = random.nextInt();
stat.execute("insert into test values(" + i + ", " + value + ")");
......
......@@ -74,13 +74,13 @@ public class SupportedTypes {
static SupportedTypes randomValue() {
Random rand = new Random();
SupportedTypes s = new SupportedTypes();
s.myBool = Boolean.valueOf(rand.nextBoolean());
s.myByte = new Byte((byte) rand.nextInt(Byte.MAX_VALUE));
s.myShort = new Short((short) rand.nextInt(Short.MAX_VALUE));
s.myInteger = new Integer(rand.nextInt());
s.myLong = new Long(rand.nextLong());
s.myFloat = new Float(rand.nextFloat());
s.myDouble = new Double(rand.nextDouble());
s.myBool = rand.nextBoolean();
s.myByte = (byte) rand.nextInt(Byte.MAX_VALUE);
s.myShort = (short) rand.nextInt(Short.MAX_VALUE);
s.myInteger = rand.nextInt();
s.myLong = rand.nextLong();
s.myFloat = rand.nextFloat();
s.myDouble = rand.nextDouble();
s.myBigDecimal = new BigDecimal(rand.nextDouble());
s.myString = Long.toHexString(rand.nextLong());
s.myUtilDate = new java.util.Date(rand.nextLong());
......
......@@ -986,7 +986,7 @@ public class TestPreparedStatement extends TestBase {
prep.setString(2, "-1");
prep.executeUpdate();
prep.setInt(1, 7);
prep.setObject(2, new Integer(3));
prep.setObject(2, 3);
prep.executeUpdate();
prep.setObject(1, "8");
// should throw an exception
......@@ -1132,12 +1132,12 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(1, Boolean.TRUE);
prep.setObject(2, "Abc");
prep.setObject(3, new BigDecimal("10.2"));
prep.setObject(4, new Byte((byte) 0xff));
prep.setObject(5, new Short(Short.MAX_VALUE));
prep.setObject(6, new Integer(Integer.MIN_VALUE));
prep.setObject(7, new Long(Long.MAX_VALUE));
prep.setObject(8, new Float(Float.MAX_VALUE));
prep.setObject(9, new Double(Double.MAX_VALUE));
prep.setObject(4, (byte) 0xff);
prep.setObject(5, Short.MAX_VALUE);
prep.setObject(6, Integer.MIN_VALUE);
prep.setObject(7, Long.MAX_VALUE);
prep.setObject(8, Float.MAX_VALUE);
prep.setObject(9, Double.MAX_VALUE);
prep.setObject(10, java.sql.Date.valueOf("2001-02-03"));
prep.setObject(11, java.sql.Time.valueOf("04:05:06"));
prep.setObject(12, java.sql.Timestamp.valueOf(
......@@ -1145,7 +1145,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(13, new java.util.Date(java.sql.Date.valueOf(
"2001-02-03").getTime()));
prep.setObject(14, new byte[] { 10, 20, 30 });
prep.setObject(15, new Character('a'), Types.OTHER);
prep.setObject(15, 'a', Types.OTHER);
prep.setObject(16, "2001-01-02", Types.DATE);
// converting to null seems strange...
prep.setObject(17, "2001-01-02", Types.NULL);
......@@ -1163,14 +1163,10 @@ public class TestPreparedStatement extends TestBase {
(Object) Byte.valueOf((byte) 0xff) : (Object) Integer.valueOf(-1)));
assertTrue(rs.getObject(5).equals(SysProperties.OLD_RESULT_SET_GET_OBJECT ?
(Object) Short.valueOf(Short.MAX_VALUE) : (Object) Integer.valueOf(Short.MAX_VALUE)));
assertTrue(rs.getObject(6).equals(
new Integer(Integer.MIN_VALUE)));
assertTrue(rs.getObject(7).equals(
new Long(Long.MAX_VALUE)));
assertTrue(rs.getObject(8).equals(
new Float(Float.MAX_VALUE)));
assertTrue(rs.getObject(9).equals(
new Double(Double.MAX_VALUE)));
assertTrue(rs.getObject(6).equals(Integer.MIN_VALUE));
assertTrue(rs.getObject(7).equals(Long.MAX_VALUE));
assertTrue(rs.getObject(8).equals(Float.MAX_VALUE));
assertTrue(rs.getObject(9).equals(Double.MAX_VALUE));
assertTrue(rs.getObject(10).equals(
java.sql.Date.valueOf("2001-02-03")));
assertEquals("04:05:06", rs.getObject(11).toString());
......@@ -1185,8 +1181,7 @@ public class TestPreparedStatement extends TestBase {
assertTrue(rs.getObject(16).equals(
java.sql.Date.valueOf("2001-01-02")));
assertTrue(rs.getObject(17) == null && rs.wasNull());
assertTrue(rs.getObject(18).equals(
new Double(3.725)));
assertTrue(rs.getObject(18).equals(3.725d));
assertTrue(rs.getObject(19).equals(
java.sql.Time.valueOf("23:22:21")));
assertTrue(rs.getObject(20).equals(
......
......@@ -1205,19 +1205,19 @@ public class TestResultSet extends TestBase {
o = rs.getObject(2);
trace(o.getClass().getName());
assertTrue(o instanceof Double);
assertTrue(((Double) o).compareTo(new Double("-1.00")) == 0);
assertTrue(((Double) o).compareTo(-1d) == 0);
o = rs.getObject(2, Double.class);
trace(o.getClass().getName());
assertTrue(o instanceof Double);
assertTrue(((Double) o).compareTo(new Double("-1.00")) == 0);
assertTrue(((Double) o).compareTo(-1d) == 0);
o = rs.getObject(3);
trace(o.getClass().getName());
assertTrue(o instanceof Float);
assertTrue(((Float) o).compareTo(new Float("-1.00")) == 0);
assertTrue(((Float) o).compareTo(-1f) == 0);
o = rs.getObject(3, Float.class);
trace(o.getClass().getName());
assertTrue(o instanceof Float);
assertTrue(((Float) o).compareTo(new Float("-1.00")) == 0);
assertTrue(((Float) o).compareTo(-1f) == 0);
rs.next();
assertTrue(rs.getInt(1) == 2);
assertTrue(!rs.wasNull());
......@@ -1745,7 +1745,7 @@ public class TestResultSet extends TestBase {
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE ARRAY)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)");
prep.setInt(1, 1);
prep.setObject(2, new Object[] { new Integer(1), new Integer(2) });
prep.setObject(2, new Object[] { 1, 2 });
prep.execute();
prep.setInt(1, 2);
prep.setObject(2, new Object[] { 11, 12 });
......
......@@ -440,7 +440,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
} else if (type == boolean.class) {
return random.nextBoolean();
} else if (type == double.class) {
return new Double(random.getRandomDouble());
return random.getRandomDouble();
} else if (type == String.class) {
if (random.getInt(10) == 0) {
return null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论