Package jdbm

Examples of jdbm.RecordManager


    public void setup() {
        try {
            indexPath = tempFolder.newFolder();
            value = new SkinnyUUID(UUID.randomUUID());

            RecordManager recman = RecordManagerFactory.createRecordManager(
                    indexPath.getAbsolutePath(), new Properties());
            PrimaryTreeMap<String, SkinnyUUID> tree =
                    recman.treeMap(IndexerConstants.INDEX_TREE_KEY,
                            new SkinnyUUIDSerializer());
            tree.inverseHashView(IndexerConstants.INVERSE_KEY);
            tree.put(key, value);
            recman.commit();
            recman.close();
        } catch (IOException e) {
            e.printStackTrace();
            fail("Failure to create temporary folder for testing.");
        }
    }
View Full Code Here


    @Before
    public void setup() {
        try {
            indexPath = tempFolder.newFolder();
            this.uuids = new ArrayList<SkinnyUUID>();
            RecordManager recman = RecordManagerFactory.createRecordManager(
                    indexPath.getAbsolutePath(), new Properties());

            PrimaryTreeMap<String, SkinnyUUID> tree =
                    recman.treeMap(IndexerConstants.INDEX_TREE_KEY,
                            new SkinnyUUIDSerializer());
            tree.inverseHashView(IndexerConstants.INVERSE_KEY);

            for (int i = 0; i < numToTest; i++) {
                SkinnyUUID uuid = new SkinnyUUID(UUID.randomUUID());
                tree.put(String.valueOf(i), uuid);
                uuids.add(uuid);
            }

            recman.commit();
            recman.close();
        } catch (IOException e) {
            e.printStackTrace();
            fail("Failure to create temporary folder for testing.");
        }
    }
View Full Code Here

        rmProps.put(RecordManagerOptions.DISABLE_TRANSACTIONS, "true");

        String dbname = new File(System.getProperty("java.io.tmpdir"), "lastlogindb").getCanonicalPath();
        if (VERBOSE)
            System.out.println("dbname:  " + dbname);
        RecordManager stamps = RecordManagerFactory.createRecordManager(dbname, rmProps);
        BTree stampDb = BTree.createInstance(stamps, new StringComparator());

        // Scan log files looking for login records
        final Pattern loginCracker = Pattern.compile(loginRE);
        final SimpleDateFormat dateEncoder = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (String logName : args)
        {
            BufferedReader logReader = new BufferedReader(new FileReader(logName));
            while(true)
            {
                String line = logReader.readLine();
                // End of file?
                if (null == line)
                    break;
                // Skip if definitely not a login record
                if (!line.contains(":login:"))
                    continue;

                // Try to recognize the interesting fields
                Matcher loginMatcher = loginCracker.matcher(line);
                if (!loginMatcher.matches())
                    continue;

                // Pretty sure we have a login
                String date = loginMatcher.group(1);
                String time = loginMatcher.group(2);
                String user = loginMatcher.group(3);

                String logDateTime = date + ' ' + time;
                Date stamp;
                try {
                    stamp = dateEncoder.parse(logDateTime);
                } catch (ParseException ex) {
                    System.err.println("Skipping log record:  " + ex.getMessage());
                    continue;
                }
                Date previous = (Date) stampDb.find(user);
                if (null == previous || stamp.after(previous))
                {
                    stampDb.insert(user, stamp, true); // Record this user's newest login so far
                }
            }
            logReader.close();
        }

        // Now walk the cache and update EPersons
        TupleBrowser walker = stampDb.browse();
        Tuple stamp = new Tuple();
        Context ctx = new Context();
        ctx.turnOffAuthorisationSystem();

        while(walker.getNext(stamp))
        {
            // Update an EPerson's last login
            String name = (String) stamp.getKey();
            Date date = (Date) stamp.getValue();
            EPerson ePerson;
            ePerson = EPerson.findByEmail(ctx, name);
            if (null == ePerson)
                ePerson = EPerson.findByNetid(ctx, name);
            if (null == ePerson)
            {
                System.err.println("Skipping unknown user:  " + name);
                continue;
            }
            Date previous = ePerson.getLastActive();
            if ((null == previous) || date.after(previous))
            {
                if (PRETEND)
                {
                    System.out.printf("%d\t%s\t%s\t%s\t%s\n",
                            ePerson.getID(),
                            date,
                            ePerson.getEmail(),
                            ePerson.getNetid(),
                            ePerson.getFullName());
                }
                else
                {
                    ePerson.setLastActive(date);
                    ePerson.update();
                    ctx.commit();
                }
            }
        }

        ctx.complete();

        stamps.close();

        // Clean up external data and index files, if any
        File target;

        target = new File(dbname + ".db");
