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

New experimental page store.

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