Example #1
0
  public void setUp(short pageSize, IndexFactory<Long, Integer> indexType) throws IOException {
    File path = File.createTempFile("test-mixed", ".tmp", new File("test"));
    path.delete();
    System.out.println("file: " + path);

    m_pageSize = pageSize;
    m_dataSize = (short) (pageSize - (MAGIC.length + Long.SIZE / 8));
    m_pageFile = createFileFactory(path, pageSize);
    m_indexFactory = indexType;

    // create the index
    Transaction tx = m_pageFile.tx();
    try {
      Index<Long, Integer> index = m_indexFactory.create(tx);

      // seed the index with some metadata about the test
      index.put(-2L, (int) m_pageSize);
      index.put(-3L, (int) m_dataSize);
      index.put(-4L, MAGIC.length);
    } finally {
      tx.commit();
    }

    m_pageFile.flush();
  }
Example #2
0
 private CustomObject load(long id) {
   Transaction tx = m_pageFile.tx();
   try {
     Index<Long, Integer> idx = m_indexFactory.open(tx);
     Integer pageNumber = idx.get(id);
     // see if the index contains this object
     if (pageNumber == null) {
       return null;
     } else {
       return load(tx, pageNumber);
     }
   } finally {
     tx.commit();
     tx.close();
   }
 }
Example #3
0
 private void store(CustomObject c) {
   Transaction tx = m_pageFile.tx();
   try {
     Index<Long, Integer> idx = m_indexFactory.open(tx);
     Integer pageNumber = idx.get(c.id);
     // see if the index contains this object
     if (pageNumber == null) {
       pageNumber = tx.alloc();
       store(tx, pageNumber, c);
       idx.put(c.id, pageNumber);
     } else {
       store(tx, pageNumber, c);
     }
     tx.commit();
   } finally {
     tx.close();
   }
 }