发布于 2014-07-21 09:26:18 | 390 次阅读 | 评论: 0 | 来源: 网友投递
MapDB 嵌入式Java数据库引擎
MapDB提供了并发的Maps,Sets 和 Queues,基于磁盘存储或off-heap-memory。这是一个快速,可扩展的和易于使用的嵌入式Java数据库引擎。非常微小(jar只有160KB),但功能强大,如事务,空间高效的序列化,实例缓存和透明压缩/加密。
MapDB 1.0.5 发布了,该版本修复了两个 bug:
事务日志重放失败的问题
异步写时很偶发的一个问题
MapDB 提供了并发的 TreeMap 和 HashMap ,使用基于磁盘的存储。快速、可伸缩性以及易用。
示例代码:
import org.mapdb.*;
// configure and open database using builder pattern.
// all options are available with code auto-completion.
DB db = DBMaker.newFileDB(new File("testdb"))
.closeOnJvmShutdown()
.encryptionEnable("password")
.make();
// open existing an collection (or create new)
ConcurrentNavigableMap<Integer,String> map = db.getTreeMap("collectionName");
map.put(1, "one");
map.put(2, "two");
// map.keySet() is now [1,2]
db.commit(); //persist changes into disk
map.put(3, "three");
// map.keySet() is now [1,2,3]
db.rollback(); //revert recent changes
// map.keySet() is now [1,2]
db.close();