- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
(我已经在网上某个地方看到了这个问题,但是依赖于“100”作为搜索词的搜索查询显然不是一个有希望的查询 - 所以如果这个问题已经被问到,请原谅我)
我刚刚开始使用 Java 中的 berkeley DB 使用其 DPL 功能。我创建了一个“Client”类,它具有以下主键和序列:
public class Client {
// primary key
@PrimaryKey(sequence="Client_ID")
private long id;
[...]
}
我正在使用主索引添加一些示例实体:
clientById = store.getPrimaryIndex(Long.class, Client.class);
clientById.put(client);
我第一次启动应用程序,一切正常。该序列从 1 开始并增加 1。下次启动应用程序时,它从 101 开始(步长仍为 1),而不是从 4 继续(我有 3 个示例实体)。是否有可能以某种方式影响这种行为?我想要一个持续的序列。
编辑:这是我的测试代码:
public static void main(String[] args) {
test();
test();
}
public static void test() {
// create some test clients
Client c1 = new Client("Client 1", "Cli 1 street 1", null, "55411", "Bingen");
Client c2 = new Client("Client 2", "Cli 1 street 2", null, "55411", "Bingen");
Client c3 = new Client("Test Custoamer");
// create database
Store store = new Store();
ClientAccessor ca = new ClientAccessor(store.getStore());
ca.put(c1);
ca.put(c2);
ca.put(c3);
List<Client> clients = ca.getAll();
for (Client c : clients) {
System.out.println(c);
System.out.println("-------------------");
}
store.shutdown();
}
商店看起来像这样:
public class Store {
private File dbfile;
private Environment env;
private EntityStore store;
public Store() {
this(new File(System.getProperty("user.home"), "tmdb"));
}
public Store(File dbfile) {
this.dbfile = dbfile;
setup();
}
public void setup() {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
env = new Environment(dbfile, envConfig);
StoreConfig storeConfig = new StoreConfig();
storeConfig.setAllowCreate(true);
storeConfig.setTransactional(true);
store = new EntityStore(env, "TimeManagement", storeConfig);
}
public void shutdown() {
store.close();
env.close();
}
public EntityStore getStore() {
return store;
}
}
ClientAccessor 像这样:
public class ClientAccessor {
private EntityStore store;
// primary index
PrimaryIndex<Long, Client> clientById;
public ClientAccessor(EntityStore store) {
this.store = store;
if (store == null)
throw new IllegalArgumentException("EntityStore can't be null!");
clientById = store.getPrimaryIndex(Long.class, Client.class);
}
public void put(Client c) {
clientById.put(c);
}
public List<Client> getAll() {
ArrayList<Client> clients = new ArrayList<Client>();
EntityCursor<Client> cursor = clientById.entities();
for (Client c : cursor) {
clients.add(c);
}
cursor.close();
return clients;
}
}
客户端看起来像这样:
@Entity
public class Client {
// primary key
@PrimaryKey(sequence="Client_ID")
private long id;
// secondary keys
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String name;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String address1;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String address2;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String plz;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String city;
private Client(){}
// address is optional
public Client(String name) {
this(name, null, null, null, null);
}
public Client(String name, String address1, String address2, String plz, String city) {
this.setName(name);
this.setAddress1(address1);
this.setAddress2(address2);
this.setPlz(plz);
this.setCity(city);
}
@Override
public String toString() {
String str = "";
str += id + "\n";
str += name + "\n";
str += (address1 != null && ! address1.isEmpty()) ? address1 + "\n" : "";
str += (address2 != null && ! address2.isEmpty()) ? address2 + "\n" : "";
str += (plz != null && ! plz.isEmpty()) ? plz + " " : "";
str += (city != null &&! city.isEmpty()) ? city + "\n" : "";
return str;
}
// getters and setters
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getPlz() {
return plz;
}
public void setPlz(String plz) {
this.plz = plz;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
最佳答案
默认情况下,序列缓存 100 个条目。要更改此设置,请将此代码添加到 Store.setup()
方法的末尾:
SequenceConfig sequenceConfig = store.getSequenceConfig("Client_ID");
sequenceConfig.setCacheSize(1);
store.setSequenceConfig("Client_ID", sequenceConfig);
关于berkeley-db - 应用重启后 Berkeley DB 主键序列跳转 100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24256038/
Berkeley DB 是否有空间索引,例如 R-tree? 最佳答案 有人问the same question on the Oracle forum .还没有甲骨文回答。但答案是否定的,它没有任何
berkeley-db-je 的最新版本是什么? 来自 oracle , 为 7.5。 但来自maven存储库,它是 18.3.12。 有没有人知道更多的细节? 最佳答案 Berkeley DB Ja
看起来 BerkeleyDB 被 Oracle 收购了,它没有在其网站上发布源代码? 最佳答案 Sleepycat 于 2006 年被 Oracle 收购。该产品继续在原始开源许可下可用,并继续得到增
我正在尝试通读 Berkeley DB XML 上的文档,而且我认为我真的可以使用开发人员的博客文章或概要,当他们遇到问题时发现 Berkeley DB 上的 XML 层是正确的处方。 也许我不明白,
(我已经在网上某个地方看到了这个问题,但是依赖于“100”作为搜索词的搜索查询显然不是一个有希望的查询 - 所以如果这个问题已经被问到,请原谅我) 我刚刚开始使用 Java 中的 berkeley D
几天前我刚刚开始使用 Berkeley DB,所以我想看看在尽可能快地存储数据方面是否遗漏了什么。 以下是有关数据的一些信息: - 它有 512 字节的块 - 大块按顺序排列 - 块将按 FIFO 顺
我有一个现有的 C++ 程序,它使用 Berkeley DB 作为存储后端。我想用 Rust 重写它。有没有办法在 Rust 中编写外部函数接口(interface)以使用 Berkeley DB?我
我正在设计一个基于 Java 的网络应用程序,我需要一个键值存储。 Berkeley DB 似乎很适合我,但似乎有两个 Berkeley DB 可供选择:用 C 实现的 Berkeley DB Cor
我有一个由 C 实现(python bsddb 模块)创建的 berkeley db 文件(*.bdb)。是否可以通过 Berkeley Db 的纯 Java 实现来读取此文件?我尝试使用 berke
我正在尝试从本地比特币数据库中提取数据。据我所知,bitcoin-qt 正在使用 BerkeleyDB。我已经从 Oracle 网站安装了 Berkley db,并在这里找到了 .NET 的 dll:
有没有办法在 Berkeley DB 的 java 接口(interface)上执行非阻塞操作,并使用 Future 或类似的东西获取操作的状态和结果(比如使用 Future 获取 Callable
我在nginx中使用Berkeley DB(BDB)。当请求到达时,nginx 将 URI 作为键传递给 BDB,并检查该键在 BDB 文件中是否有值。 我实际上在一个例子中做到了。我在BDB中添加了
在多线程应用程序中使用 berkeley DB (bdb) 句柄的最佳方法是什么? 让每个线程打开自己的句柄更好吗?或者, 打开单个句柄并让每个线程执行 txn_begin { } txn->comm
好消息!自 4.8 版以来,BerkeleyDB 具有 c# 接口(interface)。 BerkeleyDB 对我来说是一件非常有趣的事情,因为它是非 SQL 的。我知道如果有人想要存储很多键/值
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在寻找一些不错的 xml db ,它将嵌入到我的应用程序中。我想使用我的java应用程序中嵌入的berkley db。也就是说,我不想将 berkley db 作为服务运行并访问它,而是想从我的应
我知道在线路上,大多数整数都是大端格式。 但为什么应用程序的负担是在像 sockaddr_in 这样的结构中进行字节交换,而不是内核,所有低级工作实际上都发生在内核中?如果用户空间 API 与平台无关
我使用Java版的BerkeleyDB,DPL。 在将数据解析到 BerkeleyDB 时,我将一些临时信息存储在特定的 PrimaryIndex 中。这个 PrimaryIndex 占用了大量空间,
出于实验原因,我正在研究 Berkeley DB。但我在从数据库读取文件时遇到问题。 当程序像 创建数据库 打开 写 阅读 关闭 在执行中完全没有问题。 但是当我将数据写入数据库文件并关闭它,然后再次
我正在使用 Berkeley DB 将数据持久存储在我的程序中。我在我的SSD上进行了测试,我的SSD写入速度为1.4Gb/s。我测试DB存储速度的程序如下(错误检查省略)。 const char*
我是一名优秀的程序员,十分优秀!