01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.nativerdf;
07:
08: import java.io.File;
09: import java.io.IOException;
10:
11: import org.openrdf.sail.nativerdf.btree.BTree;
12: import org.openrdf.sail.nativerdf.btree.RecordComparator;
13: import org.openrdf.sail.nativerdf.btree.RecordIterator;
14:
15: /**
16: * A cache for fixed size byte array records. This cache uses a temporary file
17: * to store the records. This file is deleted upon calling {@link #discard()}.
18: *
19: * @author Arjohn Kampman
20: */
21: class SortedRecordCache extends RecordCache {
22:
23: /*-----------*
24: * Constants *
25: *-----------*/
26:
27: protected final BTree btree;
28:
29: /*--------------*
30: * Constructors *
31: *--------------*/
32:
33: public SortedRecordCache(File cacheDir, int recordSize,
34: RecordComparator comparator) throws IOException {
35: this (cacheDir, recordSize, Long.MAX_VALUE, comparator);
36: }
37:
38: public SortedRecordCache(File cacheDir, int recordSize,
39: long maxRecords, RecordComparator comparator)
40: throws IOException {
41: super (cacheDir, maxRecords);
42: btree = new BTree(cacheFile, 4096, recordSize, comparator);
43: }
44:
45: /*---------*
46: * Methods *
47: *---------*/
48:
49: @Override
50: public void discard() throws IOException {
51: try {
52: btree.close();
53: } finally {
54: super .discard();
55: }
56: }
57:
58: public void storeRecordInternal(byte[] record) throws IOException {
59: btree.insert(record);
60: }
61:
62: public RecordIterator getRecordsInternal() {
63: return btree.iterateAll();
64: }
65: }
|