提交 2f4fbec0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use _ in long numbers for readability

上级 aac42d22
......@@ -311,7 +311,7 @@ public abstract class Command implements CommandInterface {
errorCode != ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1) {
throw e;
}
long now = System.nanoTime() / 1000000;
long now = System.nanoTime() / 1_000_000;
if (start != 0 && now - start > session.getLockTimeout()) {
throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), "");
}
......@@ -327,7 +327,7 @@ public abstract class Command implements CommandInterface {
} catch (InterruptedException e1) {
// ignore
}
long slept = System.nanoTime() / 1000000 - now;
long slept = System.nanoTime() / 1_000_000 - now;
if (slept >= sleep) {
break;
}
......
......@@ -149,7 +149,7 @@ public abstract class Query extends Prepared {
public int getCostAsExpression() {
// ensure the cost is not larger than 1 million,
// so that adding other values can't overflow
return (int) Math.min(1000000.0, 10.0 + 10.0 * getCost());
return (int) Math.min(1_000_000d, 10d + 10d * getCost());
}
/**
......
......@@ -246,12 +246,12 @@ public class Constants {
/**
* The default value for the MAX_MEMORY_UNDO setting.
*/
public static final int DEFAULT_MAX_MEMORY_UNDO = 50000;
public static final int DEFAULT_MAX_MEMORY_UNDO = 50_000;
/**
* The default for the setting MAX_OPERATION_MEMORY.
*/
public static final int DEFAULT_MAX_OPERATION_MEMORY = 100000;
public static final int DEFAULT_MAX_OPERATION_MEMORY = 100_000;
/**
* The default page size to use for new databases.
......@@ -312,7 +312,7 @@ public class Constants {
/**
* The highest possible parameter index.
*/
public static final int MAX_PARAMETER_INDEX = 100000;
public static final int MAX_PARAMETER_INDEX = 100_000;
/**
* The memory needed by a object of class Data
......@@ -404,7 +404,7 @@ public class Constants {
/**
* The number of distinct values to keep in memory when running ANALYZE.
*/
public static final int SELECTIVITY_DISTINCT_COUNT = 10000;
public static final int SELECTIVITY_DISTINCT_COUNT = 10_000;
/**
* The default directory name of the server properties file for the H2
......@@ -512,7 +512,7 @@ public class Constants {
* The maximum time in milliseconds to keep the cost of a view.
* 10000 means 10 seconds.
*/
public static final int VIEW_COST_CACHE_MAX_AGE = 10000;
public static final int VIEW_COST_CACHE_MAX_AGE = 10_000;
/**
* The name of the index cache that is used for temporary view (subqueries
......
......@@ -54,7 +54,7 @@ public class DbSettings extends SettingsBase {
* Database setting <code>ANALYZE_SAMPLE</code> (default: 10000).<br />
* The default sample size when analyzing a table.
*/
public final int analyzeSample = get("ANALYZE_SAMPLE", 10000);
public final int analyzeSample = get("ANALYZE_SAMPLE", 10_000);
/**
* Database setting <code>DATABASE_TO_UPPER</code> (default: true).<br />
......@@ -144,7 +144,7 @@ public class DbSettings extends SettingsBase {
* times out. After the timeout, the LOB is no longer accessible using this
* reference.
*/
public final int lobTimeout = get("LOB_TIMEOUT", 300000);
public final int lobTimeout = get("LOB_TIMEOUT", 300_000);
/**
* Database setting <code>MAX_COMPACT_COUNT</code>
......
......@@ -129,7 +129,7 @@ public class SysProperties {
* been set for the database.
*/
public static final int COLLATOR_CACHE_SIZE =
Utils.getProperty("h2.collatorCacheSize", 32000);
Utils.getProperty("h2.collatorCacheSize", 32_000);
/**
* System property <code>h2.consoleTableIndexes</code>
......@@ -260,7 +260,7 @@ public class SysProperties {
* The default maximum number of rows to be kept in memory in a result set.
*/
public static final int MAX_MEMORY_ROWS =
getAutoScaledForMemoryProperty("h2.maxMemoryRows", 40000);
getAutoScaledForMemoryProperty("h2.maxMemoryRows", 40_000);
/**
* System property <code>h2.maxTraceDataLength</code>
......
......@@ -259,7 +259,7 @@ class AggregateDataMedian extends AggregateData {
nanos += DateTimeUtils.NANOS_PER_DAY / 2;
}
if ((offset & 1) != 0) {
nanos += 30L * 1000000000;
nanos += 30_000_000_000L;
}
if (nanos >= DateTimeUtils.NANOS_PER_DAY) {
nanos -= DateTimeUtils.NANOS_PER_DAY;
......
......@@ -2234,10 +2234,10 @@ public class Function extends Expression implements FunctionCall {
}
private static double roundMagic(double d) {
if ((d < 0.0000000000001) && (d > -0.0000000000001)) {
if ((d < 0.000_000_000_000_1) && (d > -0.000_000_000_000_1)) {
return 0.0;
}
if ((d > 1000000000000.) || (d < -1000000000000.)) {
if ((d > 1_000_000_000_000d) || (d < -1_000_000_000_000d)) {
return d;
}
StringBuilder s = new StringBuilder();
......
......@@ -143,7 +143,7 @@ public class PageDataIndex extends PageIndex {
if (add == 0) {
// in the first re-try add a small random number,
// to avoid collisions after a re-start
row.setKey((long) (row.getKey() + Math.random() * 10000));
row.setKey((long) (row.getKey() + Math.random() * 10_000));
} else {
row.setKey(row.getKey() + add);
}
......
......@@ -314,7 +314,7 @@ public class FileStore {
* @return the retention time
*/
public int getDefaultRetentionTime() {
return 45000;
return 45_000;
}
/**
......
......@@ -141,7 +141,7 @@ public final class MVStore {
* Used to mark a chunk as free, when it was detected that live bookkeeping
* is incorrect.
*/
private static final int MARKED_FREE = 10000000;
private static final int MARKED_FREE = 10_000_000;
/**
* The background thread, if any.
......
......@@ -1479,7 +1479,7 @@ public class ObjectDataType implements DataType {
*/
static class SerializedObjectType extends AutoDetectDataType {
private int averageSize = 10000;
private int averageSize = 10_000;
SerializedObjectType(ObjectDataType base) {
super(base, TYPE_SERIALIZED_OBJECT);
......
......@@ -1775,7 +1775,7 @@ public class WebApp {
String d = rs.getString(columnIndex);
if (d == null) {
return "<i>null</i>";
} else if (d.length() > 100000) {
} else if (d.length() > 100_000) {
String s;
if (isBinary(rs.getMetaData().getColumnType(columnIndex))) {
s = PageParser.escapeHtml(d.substring(0, 6)) +
......
......@@ -491,8 +491,8 @@ public class Data {
writeByte((byte) LOCAL_TIME);
ValueTime t = (ValueTime) v;
long nanos = t.getNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
writeVarLong(millis);
writeVarLong(nanos);
} else {
......@@ -519,15 +519,15 @@ public class Data {
long dateValue = ts.getDateValue();
writeVarLong(dateValue);
long nanos = ts.getTimeNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
writeVarLong(millis);
writeVarLong(nanos);
} else {
Timestamp ts = v.getTimestamp();
writeByte((byte) type);
writeVarLong(DateTimeUtils.getTimeLocalWithoutDst(ts));
writeVarInt(ts.getNanos() % 1000000);
writeVarInt(ts.getNanos() % 1_000_000);
}
break;
}
......@@ -758,7 +758,7 @@ public class Data {
return ValueDate.fromMillis(DateTimeUtils.getTimeUTCWithoutDst(x));
}
case LOCAL_TIME: {
long nanos = readVarLong() * 1000000 + readVarLong();
long nanos = readVarLong() * 1_000_000 + readVarLong();
return ValueTime.fromNanos(nanos);
}
case Value.TIME:
......@@ -767,7 +767,7 @@ public class Data {
DateTimeUtils.getTimeUTCWithoutDst(readVarLong()));
case LOCAL_TIMESTAMP: {
long dateValue = readVarLong();
long nanos = readVarLong() * 1000000 + readVarLong();
long nanos = readVarLong() * 1_000_000 + readVarLong();
return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos);
}
case Value.TIMESTAMP: {
......@@ -1003,8 +1003,8 @@ public class Data {
case Value.TIME:
if (STORE_LOCAL_TIME) {
long nanos = ((ValueTime) v).getNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
return 1 + getVarLongLen(millis) + getVarLongLen(nanos);
}
return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(v.getTime()));
......@@ -1021,14 +1021,14 @@ public class Data {
ValueTimestamp ts = (ValueTimestamp) v;
long dateValue = ts.getDateValue();
long nanos = ts.getTimeNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
return 1 + getVarLongLen(dateValue) + getVarLongLen(millis) +
getVarLongLen(nanos);
}
Timestamp ts = v.getTimestamp();
return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(ts)) +
getVarIntLen(ts.getNanos() % 1000000);
getVarIntLen(ts.getNanos() % 1_000_000);
}
case Value.TIMESTAMP_TZ: {
ValueTimestampTimeZone ts = (ValueTimestampTimeZone) v;
......
......@@ -78,7 +78,7 @@ public class LobStorageBackend implements LobStorageInterface {
/**
* The size of the chunks we use when storing LOBs inside the database file.
*/
private static final int BLOCK_LENGTH = 20000;
private static final int BLOCK_LENGTH = 20_000;
/**
* The size of cache for lob block hashes. Each entry needs 2 longs (16
......
......@@ -44,7 +44,7 @@ public class FilePathNioMapped extends FilePathNio {
*/
class FileNioMapped extends FileBase {
private static final long GC_TIMEOUT_MS = 10000;
private static final long GC_TIMEOUT_MS = 10_000;
private final String name;
private final MapMode mode;
private RandomAccessFile file;
......
......@@ -47,7 +47,7 @@ public class TableLink extends Table {
private static final int MAX_RETRY = 2;
private static final long ROW_COUNT_APPROXIMATION = 100000;
private static final long ROW_COUNT_APPROXIMATION = 100_000;
private final String originalSchema;
private String driver, url, user, password, originalTable, qualifiedTableName;
......
......@@ -181,13 +181,13 @@ public class CompressTool {
buff[pos++] = (byte) (0x80 | (x >> 8));
buff[pos] = (byte) x;
return 2;
} else if (x < 0x200000) {
} else if (x < 0x20_0000) {
buff[pos++] = (byte) (0xc0 | (x >> 16));
buff[pos++] = (byte) (x >> 8);
buff[pos] = (byte) x;
return 3;
} else if (x < 0x10000000) {
Bits.writeInt(buff, pos, x | 0xe0000000);
} else if (x < 0x1000_0000) {
Bits.writeInt(buff, pos, x | 0xe000_0000);
return 4;
} else {
buff[pos++] = (byte) 0xf0;
......@@ -210,9 +210,9 @@ public class CompressTool {
return 1;
} else if (x < 0x4000) {
return 2;
} else if (x < 0x200000) {
} else if (x < 0x20_0000) {
return 3;
} else if (x < 0x10000000) {
} else if (x < 0x1000_0000) {
return 4;
} else {
return 5;
......
......@@ -50,7 +50,7 @@ public class DateTimeUtils {
/**
* The number of nanoseconds per day.
*/
public static final long NANOS_PER_DAY = MILLIS_PER_DAY * 1000000;
public static final long NANOS_PER_DAY = MILLIS_PER_DAY * 1_000_000;
private static final int SHIFT_YEAR = 9;
private static final int SHIFT_MONTH = 5;
......@@ -229,10 +229,10 @@ public class DateTimeUtils {
cal.clear();
cal.setLenient(true);
long nanos = t.getNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long s = millis / 1000;
millis -= s * 1000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
long s = millis / 1_000;
millis -= s * 1_000;
long m = s / 60;
s -= m * 60;
long h = m / 60;
......@@ -257,10 +257,10 @@ public class DateTimeUtils {
cal.setLenient(true);
long dateValue = ts.getDateValue();
long nanos = ts.getTimeNanos();
long millis = nanos / 1000000;
nanos -= millis * 1000000;
long s = millis / 1000;
millis -= s * 1000;
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
long s = millis / 1_000;
millis -= s * 1_000;
long m = s / 60;
s -= m * 60;
long h = m / 60;
......@@ -269,7 +269,7 @@ public class DateTimeUtils {
monthFromDateValue(dateValue), dayFromDateValue(dateValue),
(int) h, (int) m, (int) s, (int) millis);
Timestamp x = new Timestamp(ms);
x.setNanos((int) (nanos + millis * 1000000));
x.setNanos((int) (nanos + millis * 1_000_000));
return x;
}
......@@ -323,7 +323,7 @@ public class DateTimeUtils {
cal.setTimeInMillis(x.getTime());
long dateValue = dateValueFromCalendar(cal);
long nanos = nanosFromCalendar(cal);
nanos += x.getNanos() % 1000000;
nanos += x.getNanos() % 1_000_000;
return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos);
}
......@@ -408,14 +408,14 @@ public class DateTimeUtils {
String n = (s.substring(s3 + 1, end) + "000000000").substring(0, 9);
nanos = Integer.parseInt(n);
}
if (hour >= 2000000 || minute < 0 || minute >= 60 || second < 0
if (hour >= 2_000_000 || minute < 0 || minute >= 60 || second < 0
|| second >= 60) {
throw new IllegalArgumentException(s);
}
if (timeOfDay && hour >= 24) {
throw new IllegalArgumentException(s);
}
nanos += ((((hour * 60L) + minute) * 60) + second) * 1000000000;
nanos += ((((hour * 60L) + minute) * 60) + second) * 1_000_000_000;
return negative ? -nanos : nanos;
}
......@@ -507,13 +507,13 @@ public class DateTimeUtils {
if (tz != null) {
if (withTimeZone) {
if (tz != UTC) {
long millis = convertDateTimeValueToMillis(tz, dateValue, nanos / 1000000);
long millis = convertDateTimeValueToMillis(tz, dateValue, nanos / 1_000_000);
tzMinutes = (short) (tz.getOffset(millis) / 1000 / 60);
}
} else {
long millis = convertDateTimeValueToMillis(tz, dateValue, nanos / 1000000);
long millis = convertDateTimeValueToMillis(tz, dateValue, nanos / 1_000_000);
dateValue = dateValueFromDate(millis);
nanos = nanos % 1000000 + nanosFromDate(millis);
nanos = nanos % 1_000_000 + nanosFromDate(millis);
}
}
}
......@@ -1031,9 +1031,9 @@ public class DateTimeUtils {
* @return the time
*/
public static Time convertNanoToTime(long nanosSinceMidnight) {
long millis = nanosSinceMidnight / 1000000;
long s = millis / 1000;
millis -= s * 1000;
long millis = nanosSinceMidnight / 1_000_000;
long s = millis / 1_000;
millis -= s * 1_000;
long m = s / 60;
s -= m * 60;
long h = m / 60;
......@@ -1246,7 +1246,7 @@ public class DateTimeUtils {
y--;
m += 12;
}
long a = ((y * 2922L) >> 3) + DAYS_OFFSET[m - 3] + d - 719484;
long a = ((y * 2922L) >> 3) + DAYS_OFFSET[m - 3] + d - 719_484;
if (y <= 1582 && ((y < 1582) || (m * 100 + d < 1015))) {
// Julian calendar (cutover at 1582-10-04 / 1582-10-15)
a += 13;
......@@ -1272,7 +1272,7 @@ public class DateTimeUtils {
y--;
m += 12;
}
long a = ((y * 2922L) >> 3) + DAYS_OFFSET[m - 3] + d - 719484;
long a = ((y * 2922L) >> 3) + DAYS_OFFSET[m - 3] + d - 719_484;
if (y < 1901 || y > 2099) {
// Slow mode
a += (y / 400) - (y / 100) + 15;
......@@ -1287,19 +1287,19 @@ public class DateTimeUtils {
* @return the date value
*/
public static long dateValueFromAbsoluteDay(long absoluteDay) {
long d = absoluteDay + 719468;
long d = absoluteDay + 719_468;
long y100 = 0, offset;
if (d > 578040) {
if (d > 578_040) {
// Gregorian calendar
long y400 = d / 146097;
d -= y400 * 146097;
y100 = d / 36524;
d -= y100 * 36524;
long y400 = d / 146_097;
d -= y400 * 146_097;
y100 = d / 36_524;
d -= y100 * 36_524;
offset = y400 * 400 + y100 * 100;
} else {
// Julian calendar
d += 292200000002L;
offset = -800000000;
d += 292_200_000_002L;
offset = -800_000_000;
}
long y4 = d / 1461;
d -= y4 * 1461;
......@@ -1330,7 +1330,7 @@ public class DateTimeUtils {
int y = yearFromDateValue(dateValue);
int m = monthFromDateValue(dateValue);
int d = dayFromDateValue(dateValue);
if (y > 0 && y < 10000) {
if (y > 0 && y < 10_000) {
StringUtils.appendZeroPadded(buff, 4, y);
} else {
buff.append(y);
......@@ -1358,10 +1358,10 @@ public class DateTimeUtils {
* get correct result. The simplest way to do this with such constraints is to
* divide -nanos by -1000000.
*/
long ms = -nanos / -1000000;
nanos -= ms * 1000000;
long s = ms / 1000;
ms -= s * 1000;
long ms = -nanos / -1_000_000;
nanos -= ms * 1_000_000;
long s = ms / 1_000;
ms -= s * 1_000;
long m = s / 60;
s -= m * 60;
long h = m / 60;
......
......@@ -224,7 +224,7 @@ public class MathUtils {
public static int nextPowerOf2(int x) throws IllegalArgumentException {
if (x == 0) {
return 1;
} else if (x < 0 || x > 0x40000000 ) {
} else if (x < 0 || x > 0x4000_0000 ) {
throw new IllegalArgumentException("Argument out of range"
+ " [0x0-0x40000000]. Argument was: " + x);
}
......
......@@ -44,7 +44,7 @@ public class ThreadDeadlockDetector {
public void run() {
checkForDeadlocks();
}
}, 10, 10000);
}, 10, 10_000);
}
/**
......
......@@ -126,8 +126,8 @@ public class ToDateParser {
if (timeZone == null) {
timeZone = TimeZone.getDefault();
}
long millis = DateTimeUtils.convertDateTimeValueToMillis(timeZone, dateValue, nanos / 1000000);
offset = (short) (timeZone.getOffset(millis) / 1000 / 60);
long millis = DateTimeUtils.convertDateTimeValueToMillis(timeZone, dateValue, nanos / 1_000_000);
offset = (short) (timeZone.getOffset(millis) / 60_000);
}
return ValueTimestampTimeZone.fromDateValueAndNanos(dateValue, ts.getTimeNanos(), offset);
}
......
......@@ -372,11 +372,11 @@ public class Transfer {
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
Timestamp ts = v.getTimestamp();
writeLong(DateTimeUtils.getTimeLocalWithoutDst(ts));
writeInt(ts.getNanos() % 1000000);
writeInt(ts.getNanos() % 1_000_000);
} else {
Timestamp ts = v.getTimestamp();
writeLong(ts.getTime());
writeInt(ts.getNanos() % 1000000);
writeInt(ts.getNanos() % 1_000_000);
}
break;
}
......@@ -573,10 +573,10 @@ public class Transfer {
} else if (version >= Constants.TCP_PROTOCOL_VERSION_7) {
return ValueTimestamp.fromMillisNanos(
DateTimeUtils.getTimeUTCWithoutDst(readLong()),
readInt() % 1000000);
readInt() % 1_000_000);
}
return ValueTimestamp.fromMillisNanos(readLong(),
readInt() % 1000000);
readInt() % 1_000_000);
}
case Value.TIMESTAMP_TZ: {
return ValueTimestampTimeZone.fromDateValueAndNanos(readLong(),
......
......@@ -48,7 +48,7 @@ public class ValueDecimal extends Value {
/**
* The maximum scale of a BigDecimal value.
*/
private static final int BIG_DECIMAL_SCALE_MAX = 100000;
private static final int BIG_DECIMAL_SCALE_MAX = 100_000;
private final BigDecimal value;
private String valueString;
......
......@@ -70,7 +70,7 @@ public class ValueTime extends Value {
*/
public static ValueTime fromNanos(long nanos) {
if (!SysProperties.UNLIMITED_TIME_RANGE) {
if (nanos < 0L || nanos >= 86400000000000L) {
if (nanos < 0L || nanos >= DateTimeUtils.NANOS_PER_DAY) {
StringBuilder builder = new StringBuilder();
DateTimeUtils.appendTime(builder, nanos);
throw DbException.get(ErrorCode.INVALID_DATETIME_CONSTANT_2,
......
......@@ -88,7 +88,7 @@ public class ValueTimestamp extends Value {
*/
public static ValueTimestamp get(Timestamp timestamp) {
long ms = timestamp.getTime();
long nanos = timestamp.getNanos() % 1000000;
long nanos = timestamp.getNanos() % 1_000_000;
long dateValue = DateTimeUtils.dateValueFromDate(ms);
nanos += DateTimeUtils.nanosFromDate(ms);
return fromDateValueAndNanos(dateValue, nanos);
......
......@@ -54,7 +54,7 @@ public class ValueUuid extends Value {
// version 4 (random)
high = (high & (~0xf000L)) | 0x4000L;
// variant (Leach-Salz)
low = (low & 0x3fffffffffffffffL) | 0x8000000000000000L;
low = (low & 0x3fff_ffff_ffff_ffffL) | 0x8000_0000_0000_0000L;
return new ValueUuid(high, low);
}
......
......@@ -30,7 +30,7 @@ public class DirectInsert {
Class.forName("org.h2.Driver");
DeleteDbFiles.execute("~", "test", true);
String url = "jdbc:h2:~/test";
initialInsert(url, 200000);
initialInsert(url, 200_000);
for (int i = 0; i < 3; i++) {
createAsSelect(url, true);
createAsSelect(url, false);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论