lazy initialization of database tables

pull/1/head
Michael Peter Christen 13 years ago
parent 701b9a28a0
commit ba10caf89a

@ -70,8 +70,8 @@ public class Tables implements Iterable<String> {
this.keymaxlen = keymaxlen; this.keymaxlen = keymaxlen;
this.tables = new ConcurrentHashMap<String, BEncodedHeap>(); this.tables = new ConcurrentHashMap<String, BEncodedHeap>();
final String[] files = this.location.list(); final String[] files = this.location.list();
String tablename;
File file; File file;
// lazy initialization: do not open the database files here
for (final String f: files) { for (final String f: files) {
if (f.endsWith(suffix)) { if (f.endsWith(suffix)) {
file = new File(this.location, f); file = new File(this.location, f);
@ -79,6 +79,22 @@ public class Tables implements Iterable<String> {
file.delete(); file.delete();
continue; continue;
} }
}
}
}
@Override
public Iterator<String> iterator() {
// we did a lazy initialization, but here we must discover all actually existing tables
String tablename;
File file;
final String[] files = this.location.list();
for (final String f: files) {
if (f.endsWith(suffix)) {
file = new File(this.location, f);
if (file.length() == 0) {
continue;
}
tablename = f.substring(0, f.length() - suffix.length()); tablename = f.substring(0, f.length() - suffix.length());
try { try {
getHeap(tablename); getHeap(tablename);
@ -86,10 +102,7 @@ public class Tables implements Iterable<String> {
} }
} }
} }
} // now the list of tables is enriched, return an iterator
@Override
public Iterator<String> iterator() {
return this.tables.keySet().iterator(); return this.tables.keySet().iterator();
} }
@ -376,6 +389,7 @@ public class Tables implements Iterable<String> {
this.i = heap.iterator(); this.i = heap.iterator();
} }
@Override
protected Row next0() { protected Row next0() {
Row r; Row r;
while (this.i.hasNext()) { while (this.i.hasNext()) {

Loading…
Cancel
Save