0

我想在 BerkeleyDB 中创建一个序列,我可以手动操作,但我不知道该怎么做。我想要一些类似于 SQL 序列对象的东西。我在 API 文档中找到了一个类,但不清楚如何创建一个。

任何帮助是极大的赞赏!

4

1 回答 1

1

下面的代码工作正常:

@Test
public void testSequenceCreation() throws ClassNotFoundException {
    EnvironmentConfig econf = EnvironmentConfig.DEFAULT.setAllowCreate(true);
    Environment env = new Environment(envHome, econf);

    StoreConfig sconf = StoreConfig.DEFAULT.setAllowCreate(true);
    EntityStore store = new EntityStore(env, "TestStore", sconf);

    store.setPrimaryConfig(FakeEntity.class, 
            DatabaseConfig.DEFAULT.setAllowCreate(true));
    store.setSequenceConfig("testSequence", SequenceConfig.DEFAULT.setAllowCreate(true));

    Sequence seq = store.getSequence("testSequence");
    Assert.assertEquals(0, seq.get(null, 1));
    Assert.assertEquals(1, seq.get(null, 1));
    Assert.assertEquals(2, seq.get(null, 1));

    store.sync();

    seq.close();
    store.close();
    env.close();        
}

我所要做的就是设置一个配置,然后创建序列。

于 2012-01-24T09:18:56.170 回答