提交 16380c5b authored 作者: Thomas Mueller's avatar Thomas Mueller

New experimental page store.

上级 047ecea7
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Result sets are now read-only except if the statement or prepared statement was created
<ul><li>H2 Console: Oracle system tables are no longer listed, improving performance.
</li><li>Result sets are now read-only except if the statement or prepared statement was created
with the concurrency ResultSet.CONCUR_UPDATABLE. This change is required because the old behavior
(all result set are updatable) violated the JDBC spec. For backward compatibility, use the
system property h2.defaultResultSetConcurrency.
......@@ -32,7 +33,9 @@ Change Log
and in some cases (specially when using the Lucene fulltext index mechanism) a NullPointerException was
thrown later on. Now the exception that occurred on init is thrown when changing data.
</li><li>The soft-references cache (CACHE_TYPE=SOFT_LRU) could throw a NullPointerException.
</li><li>Bugfixes in the new storage mechanism (page store).
</li><li>To enable the new page store mechanism, append ;PAGE_STORE=TRUE to the database URL.
or set the system property h2.pageStore to true.
This mechanism is still experimental, and the file format will change.
</li></ul>
<h2>Version 1.1.115 (2009-06-21)</h2>
......
......@@ -4053,6 +4053,10 @@ public class Parser {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("PAGE_STORE")) {
readIfEqualOrTo();
read();
return new NoOperation(session);
} else if (readIf("CACHE_TYPE")) {
readIfEqualOrTo();
read();
......
......@@ -13,11 +13,9 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.h2.api.DatabaseEventListener;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -71,7 +69,7 @@ public class BackupCommand extends Prepared {
log.flush();
log.updateKeepFiles(1);
String fn;
if (SysProperties.PAGE_STORE) {
if (db.isPageStoreEnabled()) {
fn = db.getName() + Constants.SUFFIX_PAGE_FILE;
backupPageStore(out, fn, db.getPageStore());
} else {
......@@ -84,7 +82,7 @@ public class BackupCommand extends Prepared {
// creation / deletion / backup
String base = FileUtils.getParent(fn);
synchronized (db.getLobSyncObject()) {
if (!SysProperties.PAGE_STORE) {
if (!db.isPageStoreEnabled()) {
ObjectArray<LogFile> list = log.getActiveLogFiles();
int max = list.size();
for (int i = 0; i < list.size(); i++) {
......
......@@ -40,6 +40,11 @@ public class SysProperties {
*/
public static final String H2_COLLATOR_CACHE_SIZE = "h2.collatorCacheSize";
/**
* INTERNAL
*/
public static final String H2_PAGE_STORE = "h2.pageStore";
/**
* System property <code>file.encoding</code> (default: Cp1252).<br />
* It is usually set by the system and is the default encoding used for the
......@@ -467,12 +472,6 @@ public class SysProperties {
*/
public static final boolean OVERFLOW_EXCEPTIONS = getBooleanSetting("h2.overflowExceptions", true);
/**
* System property <code>h2.pageStore</code> (default: false).<br />
* Use the page store file format (experimental).
*/
public static final boolean PAGE_STORE = getBooleanSetting("h2.pageStore", false);
/**
* System property <code>h2.recompileAlways</code> (default: false).<br />
* Always recompile prepared statements.
......@@ -716,4 +715,12 @@ public class SysProperties {
public static int getCollatorCacheSize() {
return getIntSetting(H2_COLLATOR_CACHE_SIZE, 32000);
}
/**
* INTERNAL
*/
public static boolean getPageStore() {
return getBooleanSetting(H2_PAGE_STORE, false);
}
}
......@@ -82,7 +82,7 @@ public class ConnectionInfo implements Cloneable {
String[] connectionTime = new String[] { "ACCESS_MODE_LOG", "ACCESS_MODE_DATA", "AUTOCOMMIT", "CIPHER",
"CREATE", "CACHE_TYPE", "DB_CLOSE_ON_EXIT", "FILE_LOCK", "IGNORE_UNKNOWN_SETTINGS", "IFEXISTS",
"PASSWORD", "RECOVER", "USER", "DATABASE_EVENT_LISTENER_OBJECT", "AUTO_SERVER",
"AUTO_RECONNECT", "OPEN_NEW" };
"AUTO_RECONNECT", "OPEN_NEW", "PAGE_STORE" };
for (String key : connectionTime) {
if (SysProperties.CHECK && set.contains(key)) {
Message.throwInternalError(key);
......@@ -321,7 +321,7 @@ public class ConnectionInfo implements Cloneable {
String getName() throws SQLException {
if (persistent) {
String suffix;
if (SysProperties.PAGE_STORE) {
if (SysProperties.getPageStore()) {
suffix = Constants.SUFFIX_PAGE_FILE;
} else {
suffix = Constants.SUFFIX_DATA_FILE;
......
......@@ -162,6 +162,7 @@ public class Database implements DataHandler {
private HashMap<TableLinkConnection, TableLinkConnection> linkConnections;
private TempFileDeleter tempFileDeleter = TempFileDeleter.getInstance();
private PageStore pageStore;
private boolean usePageStore;
private Properties reconnectLastLock;
private volatile long reconnectCheckNext;
......@@ -178,6 +179,7 @@ public class Database implements DataHandler {
this.accessModeLog = ci.getProperty("ACCESS_MODE_LOG", "rw").toLowerCase();
this.accessModeData = ci.getProperty("ACCESS_MODE_DATA", "rw").toLowerCase();
this.autoServerMode = ci.getProperty("AUTO_SERVER", false);
this.usePageStore = ci.getProperty("PAGE_STORE", SysProperties.getPageStore());
if ("r".equals(accessModeData)) {
readOnly = true;
accessModeLog = "r";
......@@ -453,10 +455,7 @@ public class Database implements DataHandler {
* @return true if one exists
*/
public static boolean exists(String name) {
if (SysProperties.PAGE_STORE) {
return FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE);
}
return FileUtils.exists(name + Constants.SUFFIX_DATA_FILE);
return FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE) | FileUtils.exists(name + Constants.SUFFIX_DATA_FILE);
}
/**
......@@ -530,10 +529,12 @@ public class Database implements DataHandler {
private synchronized void open(int traceLevelFile, int traceLevelSystemOut) throws SQLException {
if (persistent) {
boolean exists;
if (SysProperties.PAGE_STORE) {
String pageFileName = databaseName + Constants.SUFFIX_PAGE_FILE;
exists = FileUtils.exists(pageFileName);
boolean exists = FileUtils.exists(pageFileName);
if (exists) {
usePageStore = true;
}
if (usePageStore) {
if (exists && FileUtils.isReadOnly(pageFileName)) {
readOnly = true;
}
......@@ -577,7 +578,7 @@ public class Database implements DataHandler {
}
dummy = DataPage.create(this, 0);
deleteOldTempFiles();
if (SysProperties.PAGE_STORE) {
if (usePageStore) {
starting = true;
getPageStore();
starting = false;
......@@ -2218,7 +2219,7 @@ public class Database implements DataHandler {
}
public PageStore getPageStore() throws SQLException {
if (pageStore == null && SysProperties.PAGE_STORE) {
if (pageStore == null && usePageStore) {
pageStore = new PageStore(this, databaseName + Constants.SUFFIX_PAGE_FILE, accessModeData,
SysProperties.CACHE_SIZE_DEFAULT);
pageStore.open();
......@@ -2226,6 +2227,10 @@ public class Database implements DataHandler {
return pageStore;
}
public boolean isPageStoreEnabled() {
return usePageStore;
}
/**
* Get the first user defined table.
*
......@@ -2347,12 +2352,12 @@ public class Database implements DataHandler {
* Flush all changes and open a new log file.
*/
public void checkpoint() throws SQLException {
if (SysProperties.PAGE_STORE) {
if (persistent) {
if (pageStore != null) {
pageStore.checkpoint();
}
}
getLog().checkpoint();
}
getTempFileDeleter().deleteUnused();
}
......
......@@ -7,8 +7,6 @@
package org.h2.result;
import java.sql.SQLException;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.Session;
import org.h2.index.BtreeIndex;
......@@ -54,7 +52,7 @@ public class ResultTempTable implements ResultExternal {
IndexType indexType;
indexType = IndexType.createPrimaryKey(true, false);
IndexColumn[] indexCols = new IndexColumn[]{indexColumn};
if (SysProperties.PAGE_STORE) {
if (session.getDatabase().isPageStoreEnabled()) {
index = new PageBtreeIndex(table, indexId, tableName, indexCols, indexType, Index.EMPTY_HEAD, session);
} else {
index = new BtreeIndex(session, table, indexId, tableName, indexCols, indexType, Index.EMPTY_HEAD);
......
......@@ -81,7 +81,7 @@ public class RowList {
private void writeAllRows() throws SQLException {
if (file == null) {
Database db = session.getDatabase();
if (!SysProperties.PAGE_STORE) {
if (!db.isPageStoreEnabled()) {
cache = db.getDataFile().getCache();
}
String fileName = db.createTempFile();
......
......@@ -8,8 +8,6 @@ package org.h2.store;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.util.FileUtils;
import org.h2.util.New;
......@@ -31,15 +29,11 @@ public class FileLister {
* @return the database name or null
*/
public static String getDatabaseNameFromFileName(String fileName) {
if (SysProperties.PAGE_STORE) {
if (fileName.endsWith(Constants.SUFFIX_PAGE_FILE)) {
return fileName.substring(0, fileName.length() - Constants.SUFFIX_PAGE_FILE.length());
}
} else {
if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
} else if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
return fileName.substring(0, fileName.length() - Constants.SUFFIX_DATA_FILE.length());
}
}
return null;
}
......
......@@ -100,6 +100,7 @@ public class FileLock {
private Properties properties;
private boolean locked;
private String uniqueId;
private Thread watchdog;
/**
* Create a new file locking object.
......@@ -191,13 +192,6 @@ public class FileLock {
}
}
// void kill() {
// socket = null;
// file = null;
// locked = false;
// trace("killed", null);
// }
/**
* Save the lock file.
*
......@@ -348,7 +342,7 @@ public class FileLock {
fileName = null;
throw getExceptionFatal("Concurrent update", null);
}
Thread watchdog = new Thread(new Runnable() {
watchdog = new Thread(new Runnable() {
public void run() {
try {
while (fileName != null) {
......@@ -440,7 +434,7 @@ public class FileLock {
return;
}
save();
Thread watchdog = new Thread(new Runnable() {
watchdog = new Thread(new Runnable() {
public void run() {
while (socket != null) {
try {
......
......@@ -72,7 +72,7 @@ public class TableData extends Table implements RecordReader {
setColumns(cols);
this.clustered = clustered;
if (!clustered) {
if (SysProperties.PAGE_STORE && persistData && database.isPersistent()) {
if (database.isPageStoreEnabled() && persistData && database.isPersistent()) {
scanIndex = new PageScanIndex(this, id, IndexColumn.wrap(cols), IndexType.createScan(persistData), headPos, session);
} else {
scanIndex = new ScanIndex(this, id, IndexColumn.wrap(cols), IndexType.createScan(persistData));
......@@ -179,7 +179,7 @@ public class TableData extends Table implements RecordReader {
}
Index index;
if (isPersistIndexes() && indexType.getPersistent()) {
if (SysProperties.PAGE_STORE) {
if (database.isPageStoreEnabled()) {
index = new PageBtreeIndex(this, indexId, indexName, cols, indexType, headPos, session);
} else {
index = new BtreeIndex(session, this, indexId, indexName, cols, indexType, headPos);
......@@ -242,7 +242,7 @@ public class TableData extends Table implements RecordReader {
}
// must not do this when using the page store
// because recovery is not done yet
if (!SysProperties.PAGE_STORE) {
if (!database.isPageStoreEnabled()) {
// need to update, because maybe the index is rebuilt at startup,
// and so the head pos may have changed, which needs to be stored now.
// addSchemaObject doesn't update the sys table at startup
......
......@@ -14,9 +14,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.h2.command.dml.BackupCommand;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.message.Message;
import org.h2.store.FileLister;
......@@ -108,14 +106,12 @@ public class Backup extends Tool {
ZipOutputStream zipOut = new ZipOutputStream(fileOut);
String base = "";
for (String fileName : list) {
if (SysProperties.PAGE_STORE) {
if (fileName.endsWith(Constants.SUFFIX_PAGE_FILE)) {
base = FileUtils.getParent(fileName);
}
} else {
if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
break;
} else if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
base = FileUtils.getParent(fileName);
}
break;
}
}
for (String fileName : list) {
......
......@@ -24,7 +24,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.zip.CRC32;
import org.h2.command.Parser;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.DbObject;
import org.h2.engine.MetaRecord;
......@@ -133,11 +132,10 @@ public class Recover extends Tool implements DataHandler {
throwUnsupportedOption(arg);
}
}
if (!SysProperties.PAGE_STORE && remove) {
if (remove) {
removePassword(dir, db);
} else {
process(dir, db);
}
process(dir, db);
}
/**
......@@ -156,9 +154,6 @@ public class Recover extends Tool implements DataHandler {
private void removePassword(String dir, String db) throws SQLException {
ArrayList<String> list = FileLister.getDatabaseFiles(dir, db, true);
if (list.size() == 0) {
printNoDatabaseFilesFound(dir, db);
}
for (String fileName : list) {
if (fileName.endsWith(Constants.SUFFIX_DATA_FILE)) {
removePassword(fileName);
......
......@@ -9,6 +9,7 @@ package org.h2.test;
import java.sql.SQLException;
import java.util.Properties;
import org.h2.Driver;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.store.fs.FileSystemDisk;
import org.h2.test.bench.TestPerformance;
......@@ -80,10 +81,8 @@ import org.h2.test.mvcc.TestMvcc2;
import org.h2.test.mvcc.TestMvcc3;
import org.h2.test.mvcc.TestMvccMultiThreaded;
import org.h2.test.rowlock.TestRowLocks;
import org.h2.test.server.TestAutoReconnect;
import org.h2.test.server.TestAutoServer;
import org.h2.test.server.TestNestedLoop;
import org.h2.test.server.TestPgServer;
import org.h2.test.server.TestWeb;
import org.h2.test.synth.TestBtreeIndex;
import org.h2.test.synth.TestCrashAPI;
......@@ -99,6 +98,7 @@ import org.h2.test.synth.TestTimer;
import org.h2.test.synth.sql.TestSynth;
import org.h2.test.synth.thread.TestMulti;
import org.h2.test.unit.SelfDestructor;
import org.h2.test.unit.TestAutoReconnect;
import org.h2.test.unit.TestBitField;
import org.h2.test.unit.TestCache;
import org.h2.test.unit.TestClearReferences;
......@@ -117,6 +117,7 @@ import org.h2.test.unit.TestMathUtils;
import org.h2.test.unit.TestMultiThreadedKernel;
import org.h2.test.unit.TestOverflow;
import org.h2.test.unit.TestPattern;
import org.h2.test.unit.TestPgServer;
import org.h2.test.unit.TestReader;
import org.h2.test.unit.TestRecovery;
import org.h2.test.unit.TestSampleApps;
......@@ -162,6 +163,11 @@ java org.h2.test.TestAll timer
*/
/**
* If the test should run with the page store flag.
*/
public boolean pageStore;
/**
* If the test should run with many rows.
*/
......@@ -285,8 +291,6 @@ java org.h2.test.TestAll timer
System.setProperty("h2.maxMemoryRowsDistinct", "128");
System.setProperty("h2.check2", "true");
// System.setProperty("h2.pageStore", "true");
/*
create a short documentation
......@@ -328,7 +332,13 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
new TestTimer().runTest(test);
}
} else {
System.setProperty(SysProperties.H2_PAGE_STORE, "false");
test.pageStore = false;
test.runTests();
System.setProperty(SysProperties.H2_PAGE_STORE, "true");
test.pageStore = true;
int todo;
// test.runTests();
TestPerformance.main(new String[]{ "-init", "-db", "1"});
}
System.out.println(TestBase.formatTime(System.currentTimeMillis() - time) + " total");
......@@ -508,11 +518,9 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
new TestXASimple().runTest(this);
// server
new TestAutoReconnect().runTest(this);
new TestAutoServer().runTest(this);
new TestNestedLoop().runTest(this);
new TestWeb().runTest(this);
new TestPgServer().runTest(this);
// mvcc & row level locking
new TestMvcc1().runTest(this);
......@@ -534,6 +542,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
}
private void testUnit() {
new TestAutoReconnect().runTest(this);
new TestBitField().runTest(this);
new TestCache().runTest(this);
new TestClearReferences().runTest(this);
......@@ -552,6 +561,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
new TestMultiThreadedKernel().runTest(this);
new TestOverflow().runTest(this);
new TestPattern().runTest(this);
new TestPgServer().runTest(this);
new TestReader().runTest(this);
new TestRecovery().runTest(this);
new TestSampleApps().runTest(this);
......@@ -635,6 +645,7 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
public String toString() {
StringBuilder buff = new StringBuilder();
appendIf(buff, pageStore, "pageStore");
appendIf(buff, big, "big");
appendIf(buff, networked, "net");
appendIf(buff, memory, "memory");
......@@ -664,4 +675,5 @@ kill -9 `jps -l | grep "org.h2.test.TestAll" | cut -d " " -f 1`
buff.append(' ');
}
}
}
......@@ -250,6 +250,9 @@ public abstract class TestBase {
if (config.cipher != null) {
url += ";CIPHER=" + config.cipher;
}
if (config.pageStore) {
url += ";PAGE_STORE=TRUE";
}
return "jdbc:h2:" + url;
}
......@@ -1056,4 +1059,13 @@ public abstract class TestBase {
return "temp" + File.pathSeparator + "bin" + File.pathSeparator + ".";
}
/**
* Get the page store property to use when starting new processes.
*
* @return the property
*/
public String getPageStoreProperty() {
return "-Dh2.pageStore=" + System.getProperty("h2.pageStore");
}
}
......@@ -41,7 +41,9 @@ public class TestCluster extends TestBase {
// create the master database
Connection conn;
org.h2.Driver.load();
conn = DriverManager.getConnection("jdbc:h2:file:" + baseDir + "/node1/test", "sa", "");
String urlNode1 = getURL("node1/test", true);
String urlNode2 = getURL("node2/test", true);
conn = DriverManager.getConnection(urlNode1, "sa", "");
Statement stat;
stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS TEST");
......@@ -56,8 +58,8 @@ public class TestCluster extends TestBase {
check(conn, len);
conn.close();
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
"jdbc:h2:file:" + baseDir + "/node2/test", "-user", "sa", "-serverList",
CreateCluster.main(new String[] { "-urlSource", urlNode1, "-urlTarget",
urlNode2, "-user", "sa", "-serverList",
"localhost:9191,localhost:9192" });
Server n1 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9191", "-baseDir", baseDir + "/node1" }).start();
......@@ -97,8 +99,8 @@ public class TestCluster extends TestBase {
// re-create the cluster
DeleteDbFiles.main(new String[] { "-dir", baseDir + "/node2", "-quiet" });
CreateCluster.main(new String[] { "-urlSource", "jdbc:h2:file:" + baseDir + "/node1/test", "-urlTarget",
"jdbc:h2:file:" + baseDir + "/node2/test", "-user", "sa", "-serverList",
CreateCluster.main(new String[] { "-urlSource", urlNode1, "-urlTarget",
urlNode2, "-user", "sa", "-serverList",
"localhost:9191,localhost:9192" });
n1 = org.h2.tools.Server.createTcpServer(
new String[] { "-tcpPort", "9191", "-baseDir", baseDir + "/node1" }).start();
......
......@@ -238,16 +238,19 @@ public class TestLinkedTable extends TestBase {
deleteDb("linked2");
org.h2.Driver.load();
Connection conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked1", "sa1", "abc");
String url1 = getURL("linked1", true);
String url2 = getURL("linked2", true);
Connection conn = DriverManager.getConnection(url1, "sa1", "abc");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
Connection conn2 = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked2", "sa2", "def");
Connection conn2 = DriverManager.getConnection(url2, "sa2", "def");
Statement stat2 = conn2.createStatement();
String link = "CREATE LINKED TABLE TEST_LINK_U('', 'jdbc:h2:" + baseDir
+ "/linked1', 'sa1', 'abc', 'TEST') EMIT UPDATES";
String link = "CREATE LINKED TABLE TEST_LINK_U('', '" + url1
+ "', 'sa1', 'abc', 'TEST') EMIT UPDATES";
stat2.execute(link);
link = "CREATE LINKED TABLE TEST_LINK_DI('', 'jdbc:h2:" + baseDir + "/linked1', 'sa1', 'abc', 'TEST')";
link = "CREATE LINKED TABLE TEST_LINK_DI('', '" + url1 + "', 'sa1', 'abc', 'TEST')";
stat2.execute(link);
stat2.executeUpdate("INSERT INTO TEST_LINK_U VALUES(1, 'Hello')");
stat2.executeUpdate("INSERT INTO TEST_LINK_DI VALUES(2, 'World')");
......@@ -296,14 +299,16 @@ public class TestLinkedTable extends TestBase {
deleteDb("linked1");
deleteDb("linked2");
org.h2.Driver.load();
String url1 = getURL("linked1", true);
String url2 = getURL("linked2", true);
Connection conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked1", "sa1", "abc");
Connection conn = DriverManager.getConnection(url1, "sa1", "abc");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST1(ID INT PRIMARY KEY)");
Connection conn2 = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked2", "sa2", "def");
Connection conn2 = DriverManager.getConnection(url2, "sa2", "def");
Statement stat2 = conn2.createStatement();
String link = "CALL LINK_SCHEMA('LINKED', '', 'jdbc:h2:" + baseDir + "/linked1', 'sa1', 'abc', 'PUBLIC')";
String link = "CALL LINK_SCHEMA('LINKED', '', '" + url1 + "', 'sa1', 'abc', 'PUBLIC')";
stat2.execute(link);
stat2.executeQuery("SELECT * FROM LINKED.TEST1");
......@@ -321,24 +326,23 @@ public class TestLinkedTable extends TestBase {
deleteDb("linked2");
org.h2.Driver.load();
Connection conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked1", "sa1", "abc");
String url1 = getURL("linked1", true);
String url2 = getURL("linked2", true);
Connection conn = DriverManager.getConnection(url1, "sa1", "abc");
Statement stat = conn.createStatement();
stat.execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY)");
stat
.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(200), XT TINYINT, XD DECIMAL(10,2), XTS TIMESTAMP, XBY BINARY(255), XBO BIT, XSM SMALLINT, XBI BIGINT, XBL BLOB, XDA DATE, XTI TIME, XCL CLOB, XDO DOUBLE)");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(200), XT TINYINT, XD DECIMAL(10,2), XTS TIMESTAMP, XBY BINARY(255), XBO BIT, XSM SMALLINT, XBI BIGINT, XBL BLOB, XDA DATE, XTI TIME, XCL CLOB, XDO DOUBLE)");
stat.execute("CREATE INDEX IDXNAME ON TEST(NAME)");
stat
.execute("INSERT INTO TEST VALUES(0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
stat
.execute("INSERT INTO TEST VALUES(1, 'Hello', -1, 10.30, '2001-02-03 11:22:33.4455', X'FF0102', TRUE, 3000, 1234567890123456789, X'1122AA', DATE '0002-01-01', TIME '00:00:00', 'J\u00fcrg', 2.25)");
stat.execute("INSERT INTO TEST VALUES(0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello', -1, 10.30, '2001-02-03 11:22:33.4455', X'FF0102', TRUE, 3000, 1234567890123456789, X'1122AA', DATE '0002-01-01', TIME '00:00:00', 'J\u00fcrg', 2.25)");
testRow(stat, "TEST");
stat
.execute("INSERT INTO TEST VALUES(2, 'World', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)");
stat.execute("INSERT INTO TEST VALUES(2, 'World', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)");
testRow(stat, "TEST");
stat.execute("SELECT * FROM TEST_TEMP");
conn.close();
conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked1", "sa1", "abc");
conn = DriverManager.getConnection(url1, "sa1", "abc");
stat = conn.createStatement();
testRow(stat, "TEST");
try {
......@@ -349,12 +353,12 @@ public class TestLinkedTable extends TestBase {
}
conn.close();
conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked2", "sa2", "def");
conn = DriverManager.getConnection(url2, "sa2", "def");
stat = conn.createStatement();
stat.execute("CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', 'jdbc:h2:" + baseDir
+ "/linked1', 'sa1', 'abc', 'TEST')");
stat.execute("CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', 'jdbc:h2:" + baseDir
+ "/linked1', 'sa1', 'abc', 'TEST')");
stat.execute("CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', '" + url1
+ "', 'sa1', 'abc', 'TEST')");
stat.execute("CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', '" + url1
+ "', 'sa1', 'abc', 'TEST')");
testRow(stat, "LINK_TEST");
ResultSet rs = stat.executeQuery("SELECT * FROM LINK_TEST");
ResultSetMetaData meta = rs.getMetaData();
......@@ -362,11 +366,10 @@ public class TestLinkedTable extends TestBase {
assertEquals(200, meta.getPrecision(2));
conn.close();
conn = DriverManager.getConnection("jdbc:h2:" + baseDir + "/linked2", "sa2", "def");
conn = DriverManager.getConnection(url2, "sa2", "def");
stat = conn.createStatement();
stat
.execute("INSERT INTO LINK_TEST VALUES(3, 'Link Test', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)");
stat.execute("INSERT INTO LINK_TEST VALUES(3, 'Link Test', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)");
rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST");
rs.next();
......@@ -408,8 +411,8 @@ public class TestLinkedTable extends TestBase {
stat.execute("DROP TABLE LINK_TEST");
stat.execute("CREATE LINKED TABLE LINK_TEST('org.h2.Driver', 'jdbc:h2:" + baseDir
+ "/linked1', 'sa1', 'abc', '(SELECT COUNT(*) FROM TEST)')");
stat.execute("CREATE LINKED TABLE LINK_TEST('org.h2.Driver', '" + url1
+ "', 'sa1', 'abc', '(SELECT COUNT(*) FROM TEST)')");
rs = stat.executeQuery("SELECT * FROM LINK_TEST");
rs.next();
assertEquals(rs.getInt(1), 3);
......@@ -441,7 +444,6 @@ public class TestLinkedTable extends TestBase {
assertEquals(rs.getString("XTI"), "00:00:00");
assertEquals(rs.getString("XCL"), "J\u00fcrg");
assertEquals(rs.getString("XDO"), "2.25");
}
}
......@@ -36,15 +36,14 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
public void test() throws Exception {
testCloseDelay();
testBackup(false);
testBackup(true);
testBackup();
testCase();
testReconnectFast();
deleteDb("openClose");
}
private void testCloseDelay() throws Exception {
deleteDb(baseDir, "openClose");
deleteDb("openClose");
String url = getURL("openClose;DB_CLOSE_DELAY=1", true);
String user = getUser(), password = getPassword();
Connection conn = DriverManager.getConnection(url, user, password);
......@@ -60,14 +59,9 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
conn.close();
}
private void testBackup(boolean encrypt) throws SQLException {
deleteDb(baseDir, "openClose");
String url;
if (encrypt) {
url = "jdbc:h2:" + baseDir + "/openClose;CIPHER=XTEA";
} else {
url = "jdbc:h2:" + baseDir + "/openClose";
}
private void testBackup() throws SQLException {
deleteDb("openClose");
String url = getURL("openClose", true);
org.h2.Driver.load();
Connection conn = DriverManager.getConnection(url, "sa", "abc def");
Statement stat = conn.createStatement();
......@@ -75,7 +69,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
stat.execute("INSERT INTO TEST VALUES(SPACE(10000))");
stat.execute("BACKUP TO '" + baseDir + "/test.zip'");
conn.close();
deleteDb(baseDir, "openClose");
deleteDb("openClose");
Restore.execute(baseDir + "/test.zip", baseDir, null, true);
conn = DriverManager.getConnection(url, "sa", "abc def");
stat = conn.createStatement();
......@@ -88,9 +82,9 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
}
private void testReconnectFast() throws SQLException {
deleteDb(baseDir, "openClose");
String url = "jdbc:h2:" + baseDir + "/openClose;DATABASE_EVENT_LISTENER='" + TestOpenClose.class.getName()
+ "'";
deleteDb("openClose");
String url = getURL("openClose;DATABASE_EVENT_LISTENER='" + TestOpenClose.class.getName()
+ "'", true);
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
try {
......@@ -122,8 +116,8 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
private void testCase() throws Exception {
org.h2.Driver.load();
deleteDb(baseDir, "openClose");
final String url = "jdbc:h2:" + baseDir + "/openClose;FILE_LOCK=NO";
deleteDb("openClose");
final String url = getURL("openClose;FILE_LOCK=NO", true);
Connection conn = DriverManager.getConnection(url, "sa", "");
conn.createStatement().execute("drop table employee if exists");
conn.createStatement().execute("create table employee(id int primary key, name varchar, salary int)");
......
......@@ -179,7 +179,7 @@ public class TestPowerOff extends TestBase {
} catch (SQLException e) {
assertKnownException(e);
}
if (!SysProperties.PAGE_STORE) {
if (!config.pageStore) {
boolean deleted = false;
for (String fileName : FileLister.getDatabaseFiles(dir, dbName, false)) {
if (fileName.endsWith(Constants.SUFFIX_INDEX_FILE)) {
......
......@@ -51,13 +51,13 @@ public class TestDataSource extends TestBase {
public void test() throws Exception {
testDataSource();
testXAConnection();
deleteDb(baseDir, "dataSource");
deleteDb("dataSource");
}
private void testXAConnection() throws Exception {
deleteDb(baseDir, "dataSource");
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:" + baseDir + "/dataSource");
ds.setURL(getURL("dataSource", true));
XAConnection xaConn = ds.getXAConnection();
xaConn.addConnectionEventListener(new ConnectionEventListener() {
public void connectionClosed(ConnectionEvent event) {
......@@ -79,9 +79,9 @@ public class TestDataSource extends TestBase {
}
private void testDataSource() throws SQLException {
deleteDb(baseDir, "dataSource");
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:" + baseDir + "/dataSource");
ds.setURL(getURL("dataSource", true));
ds.setUser("sa");
Connection conn = ds.getConnection();
Statement stat = conn.createStatement();
......
......@@ -25,8 +25,6 @@ public class TestXA extends TestBase {
private static final String DB_NAME1 = "xadb1";
private static final String DB_NAME2 = "xadb2";
private static final String DB_URL1 = "jdbc:h2:file:" + baseDir + "/" + DB_NAME1;
private static final String DB_URL2 = "jdbc:h2:file:" + baseDir + "/" + DB_NAME2;
/**
* Run just this test.
......@@ -39,14 +37,14 @@ public class TestXA extends TestBase {
public void test() throws Exception {
testXAAutoCommit();
deleteDb(baseDir, "xa");
deleteDb("xa");
testXA(true);
deleteDb(baseDir, DB_NAME1);
deleteDb(baseDir, DB_NAME2);
deleteDb(DB_NAME1);
deleteDb(DB_NAME2);
testXA(false);
deleteDb(baseDir, "xa");
deleteDb(baseDir, DB_NAME1);
deleteDb(baseDir, DB_NAME2);
deleteDb("xa");
deleteDb(DB_NAME1);
deleteDb(DB_NAME2);
}
/**
......@@ -81,6 +79,9 @@ public class TestXA extends TestBase {
}
private void testXA(boolean useOneDatabase) {
String url1 = getURL(DB_NAME1, true);
String url2 = getURL(DB_NAME2, true);
XAConnection xaConn1 = null;
XAConnection xaConn2 = null;
Connection conn1 = null;
......@@ -89,9 +90,9 @@ public class TestXA extends TestBase {
Statement stat2 = null;
try {
trace("xads1 = createXADatasource1()");
XADataSource xaDs1 = createXADatasource(useOneDatabase, DB_URL1);
XADataSource xaDs1 = createXADatasource(useOneDatabase, url1);
trace("xads2 = createXADatasource2()");
XADataSource xaDs2 = createXADatasource(useOneDatabase, DB_URL2);
XADataSource xaDs2 = createXADatasource(useOneDatabase, url2);
trace("xacon1 = xads1.getXAConnection()");
xaConn1 = xaDs1.getXAConnection();
......
......@@ -40,12 +40,12 @@ public class TestXASimple extends TestBase {
JdbcDataSource ds1 = new JdbcDataSource();
ds1.setPassword("");
ds1.setUser("sa");
ds1.setURL("jdbc:h2:" + baseDir + "/xaSimple1");
ds1.setURL(getURL("xaSimple1", true));
JdbcDataSource ds2 = new JdbcDataSource();
ds2.setPassword("");
ds2.setUser("sa");
ds2.setURL("jdbc:h2:" + baseDir + "/xaSimple2");
ds2.setURL(getURL("xaSimple2", true));
// UserTransaction ut = (UserTransaction)
// context.lookup("UserTransaction");
......
......@@ -229,7 +229,7 @@ public class TestCrashAPI extends TestBase {
} catch (Throwable t) {
printIfBad(seed, -101010, -1, t);
try {
deleteDb(null, "test");
deleteDb();
} catch (Throwable t2) {
printIfBad(seed, -101010, -1, t2);
}
......
......@@ -233,7 +233,7 @@ public abstract class TestHalt extends TestBase {
// String classPath = "-cp
// .;D:/data/java/hsqldb.jar;D:/data/java/derby.jar";
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] { "java", selfDestruct,
String[] procDef = new String[] { "java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
getClass().getName(), "" + operations, "" + flags, "" + value};
traceOperation("start: " + StringUtils.arrayCombine(procDef, ' '));
......
......@@ -48,7 +48,7 @@ public class TestKill extends TestBase {
String password = getPassword();
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] {
"java", selfDestruct,
"java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
"org.h2.test.synth.TestKillProcess", url, user,
password, baseDir, "" + accounts };
......@@ -57,7 +57,7 @@ public class TestKill extends TestBase {
printTime("TestKill " + i);
if (i % 10 == 0) {
trace("deleting db...");
deleteDb(baseDir, "kill");
deleteDb("kill");
}
conn = getConnection(url);
createTables();
......
......@@ -32,7 +32,7 @@ public class TestKillRestart extends TestBase {
// "killRestart;CACHE_SIZE=2048;WRITE_DELAY=0", true);
String user = getUser(), password = getPassword();
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] { "java", selfDestruct,
String[] procDef = new String[] { "java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
getClass().getName(), "-url", url, "-user", user,
"-password", password };
......
......@@ -45,7 +45,7 @@ public class TestKillRestartMulti extends TestBase {
user = getUser();
password = getPassword();
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] { "java", selfDestruct,
String[] procDef = new String[] { "java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
getClass().getName(), "-url", url, "-user", user,
"-password", password };
......
......@@ -33,7 +33,7 @@ public class TestMulti extends TestBase {
public void test() throws Exception {
org.h2.Driver.load();
deleteDb(baseDir, "openClose");
deleteDb("openClose");
// int len = getSize(5, 100);
int len = 10;
......
......@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.server;
package org.h2.test.unit;
import java.sql.Connection;
import java.sql.Driver;
......
......@@ -31,7 +31,7 @@ public class TestExit extends TestBase implements DatabaseEventListener {
}
deleteDb("exit");
String selfDestruct = SelfDestructor.getPropertyString(60);
String[] procDef = new String[] { "java", selfDestruct,
String[] procDef = new String[] { "java", selfDestruct, getPageStoreProperty(),
"-cp", getClassPath(),
getClass().getName(), "" + OPEN_WITH_CLOSE_ON_EXIT };
Process proc = Runtime.getRuntime().exec(procDef);
......
......@@ -4,7 +4,7 @@
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.server;
package org.h2.test.unit;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
......
......@@ -9,7 +9,6 @@ package org.h2.test.unit;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.constant.SysProperties;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
import org.h2.tools.Recover;
......@@ -45,7 +44,7 @@ public class TestRecovery extends TestBase {
conn = getConnection("recovery", "diff", "");
stat = conn.createStatement();
String name = "recovery.data.sql";
if (SysProperties.PAGE_STORE) {
if (config.pageStore) {
name = "recovery.h2.sql";
}
......
......@@ -19,8 +19,6 @@ import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.store.FileLister;
import org.h2.test.TestBase;
......@@ -273,7 +271,7 @@ public class TestTools extends TestBase {
private void testRecover() throws SQLException {
deleteDb("toolsRecover");
org.h2.Driver.load();
String url = "jdbc:h2:" + baseDir + "/toolsRecover";
String url = getURL("toolsRecover", true);
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar, b blob, c clob)");
......@@ -300,7 +298,7 @@ public class TestTools extends TestBase {
conn = DriverManager.getConnection(url, "another", "another");
stat = conn.createStatement();
String suffix = SysProperties.PAGE_STORE ? ".h2.sql" : ".data.sql";
String suffix = config.pageStore ? ".h2.sql" : ".data.sql";
stat.execute("runscript from '" + baseDir + "/toolsRecover" + suffix + "'");
rs = stat.executeQuery("select * from \"test 2\"");
assertFalse(rs.next());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论