提交 c722ed60 authored 作者: Thomas Mueller's avatar Thomas Mueller

Use constants where possible.

上级 42a65e3f
...@@ -431,11 +431,15 @@ public class Constants { ...@@ -431,11 +431,15 @@ public class Constants {
*/ */
public static final String SUFFIX_LOCK_FILE = ".lock.db"; public static final String SUFFIX_LOCK_FILE = ".lock.db";
/**
* The file name suffix of a H2 version 1.1 database file.
*/
public static final String SUFFIX_OLD_DATABASE_FILE = ".data.db";
/** /**
* The file name suffix of page files. * The file name suffix of page files.
*/ */
public static final String SUFFIX_PAGE_FILE = ".h2.db"; public static final String SUFFIX_PAGE_FILE = ".h2.db";
/** /**
* The file name suffix of a MVStore file. * The file name suffix of a MVStore file.
*/ */
......
...@@ -568,7 +568,7 @@ public class Database implements DataHandler { ...@@ -568,7 +568,7 @@ public class Database implements DataHandler {
private synchronized void open(int traceLevelFile, int traceLevelSystemOut) { private synchronized void open(int traceLevelFile, int traceLevelSystemOut) {
if (persistent) { if (persistent) {
String dataFileName = databaseName + ".data.db"; String dataFileName = databaseName + Constants.SUFFIX_OLD_DATABASE_FILE;
boolean existsData = FileUtils.exists(dataFileName); boolean existsData = FileUtils.exists(dataFileName);
String pageFileName = databaseName + Constants.SUFFIX_PAGE_FILE; String pageFileName = databaseName + Constants.SUFFIX_PAGE_FILE;
String mvFileName = databaseName + Constants.SUFFIX_MV_FILE; String mvFileName = databaseName + Constants.SUFFIX_MV_FILE;
......
...@@ -13,6 +13,7 @@ import java.sql.Statement; ...@@ -13,6 +13,7 @@ import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import org.h2.engine.ConnectionInfo; import org.h2.engine.ConnectionInfo;
import org.h2.engine.Constants;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
...@@ -62,10 +63,10 @@ public class DbUpgrade { ...@@ -62,10 +63,10 @@ public class DbUpgrade {
return null; return null;
} }
String name = ci.getName(); String name = ci.getName();
if (FileUtils.exists(name + ".h2.db")) { if (FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE)) {
return null; return null;
} }
if (!FileUtils.exists(name + ".data.db")) { if (!FileUtils.exists(name + Constants.SUFFIX_OLD_DATABASE_FILE)) {
return null; return null;
} }
if (ci.removeProperty("NO_UPGRADE", false)) { if (ci.removeProperty("NO_UPGRADE", false)) {
...@@ -110,7 +111,7 @@ public class DbUpgrade { ...@@ -110,7 +111,7 @@ public class DbUpgrade {
private static void upgrade(ConnectionInfo ci, Properties info) private static void upgrade(ConnectionInfo ci, Properties info)
throws SQLException { throws SQLException {
String name = ci.getName(); String name = ci.getName();
String data = name + ".data.db"; String data = name + Constants.SUFFIX_OLD_DATABASE_FILE;
String index = name + ".index.db"; String index = name + ".index.db";
String lobs = name + ".lobs.db"; String lobs = name + ".lobs.db";
String backupData = data + ".backup"; String backupData = data + ".backup";
......
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
*/ */
package org.h2.test.db; package org.h2.test.db;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import org.h2.engine.Constants;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
...@@ -32,24 +33,32 @@ public class TestSpaceReuse extends TestBase { ...@@ -32,24 +33,32 @@ public class TestSpaceReuse extends TestBase {
return; return;
} }
deleteDb("spaceReuse"); deleteDb("spaceReuse");
long first = 0, now = 0; long max = 0, now = 0, min = Long.MAX_VALUE;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 20; i++) {
Connection conn = getConnection("spaceReuse"); Connection conn = getConnection("spaceReuse");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("set retention_time 0");
stat.execute("create table if not exists t(i int)"); stat.execute("create table if not exists t(i int)");
stat.execute("insert into t select x from system_range(1, 500)"); stat.execute("insert into t select x from system_range(1, 500)");
conn.close(); conn.close();
conn = getConnection("spaceReuse"); conn = getConnection("spaceReuse");
conn.createStatement().execute("delete from t"); conn.createStatement().execute("delete from t");
conn.close(); conn.close();
now = new File(getBaseDir() + "/spaceReuse.data.db").length(); String fileName = getBaseDir() + "/spaceReuse";
if (first == 0) { if (Constants.VERSION_MINOR >= 4) {
first = now; fileName += Constants.SUFFIX_MV_FILE;
} else {
fileName += Constants.SUFFIX_PAGE_FILE;
}
now = FileUtils.size(fileName);
assertTrue(now > 0);
if (i < 10) {
max = Math.max(max, now);
} else {
min = Math.min(min, now);
} }
} }
if (now > first) { assertTrue("min: " + min + " max: " + max, min <= max);
fail("first: " + first + " now: " + now);
}
deleteDb("spaceReuse"); deleteDb("spaceReuse");
} }
......
...@@ -73,7 +73,7 @@ public class Migrate { ...@@ -73,7 +73,7 @@ public class Migrate {
} }
return; return;
} }
if (!file.getName().endsWith(".data.db")) { if (!file.getName().endsWith(Constants.SUFFIX_OLD_DATABASE_FILE)) {
return; return;
} }
println("Migrating " + file.getName()); println("Migrating " + file.getName());
...@@ -81,7 +81,7 @@ public class Migrate { ...@@ -81,7 +81,7 @@ public class Migrate {
download(OLD_H2_FILE.getAbsolutePath(), DOWNLOAD_URL, CHECKSUM); download(OLD_H2_FILE.getAbsolutePath(), DOWNLOAD_URL, CHECKSUM);
} }
String url = "jdbc:h2:" + file.getAbsolutePath(); String url = "jdbc:h2:" + file.getAbsolutePath();
url = url.substring(0, url.length() - ".data.db".length()); url = url.substring(0, url.length() - Constants.SUFFIX_OLD_DATABASE_FILE.length());
exec(new String[] { exec(new String[] {
pathToJavaExe, pathToJavaExe,
"-Xmx128m", "-Xmx128m",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论