use of org.cojen.tupl.core.CoreDatabase in project Tupl by cojen.
the class RowStoreTest method randomRowInfos.
private void randomRowInfos(long seed) throws Exception {
final var rnd = new Random(seed);
final Database db = Database.open(new DatabaseConfig());
final Index ix = db.openIndex("test");
final RowStore rs = new RowStore((CoreDatabase) db, db.openIndex("Schemata"));
final Map<String, ColumnInfo> keyColumns = randomKeyColumns(0, rnd);
final boolean withAltKey = rnd.nextBoolean();
final boolean withIndex = rnd.nextBoolean();
final Map<Integer, RowInfo> rowInfos = new HashMap<>();
for (int i = 0; i < 200; i++) {
RowInfo rowInfo = randomRowInfo("Test", keyColumns, withAltKey, withIndex, rnd);
Integer version = rs.schemaVersion(rowInfo, true, ix.id(), false);
RowInfo existing = rowInfos.get(version);
if (existing == null) {
rowInfos.put(version, rowInfo);
} else {
assertMatches(rowInfo, existing);
}
}
for (Map.Entry<Integer, RowInfo> e : rowInfos.entrySet()) {
Integer version = rs.schemaVersion(e.getValue(), true, ix.id(), false);
assertEquals(version, e.getKey());
}
db.close();
}
use of org.cojen.tupl.core.CoreDatabase in project Tupl by cojen.
the class IndexBackfill method unused.
private void unused(Trigger<R> trigger, boolean close) {
Sorter sorter;
Index deleted;
synchronized (this) {
if (mTriggers == null) {
return;
}
mTriggers.remove(trigger);
if (!close && !mTriggers.isEmpty()) {
return;
}
mTriggers = null;
sorter = mSorter;
mSorter = null;
deleted = mDeleted;
mDeleted = null;
}
if (sorter == null && deleted == null) {
return;
}
CoreDatabase db = mRowStore.mDatabase;
db.removeRedoListener(this);
Runner.start(() -> {
Runnable deleteTask = null;
if (deleted != null) {
try {
deleteTask = db.deleteIndex(deleted);
} catch (Exception e) {
// Ignore.
}
}
if (sorter != null) {
try {
sorter.reset();
} catch (Exception e) {
// Ignore.
}
}
if (deleteTask != null) {
deleteTask.run();
}
});
}
Aggregations