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

MVStore: move background exception listener to the builder

上级 1dfdeea0
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.mvstore.db; package org.h2.mvstore.db;
import java.beans.ExceptionListener;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -38,9 +39,11 @@ public class MVTableEngine implements TableEngine { ...@@ -38,9 +39,11 @@ public class MVTableEngine implements TableEngine {
* @param db the database * @param db the database
* @return the store * @return the store
*/ */
public static Store init(Database db) { public static Store init(final Database db) {
Store store = db.getMvStore(); Store store = db.getMvStore();
if (store == null) { if (store != null) {
return store;
}
byte[] key = db.getFilePasswordHash(); byte[] key = db.getFilePasswordHash();
String dbPath = db.getDatabasePath(); String dbPath = db.getDatabasePath();
MVStore.Builder builder = new MVStore.Builder(); MVStore.Builder builder = new MVStore.Builder();
...@@ -68,6 +71,14 @@ public class MVTableEngine implements TableEngine { ...@@ -68,6 +71,14 @@ public class MVTableEngine implements TableEngine {
} }
builder.encryptionKey(password); builder.encryptionKey(password);
} }
builder.backgroundExceptionListener(new ExceptionListener() {
@Override
public void exceptionThrown(Exception e) {
db.setBackgroundException(DbException.convert(e));
}
});
try { try {
store = new Store(db, builder.open()); store = new Store(db, builder.open());
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
...@@ -83,7 +94,6 @@ public class MVTableEngine implements TableEngine { ...@@ -83,7 +94,6 @@ public class MVTableEngine implements TableEngine {
} }
} }
db.setMvStore(store); db.setMvStore(store);
}
return store; return store;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论