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

The database now tries to detect if the classloader or virtual machine has almost shut down.

上级 ad16b7de
...@@ -61,6 +61,14 @@ import org.h2.value.ValueString; ...@@ -61,6 +61,14 @@ import org.h2.value.ValueString;
*/ */
public class ScriptCommand extends ScriptBase { public class ScriptCommand extends ScriptBase {
private static final Comparator TABLE_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
Table t1 = (Table) o1;
Table t2 = (Table) o2;
return t1.getId() - t2.getId();
}
};
private boolean passwords; private boolean passwords;
private boolean data; private boolean data;
private boolean settings; private boolean settings;
...@@ -188,13 +196,7 @@ public class ScriptCommand extends ScriptBase { ...@@ -188,13 +196,7 @@ public class ScriptCommand extends ScriptBase {
ObjectArray tables = db.getAllSchemaObjects(DbObject.TABLE_OR_VIEW); ObjectArray tables = db.getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
// sort by id, so that views are after tables and views on views // sort by id, so that views are after tables and views on views
// after the base views // after the base views
tables.sort(new Comparator() { tables.sort(TABLE_COMPARATOR);
public int compare(Object o1, Object o2) {
Table t1 = (Table) o1;
Table t2 = (Table) o2;
return t1.getId() - t2.getId();
}
});
for (int i = 0; i < tables.size(); i++) { for (int i = 0; i < tables.size(); i++) {
Table table = (Table) tables.get(i); Table table = (Table) tables.get(i);
table.lock(session, false, false); table.lock(session, false, false);
......
...@@ -24,6 +24,19 @@ import org.h2.value.ValueString; ...@@ -24,6 +24,19 @@ import org.h2.value.ValueString;
*/ */
public class MetaRecord { public class MetaRecord {
private static final Comparator META_RECORD_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
MetaRecord m1 = (MetaRecord) o1;
MetaRecord m2 = (MetaRecord) o2;
int c1 = DbObjectBase.getCreateOrder(m1.getObjectType());
int c2 = DbObjectBase.getCreateOrder(m2.getObjectType());
if (c1 != c2) {
return c1 - c2;
}
return m1.getId() - m2.getId();
}
};
private int id; private int id;
private int objectType; private int objectType;
private int headPos; private int headPos;
...@@ -49,18 +62,7 @@ public class MetaRecord { ...@@ -49,18 +62,7 @@ public class MetaRecord {
* @param records the list of meta records * @param records the list of meta records
*/ */
public static void sort(ObjectArray records) { public static void sort(ObjectArray records) {
records.sort(new Comparator() { records.sort(META_RECORD_COMPARATOR);
public int compare(Object o1, Object o2) {
MetaRecord m1 = (MetaRecord) o1;
MetaRecord m2 = (MetaRecord) o2;
int c1 = DbObjectBase.getCreateOrder(m1.getObjectType());
int c2 = DbObjectBase.getCreateOrder(m2.getObjectType());
if (c1 != c2) {
return c1 - c2;
}
return m1.getId() - m2.getId();
}
});
} }
void setRecord(SearchRow r) { void setRecord(SearchRow r) {
......
...@@ -36,6 +36,12 @@ public class LogSystem { ...@@ -36,6 +36,12 @@ public class LogSystem {
*/ */
public static final int LOG_WRITTEN = -1; public static final int LOG_WRITTEN = -1;
private static final Comparator LOG_FILE_COMPARATOR = new Comparator() {
public int compare(Object a, Object b) {
return ((LogFile) a).getId() - ((LogFile) b).getId();
}
};
private Database database; private Database database;
private ObjectArray activeLogs; private ObjectArray activeLogs;
private LogFile currentLog; private LogFile currentLog;
...@@ -309,11 +315,7 @@ public class LogSystem { ...@@ -309,11 +315,7 @@ public class LogSystem {
} }
} }
} }
activeLogs.sort(new Comparator() { activeLogs.sort(LOG_FILE_COMPARATOR);
public int compare(Object a, Object b) {
return ((LogFile) a).getId() - ((LogFile) b).getId();
}
});
if (activeLogs.size() == 0) { if (activeLogs.size() == 0) {
LogFile l = new LogFile(this, 0, fileNamePrefix); LogFile l = new LogFile(this, 0, fileNamePrefix);
activeLogs.add(l); activeLogs.add(l);
......
...@@ -81,6 +81,18 @@ public class DiskFile implements CacheWriter { ...@@ -81,6 +81,18 @@ public class DiskFile implements CacheWriter {
private static final int OFFSET = FileStore.HEADER_LENGTH; private static final int OFFSET = FileStore.HEADER_LENGTH;
private static final int FREE_PAGE = -1; private static final int FREE_PAGE = -1;
private static final Comparator REDO_LOG_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
RedoLogRecord e1 = (RedoLogRecord) o1;
RedoLogRecord e2 = (RedoLogRecord) o2;
int comp = e1.recordId - e2.recordId;
if (comp == 0) {
comp = e1.sequenceId - e2.sequenceId;
}
return comp;
}
};
private Database database; private Database database;
private String fileName; private String fileName;
private FileStore file; private FileStore file;
...@@ -1187,17 +1199,7 @@ public class DiskFile implements CacheWriter { ...@@ -1187,17 +1199,7 @@ public class DiskFile implements CacheWriter {
if (redoBuffer.size() == 0) { if (redoBuffer.size() == 0) {
return; return;
} }
redoBuffer.sort(new Comparator() { redoBuffer.sort(REDO_LOG_COMPARATOR);
public int compare(Object o1, Object o2) {
RedoLogRecord e1 = (RedoLogRecord) o1;
RedoLogRecord e2 = (RedoLogRecord) o2;
int comp = e1.recordId - e2.recordId;
if (comp == 0) {
comp = e1.sequenceId - e2.sequenceId;
}
return comp;
}
});
// first write all deleted entries // first write all deleted entries
// because delete entries are always 1 block, // because delete entries are always 1 block,
// while not-deleted entries can be many blocks // while not-deleted entries can be many blocks
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论