Package jdbm

Examples of jdbm.RecordManager


    assertEquals(s.get(2), null);

  }
 
  public void testSecondaryHashMap() throws IOException{
    RecordManager r = newRecordManager();
    PrimaryTreeMap<Integer, String> m = r.treeMap("aa");
    SecondaryHashMap<Integer, Integer, String> s = m.secondaryHashMap("bb",
        new SecondaryKeyExtractor<Integer, Integer, String>() {

      public Integer extractSecondaryKey(Integer key, String value) {       
        return value.length();
View Full Code Here


    assertEquals(s.get(2), null);

  }
 
  public void testSecondaryTreeMapManyToOne() throws IOException{
    RecordManager r = newRecordManager();
    PrimaryTreeMap<Integer, String> m = r.treeMap("aa");
    SecondaryTreeMap<Integer, Integer, String> s = m.secondaryTreeMapManyToOne("bb",
        new SecondaryKeyExtractor<Iterable<Integer>, Integer, String>() {

      public List<Integer> extractSecondaryKey(Integer key, String value) {       
        return list(value.length(),10+value.length());
View Full Code Here

     */
    public void testLargeDataAmount()
        throws IOException
    {

        RecordManager  recman;
        BTree          tree;

        if ( DEBUG )
            System.out.println("TestBTree.testLargeDataAmount");

        recman = newRecordManager();
        // recman = new jdbm.recman.BaseRecordManager( "test" );
       
        tree = BTree.createInstance( recman);
        // tree.setSplitPoint( 4 );

        int iterations = 10000;

        // insert data
        for ( int count = 0; count < iterations; count++ ) {
           try {
            assertEquals(null,tree.insert("num"+count,new Integer(count),false));
           } catch ( IOException except ) {
               except.printStackTrace();
               throw except;
           }
        }

           // find data
         for(int count = 0; count < iterations; count++)
         {
           assertEquals(new Integer(count), tree.find("num"+count));
         }

             // delete data
         for(int count = 0; count < iterations; count++)
         {
           assertEquals(new Integer(count),tree.remove("num"+count));
         }

         assertEquals(0,tree.size());

         recman.close();
   }
View Full Code Here

        /** Test that the object is not modified by serialization.
         * @throws IOException
         */
        @Test
        public void testInsertUpdateWithCustomSerializer () throws IOException {
        RecordManager recman = newRecordManager();
        Serializer<Long> serializer = new Serializer<Long>(){

            public void serialize(SerializerOutput out, Long obj) throws IOException {
                out.writeLong(obj);
            }

            public Long deserialize(SerializerInput in) throws IOException, ClassNotFoundException {
                return in.readLong();
            }
        };
               
        Map<Long, Long> map = recman.hashMap("custom", serializer, serializer);
       
        map.put(new Long(1), new Long(1));
        map.put(new Long(2), new Long(2));
        recman.commit();
        map.put(new Long(2), new Long(3));
        recman.commit();
                recman.close();
        }
View Full Code Here

    /**
     *  Basic tests
     */
    public void testIterator() throws IOException {
       
        RecordManager recman = newRecordManager();

        HTree testTree = getHtree(recman, "htree");
   
        int total = 10;
        for ( int i = 0; i < total; i++ ) {
            testTree.put( Long.valueOf("" + i), Long.valueOf("" + i) );
        }
        recman.commit();
   
        Iterator fi = testTree.values();
        Object item;
        int count = 0;
        while(fi.hasNext()) {
          fi.next();
            count++;
        }
        assertEquals( count, total );

        recman.close();
    }
View Full Code Here

        recman.close();
    }

    public void testRecordListener() throws IOException{
        RecordManager recman = newRecordManager();
        HTree<Integer,String> tree = HTree.createInstance( recman);
        final List<SimpleEntry<Integer,String>> dels = new ArrayList();
        final List<SimpleEntry<Integer,String>> ins = new ArrayList();
        final List<SimpleEntry<Integer,String>> updNew = new ArrayList();
        final List<SimpleEntry<Integer,String>> updOld = new ArrayList();
View Full Code Here

        return testTree;
    }
   
    @SuppressWarnings("unchecked")
  public void testStoreMapSecondaryTreeListeners() throws IOException{
      RecordManager recman = newRecordManager();
      PrimaryStoreMap<Long,String> st = recman.storeMap("storeMap");
      SecondaryKeyExtractor<String, Long, String> extractor = new SecondaryKeyExtractor<String, Long, String>() {
      public String extractSecondaryKey(Long key, String value) {       
        return ""+key+value;
      }};
      SecondaryTreeMap t = st.secondaryTreeMap("map1",extractor);
      SecondaryHashMap h = st.secondaryHashMap("map2",extractor);
      Long key = st.putValue("aaa");
      assertTrue(t.size() == 1);
      assertTrue(t.containsKey(""+key+"aaa"));
      assertTrue(h.size() == 1);
      assertTrue(h.containsKey(""+key+"aaa"));
     
      //defrag will force reopening
      recman.defrag();
      recman.clearCache();
     
      assertTrue(t.size() == 1);
      assertTrue(t.containsKey(""+key+"aaa"));
      assertTrue(h.size() == 1);
      assertTrue(h.containsKey(""+key+"aaa"));
View Full Code Here

     *  Basic tests
     */
    public void testStreamCorrupted()
        throws IOException
    {
        RecordManager  recman;
        BTree          btree;
        int            iterations;

        iterations = 100; // 23 works :-(((((

        // open database
        recman = newRecordManager();

        // create a new B+Tree data structure
        btree = BTree.createInstance( recman);
        recman.setNamedObject( "testbtree", btree.getRecid() );

        // action:

        // insert data
        for( int count = 0; count < iterations; count++ ) {
            btree.insert( "num" + count, new Integer( count ), true );
        }

        // delete data
        for( int count = 0; count < iterations; count++ ) {
            btree.remove( "num" + count );
        }

        // close database
        recman.close();
        recman = null;
    }
View Full Code Here

     *  Basic tests
     */
    public void testBasics() throws IOException {
        System.out.println("testBasics");

        RecordManager recman = newRecordManager();

        HTree tree = new HTree();
        HashDirectory dir = new HashDirectory(tree, (byte)0);
        long recid = recman.insert(dir,tree.SERIALIZER);
        dir.setPersistenceContext(recman, recid);

        dir.put("key", "value");
        String s = (String)dir.get("key");
        assertEquals("value", s);

        recman.close();
    }
View Full Code Here

     *  Mixed tests
     */
    public void testMixed() throws IOException {
        System.out.println("testMixed");

        RecordManager recman = newRecordManager();
        HTree tree = new HTree();
        HashDirectory dir = new HashDirectory(tree, (byte)0);
        long recid = recman.insert(dir,tree.SERIALIZER);
        dir.setPersistenceContext(recman, recid);

        Hashtable hash = new Hashtable(); // use to compare results

        int max = 30; // must be even

        // insert & check values
        for (int i=0; i<max; i++) {
            dir.put("key"+i, "value"+i);
            hash.put("key"+i, "value"+i);
        }
        recman.commit();

        for (int i=0; i<max; i++) {
            String s = (String)dir.get("key"+i);
            assertEquals("value"+i, s);
        }
        recman.commit();

        // replace only even values
        for (int i=0; i<max; i+=2) {
            dir.put("key"+i, "value"+(i*2+1));
            hash.put("key"+i, "value"+(i*2+1));
        }
        recman.commit();

        for (int i=0; i<max; i++) {
            if ((i%2) == 1) {
                // odd
                String s = (String)dir.get("key"+i);
                assertEquals("value"+i, s);
            } else {
                // even
                String s = (String)dir.get("key"+i);
                assertEquals("value"+(i*2+1), s);
            }
        }
        recman.commit();

        // remove odd numbers
        for (int i=1; i<max; i+=2) {
            dir.remove("key"+i);
            hash.remove("key"+i);
        }
        recman.commit();

        for (int i=0; i<max; i++) {
            if ((i%2) == 1) {
                // odd
                String s = (String)dir.get("key"+i);
                assertEquals(null, s);
            } else {
                // even
                String s = (String)dir.get("key"+i);
                assertEquals("value"+(i*2+1), s);
            }
        }
        recman.commit();

        recman.close();
        recman = null;
    }
View Full Code Here

TOP

Related Classes of jdbm.RecordManager

Copyright © 2018 www.massapicom. 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.