Search in sources :

Example 1 with BTree

use of org.exist.storage.btree.BTree in project exist by eXist-db.

the class BTreeTest method rebuild.

public void rebuild() throws DBException, IOException, TerminatedException {
    BTree btree = null;
    try {
        System.out.println("Loading btree ...");
        btree = new BTree(pool, BTREE_TEST_FILE_ID, BTREE_TEST_FILE_VERSION, false, pool.getCacheManager(), file);
        btree.open((short) -1);
        System.out.println("Rebuilding ...");
        btree.rebuild();
        try (final OutputStreamWriter writer = new OutputStreamWriter(System.out)) {
            btree.dump(writer);
            writer.flush();
        }
    } finally {
        if (btree != null) {
            btree.close();
        }
    }
}
Also used : BTree(org.exist.storage.btree.BTree) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with BTree

use of org.exist.storage.btree.BTree in project exist by eXist-db.

the class CollectionTest method read.

public void read(final BrokerPool pool) throws EXistException, IOException, PermissionDeniedException, BTreeException, DatabaseConfigurationException, LockException {
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        BTree btree = ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
        Writer writer = new StringWriter();
        btree.dump(writer);
        Collection test = broker.getCollection(TEST_COLLECTION_URI.append("test2"));
        assertNotNull(test);
        for (Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext(); ) {
            DocumentImpl next = i.next();
        }
    }
}
Also used : StringWriter(java.io.StringWriter) BTree(org.exist.storage.btree.BTree) Collection(org.exist.collections.Collection) DocumentImpl(org.exist.dom.persistent.DocumentImpl) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 3 with BTree

use of org.exist.storage.btree.BTree in project exist by eXist-db.

the class BTreeTest method read.

public void read(int count) throws DBException, IOException, TerminatedException {
    BTree btree = null;
    try {
        System.out.println("Loading btree ...");
        btree = new BTree(pool, BTREE_TEST_FILE_ID, BTREE_TEST_FILE_VERSION, false, pool.getCacheManager(), file);
        btree.open((short) -1);
        String prefixStr = "KEY";
        for (int i = 1; i <= count; i++) {
            Value value = new Value(prefixStr + Integer.toString(i));
            long r = btree.findValue(value);
            if (r == -1) {
                System.out.println("Key not found: " + i);
            }
        }
    } finally {
        if (btree != null) {
            btree.close();
        }
    }
}
Also used : Value(org.exist.storage.btree.Value) BTree(org.exist.storage.btree.BTree)

Example 4 with BTree

use of org.exist.storage.btree.BTree in project exist by eXist-db.

the class BTreeTest method create.

public void create(int count) throws DBException, IOException {
    FileUtils.deleteQuietly(file);
    try (BTree btree = new BTree(pool, BTREE_TEST_FILE_ID, BTREE_TEST_FILE_VERSION, false, pool.getCacheManager(), file)) {
        btree.create((short) -1);
        String prefixStr = "KEY";
        for (int i = 1; i <= count; i++) {
            Value value = new Value(prefixStr + Integer.toString(i));
            btree.addValue(value, i);
        }
        btree.flush();
        try (final OutputStreamWriter writer = new OutputStreamWriter(System.out)) {
            btree.dump(writer);
            writer.flush();
        }
    }
}
Also used : Value(org.exist.storage.btree.Value) BTree(org.exist.storage.btree.BTree) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

BTree (org.exist.storage.btree.BTree)4 OutputStreamWriter (java.io.OutputStreamWriter)2 Value (org.exist.storage.btree.Value)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Collection (org.exist.collections.Collection)1 DocumentImpl (org.exist.dom.persistent.DocumentImpl)1