提交 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;
*/
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 data;
private boolean settings;
......@@ -188,13 +196,7 @@ public class ScriptCommand extends ScriptBase {
ObjectArray tables = db.getAllSchemaObjects(DbObject.TABLE_OR_VIEW);
// sort by id, so that views are after tables and views on views
// after the base views
tables.sort(new Comparator() {
public int compare(Object o1, Object o2) {
Table t1 = (Table) o1;
Table t2 = (Table) o2;
return t1.getId() - t2.getId();
}
});
tables.sort(TABLE_COMPARATOR);
for (int i = 0; i < tables.size(); i++) {
Table table = (Table) tables.get(i);
table.lock(session, false, false);
......
......@@ -23,6 +23,19 @@ import org.h2.value.ValueString;
* It contains the SQL statement to create the database object.
*/
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 objectType;
......@@ -49,18 +62,7 @@ public class MetaRecord {
* @param records the list of meta records
*/
public static void sort(ObjectArray records) {
records.sort(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();
}
});
records.sort(META_RECORD_COMPARATOR);
}
void setRecord(SearchRow r) {
......
......@@ -36,6 +36,12 @@ public class LogSystem {
*/
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 ObjectArray activeLogs;
private LogFile currentLog;
......@@ -309,11 +315,7 @@ public class LogSystem {
}
}
}
activeLogs.sort(new Comparator() {
public int compare(Object a, Object b) {
return ((LogFile) a).getId() - ((LogFile) b).getId();
}
});
activeLogs.sort(LOG_FILE_COMPARATOR);
if (activeLogs.size() == 0) {
LogFile l = new LogFile(this, 0, fileNamePrefix);
activeLogs.add(l);
......
......@@ -80,6 +80,18 @@ public class DiskFile implements CacheWriter {
// (to match block size of operating system)
private static final int OFFSET = FileStore.HEADER_LENGTH;
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 String fileName;
......@@ -1187,17 +1199,7 @@ public class DiskFile implements CacheWriter {
if (redoBuffer.size() == 0) {
return;
}
redoBuffer.sort(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;
}
});
redoBuffer.sort(REDO_LOG_COMPARATOR);
// first write all deleted entries
// because delete entries are always 1 block,
// while not-deleted entries can be many blocks
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论