Package org.chaidb.db

Source Code of org.chaidb.db.TestDB

/*
* Copyright (C) 2006  http://www.chaidb.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
*/

package org.chaidb.db;

import org.chaidb.db.api.keys.IntKey;
import org.chaidb.db.api.*;
import org.chaidb.db.exception.ChaiDBException;

public class TestDB {
    public static void main(String[] args) throws ChaiDBException {
        testStore();
        testLookup();
    }

    private static void testStore() throws ChaiDBException {
        Database db = new Database("D:\\temp");
        BTree btree = db.openBTree("test.idb", BTreeType.HYPER_BTREE);
        try {
            IntKey key = new IntKey(1);
            byte[] data = new byte[2];
            data[0] = 1;
            data[1] = 2;
            btree.acquire(LockType.WRITE);
            btree.store(key, data);
            btree.release();
        } catch (ChaiDBException e) {
            e.printStackTrace();
        } finally{
            btree.close();
            db.close();
        }
    }

    private static void testLookup() throws ChaiDBException {
        Database db = new Database("D:\\temp");
        BTree btree = db.openBTree("test.idb", BTreeType.HYPER_BTREE);
        try {
            IntKey key = new IntKey(1);
            btree.acquire(LockType.READ);
            DuplicatedKeyIterator it = btree.lookupValues(key);
            while (it.hasNext()) {
                byte[] bytes = (byte[]) it.next();
                for (int i = 0; i < bytes.length; i++) {
                    System.out.print(bytes[i]);
                    System.out.print(" ");
                }
            }
            btree.release();
        } catch (ChaiDBException e) {
            e.printStackTrace();
        } finally{
            btree.close();
            db.close();
        }
    }
}
TOP

Related Classes of org.chaidb.db.TestDB

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.