View Full Code Here

 
 
  public void testExpand() throws IOException{
    long init = Long.MAX_VALUE - size*2;
    String file = newTestFile();
    RecordManager recman = new BaseRecordManager(file);
    PrimaryTreeMap<Long, String> map = recman.treeMap("aa");
    for(long i = init; i<init+size;i++){
      map.put(i, "");     
    }
    recman.commit();
    recman.defrag();
    recman.close();
    long fileSize = new File(file+".dbr.0").length()/1024;
    System.out.println("file size: "+fileSize);
    assertTrue("file is too big, compression failed", fileSize<1000);
  }
View Full Code Here

    System.out.println("file size: "+fileSize);
    assertTrue("file is too big, compression failed", fileSize<1000);
  }
 
  public void testCornersLimitsLong() throws IOException{
    RecordManager recman = newRecordManager();
    PrimaryTreeMap<Long, String> map = recman.treeMap("aa");
    ArrayList<Long> ll = new ArrayList<Long>();
    for(Long i = Long.MIN_VALUE;i<Long.MIN_VALUE+1000;i++){
      map.put(i, "");
      ll.add(i);
    }
    for(Long i = -1000l;i<1000;i++){
      map.put(i, "");
      ll.add(i);
    }
    for(Long i = Long.MAX_VALUE - 1000;i<=Long.MAX_VALUE && i>0;i++){
      map.put(i, "");
      ll.add(i);
    }
     

    recman.commit();
   
    recman.clearCache();
    for(Long i:ll){
      assertTrue("failed for "+i,map.containsKey(i));
    }
   
    assertTrue(!map.containsKey(Long.valueOf(Long.MIN_VALUE+1000)));
    assertTrue(!map.containsKey(Long.valueOf(Long.MIN_VALUE+1001)));
    assertTrue(!map.containsKey(Long.valueOf(-1001L)));
    assertTrue(!map.containsKey(Long.valueOf(-1002L)));
    assertTrue(!map.containsKey(Long.valueOf(1001L)));
    assertTrue(!map.containsKey(Long.valueOf(1002L)));
    assertTrue(!map.containsKey(Long.valueOf(Long.MAX_VALUE-1001)));
    assertTrue(!map.containsKey(Long.valueOf(Long.MAX_VALUE-1002)));

    recman.close();   
  }
View Full Code Here

    recman.close();   
  }

 
  public void testCornersLimitsInt() throws IOException{
    RecordManager recman = newRecordManager();
    PrimaryTreeMap<Integer, String> map = recman.treeMap("aa");
    ArrayList<Integer> ll = new ArrayList<Integer>();
    for(Integer i = Integer.MIN_VALUE;i<Integer.MIN_VALUE+1000;i++){
      map.put(new Integer(i), "");
      ll.add(new Integer(i));
    }
    for(Integer i = -1000;i<1000;i++){
      map.put(i, "");
      ll.add(i);
    }
    for(Integer i = Integer.MAX_VALUE - 1000;i<=Integer.MAX_VALUE && i>0;i++){
      map.put(i, "");
      ll.add(i);
    }
     

    recman.commit();
   
    recman.clearCache();
    for(Integer i:ll){
      assertTrue("failed for "+i,map.containsKey(i));
    }
   
    assertTrue(!map.containsKey(Integer.valueOf(Integer.MIN_VALUE+1000)));
    assertTrue(!map.containsKey(Integer.valueOf(Integer.MIN_VALUE+1001)));
    assertTrue(!map.containsKey(Integer.valueOf(-1001)));
    assertTrue(!map.containsKey(Integer.valueOf(-1002)));
    assertTrue(!map.containsKey(Integer.valueOf(1001)));
    assertTrue(!map.containsKey(Integer.valueOf(1002)));
    assertTrue(!map.containsKey(Integer.valueOf(Integer.MAX_VALUE-1001)));
    assertTrue(!map.containsKey(Integer.valueOf(Integer.MAX_VALUE-1002)));

    recman.close();   
  }
