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

Merge pull request #1236 from grandinj/remove_store_local_time

remove STORE_LOCAL_TIME code
...@@ -93,15 +93,6 @@ public class Data { ...@@ -93,15 +93,6 @@ public class Data {
private static final long MILLIS_PER_MINUTE = 1000 * 60; private static final long MILLIS_PER_MINUTE = 1000 * 60;
/**
* Can not store the local time, because doing so with old database files
* that didn't do it could result in an ArrayIndexOutOfBoundsException. The
* reason is that adding a row to a page only allocated space for the new
* row, but didn't take into account that existing rows now can use more
* space, due to the changed format.
*/
private static final boolean STORE_LOCAL_TIME = false;
/** /**
* The data itself. * The data itself.
*/ */
...@@ -487,48 +478,20 @@ public class Data { ...@@ -487,48 +478,20 @@ public class Data {
break; break;
} }
case Value.TIME: case Value.TIME:
if (STORE_LOCAL_TIME) {
writeByte((byte) LOCAL_TIME);
ValueTime t = (ValueTime) v;
long nanos = t.getNanos();
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
writeVarLong(millis);
writeVarLong(nanos);
} else {
writeByte((byte) type); writeByte((byte) type);
writeVarLong(DateTimeUtils.getTimeLocalWithoutDst(v.getTime())); writeVarLong(DateTimeUtils.getTimeLocalWithoutDst(v.getTime()));
}
break; break;
case Value.DATE: { case Value.DATE: {
if (STORE_LOCAL_TIME) {
writeByte((byte) LOCAL_DATE);
long x = ((ValueDate) v).getDateValue();
writeVarLong(x);
} else {
writeByte((byte) type); writeByte((byte) type);
long x = DateTimeUtils.getTimeLocalWithoutDst(v.getDate()); long x = DateTimeUtils.getTimeLocalWithoutDst(v.getDate());
writeVarLong(x / MILLIS_PER_MINUTE); writeVarLong(x / MILLIS_PER_MINUTE);
}
break; break;
} }
case Value.TIMESTAMP: { case Value.TIMESTAMP: {
if (STORE_LOCAL_TIME) {
writeByte((byte) LOCAL_TIMESTAMP);
ValueTimestamp ts = (ValueTimestamp) v;
long dateValue = ts.getDateValue();
writeVarLong(dateValue);
long nanos = ts.getTimeNanos();
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
writeVarLong(millis);
writeVarLong(nanos);
} else {
Timestamp ts = v.getTimestamp(); Timestamp ts = v.getTimestamp();
writeByte((byte) type); writeByte((byte) type);
writeVarLong(DateTimeUtils.getTimeLocalWithoutDst(ts)); writeVarLong(DateTimeUtils.getTimeLocalWithoutDst(ts));
writeVarInt(ts.getNanos() % 1_000_000); writeVarInt(ts.getNanos() % 1_000_000);
}
break; break;
} }
case Value.TIMESTAMP_TZ: { case Value.TIMESTAMP_TZ: {
...@@ -1012,31 +975,12 @@ public class Data { ...@@ -1012,31 +975,12 @@ public class Data {
return 1 + getVarIntLen(scale) + getVarIntLen(bytes.length) + bytes.length; return 1 + getVarIntLen(scale) + getVarIntLen(bytes.length) + bytes.length;
} }
case Value.TIME: case Value.TIME:
if (STORE_LOCAL_TIME) {
long nanos = ((ValueTime) v).getNanos();
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
return 1 + getVarLongLen(millis) + getVarLongLen(nanos);
}
return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(v.getTime())); return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(v.getTime()));
case Value.DATE: { case Value.DATE: {
if (STORE_LOCAL_TIME) {
long dateValue = ((ValueDate) v).getDateValue();
return 1 + getVarLongLen(dateValue);
}
long x = DateTimeUtils.getTimeLocalWithoutDst(v.getDate()); long x = DateTimeUtils.getTimeLocalWithoutDst(v.getDate());
return 1 + getVarLongLen(x / MILLIS_PER_MINUTE); return 1 + getVarLongLen(x / MILLIS_PER_MINUTE);
} }
case Value.TIMESTAMP: { case Value.TIMESTAMP: {
if (STORE_LOCAL_TIME) {
ValueTimestamp ts = (ValueTimestamp) v;
long dateValue = ts.getDateValue();
long nanos = ts.getTimeNanos();
long millis = nanos / 1_000_000;
nanos -= millis * 1_000_000;
return 1 + getVarLongLen(dateValue) + getVarLongLen(millis) +
getVarLongLen(nanos);
}
Timestamp ts = v.getTimestamp(); Timestamp ts = v.getTimestamp();
return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(ts)) + return 1 + getVarLongLen(DateTimeUtils.getTimeLocalWithoutDst(ts)) +
getVarIntLen(ts.getNanos() % 1_000_000); getVarIntLen(ts.getNanos() % 1_000_000);
......
...@@ -42,7 +42,6 @@ public class TestDateStorage extends TestDb { ...@@ -42,7 +42,6 @@ public class TestDateStorage extends TestDb {
public void test() throws SQLException { public void test() throws SQLException {
deleteDb(getTestName()); deleteDb(getTestName());
testDateTimeTimestampWithCalendar(); testDateTimeTimestampWithCalendar();
testMoveDatabaseToAnotherTimezone();
testAllTimeZones(); testAllTimeZones();
testCurrentTimeZone(); testCurrentTimeZone();
} }
...@@ -150,91 +149,6 @@ public class TestDateStorage extends TestDb { ...@@ -150,91 +149,6 @@ public class TestDateStorage extends TestDb {
conn.close(); conn.close();
} }
private void testMoveDatabaseToAnotherTimezone() throws SQLException {
if (config.memory) {
return;
}
if (config.mvStore) {
return;
}
/**
* Disabled this test for now, explanation from Evgenij Ryazanov:<br>
* This test is executed only in PageStore mode because there is no
* reason to test it with MVStore that stores date-time values in local
* time.<br>
* There is a hard-coded configuration option for PageStore,
* org.h2.store.Data::STORE_LOCAL_TIME. <br>
* This test completes normally if this constant is changed to true.
* Probably this test was designed for this mode. But with
* STORE_LOCAL_TIME = false this test is useless. On Java 10 only 57% of
* conversions tested by this test are successful, the remaining 43%
* have different offsets due to differences in DST transitions between
* timezones.
*/
if (!config.mvStore) {
return;
}
String db = getTestName() + ";LOG=0;FILE_LOCK=NO";
Connection conn = getConnection(db);
Statement stat;
stat = conn.createStatement();
stat.execute("create table date_list(tz varchar, t varchar, ts timestamp)");
conn.close();
TimeZone defaultTimeZone = TimeZone.getDefault();
ArrayList<TimeZone> distinct = TestDate.getDistinctTimeZones();
try {
for (TimeZone tz : distinct) {
// println("insert using " + tz.getID());
TimeZone.setDefault(tz);
DateTimeUtils.resetCalendar();
conn = getConnection(db);
PreparedStatement prep = conn.prepareStatement(
"insert into date_list values(?, ?, ?)");
prep.setString(1, tz.getID());
for (int m = 1; m < 10; m++) {
String s = "2000-0" + m + "-01 15:00:00";
prep.setString(2, s);
prep.setTimestamp(3, Timestamp.valueOf(s));
prep.execute();
}
conn.close();
}
// printTime("inserted");
for (TimeZone target : distinct) {
// println("select from " + target.getID());
if ("Pacific/Kiritimati".equals(target.getID())) {
// there is a problem with this time zone, but it seems
// unrelated to this database (possibly wrong timezone
// information?)
continue;
}
TimeZone.setDefault(target);
DateTimeUtils.resetCalendar();
conn = getConnection(db);
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from date_list order by t");
while (rs.next()) {
String source = rs.getString(1);
String a = rs.getString(2);
String b = rs.getString(3);
b = b.substring(0, a.length());
if (!a.equals(b)) {
assertEquals(source + ">" + target, a, b);
}
}
conn.close();
}
} finally {
TimeZone.setDefault(defaultTimeZone);
DateTimeUtils.resetCalendar();
}
// printTime("done");
conn = getConnection(db);
stat = conn.createStatement();
stat.execute("drop table date_list");
conn.close();
}
private static void testCurrentTimeZone() { private static void testCurrentTimeZone() {
for (int year = 1890; year < 2050; year += 3) { for (int year = 1890; year < 2050; year += 3) {
for (int month = 1; month <= 12; month++) { for (int month = 1; month <= 12; month++) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论