View Full Code Here

  }
 
  public void testStrings() throws IOException{
    long init = Long.MAX_VALUE - size*2;
    String file = newTestFile();
    RecordManager recman = new BaseRecordManager(file);
    PrimaryTreeMap<String, String> map = recman.treeMap("aa");
    for(long i = init; i<init+size/10;i++){
      map.put("aaaaa"+i, "");     
    }
    recman.commit();
    recman.defrag();   
    recman.close();
    recman = new BaseRecordManager(file);
    map = recman.treeMap("aa");
    for(long i = init; i<init+size/10;i++){
      assertTrue(map.containsKey("aaaaa"+i));     
    }

    long fileSize = new File(file+".dbr.0").length()/1024;
View Full Code Here

public class StoreReferenceTest extends TestCaseWithTestFile{
 
  public void test() throws IOException{
    String file = newTestFile();
    RecordManager r = RecordManagerFactory.createRecordManager(file);
    PrimaryTreeMap<Long,StoreReference<String>> t = r.treeMap("aaa");
   
    t.put(1l, new StoreReference(r,"1"));
    t.put(2l, new StoreReference(r,"2"));
    r.commit();
   
    assertEquals("1",t.get(1l).get(r));
    assertEquals("2",t.get(2l).get(r));
   
    //reopen store
    r.close();
    r = RecordManagerFactory.createRecordManager(file);
    t = r.treeMap("aaa");
    assertEquals("1",t.get(1l).get(r));
    assertEquals("2",t.get(2l).get(r));
    r.close();
   
  }
View Full Code Here

    public void testRollback1()
        throws Exception
    {

        // Note: We start out with an empty file
        RecordManager recman =  newRecordManager();

        long root = recman.getNamedObject( "xyz" );
            
        HTree<String,String> tree = null;
        if ( root == 0 ) {
            // create a new one
            tree = HTree.createInstance( recman );
            root = tree.getRecid();
            recman.setNamedObject( "xyz", root );
            recman.commit();
        } else {
            tree = HTree.load( recman, root );
        }

        tree.put( "Foo", "Bar" );
        tree.put( "Fo", "Fum" );

        recman.commit();

        tree.put( "Hello", "World" );

        recman.rollback();

        tree = HTree.load( recman, root );
        assertTrue( tree.find( "Foo" ).equals( "Bar" ) );
        assertTrue( tree.find( "Fo" ).equals( "Fum" ) );
        assertTrue( tree.find( "Hello" ) == null );
View Full Code Here

     * Test case courtesy of Derek Dick (mailto:ddick  users.sourceforge.net)
     */
    public void testRollback2()
        throws Exception
    {
        RecordManager recman;
        long root;

        // Note: We start out with an empty file
        recman = newRecordManager();

        root = recman.getNamedObject( "xyz" );

        HTree tree = null;
        if ( root == 0 ) {
            // create a new one
            tree = HTree.createInstance( recman );
            root = tree.getRecid();
            recman.setNamedObject( "xyz", root );
            recman.commit();
        } else {
            tree = HTree.load( recman, root );
        }

        tree.put( "hello", "world" );
        tree.put( "goodnight", "gracie" );
        recman.commit();

        tree.put( "derek", "dick" );
        recman.rollback();

        assertTrue( tree.find( "derek" ) == null );
        assertTrue( tree.find( "goodnight" ).equals( "gracie" ) );
        assertTrue( tree.find( "hello" ).equals( "world" ) );
    }
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.