一个快速,易于使用的Java嵌入式数据库引擎:MapDB
MapDB提供了并发的Maps,Sets 和 Queues,基于磁盘存储或off-heap-memory。这是一个快速,可扩展的和易于使用的嵌入式Java数据库引擎。非常微小(jar只有160KB),但功能强大,如事务,空间高效的序列化,实例缓存和透明压缩/加密。
功能特性:
-
并发 - MapDB has record level locking and state-of-art concurrent engine. Its performance scales nearly linearly with number of cores. Data can be written by multiple parallel threads.
-
快速 - MapDB has outstanding performance rivaled only by native DBs. It is result of more than a decade of optimizations and rewrites.
-
ACID事务 - MapDB optionally supports ACID transactions with full MVCC isolation. MapDB uses write-ahead-log or append-only store for great write durability.
-
灵活 - MapDB can be used everywhere from in-memory cache to multi-terabyte database. It also has number of options to trade durability for write performance. This makes it very easy to configure MapDB to exactly fit your needs.
-
Hackable - MapDB is component based, most features (instance cache, async writes, compression) are just class wrappers. It is very easy to introduce new functionality or component into MapDB.
-
SQL Like - MapDB was developed as faster alternative to SQL engine. It has number of features which makes transition from relational database easier: secondary indexes/collections, autoincremental sequential ID, joints, triggers, composite keys...
-
低磁盘空间使用情况 - MapDB has number of features (serialization, delta key packing...) to minimize disk used by its store. It also has very fast compression and custom serializers. We take disk-usage seriously and do not waste single byte.
import org.mapdb.*; //Configure and open database using builder pattern. DB db = DBMaker .newFileDB(new File("testdb")) .closeOnJvmShutdown() .make(); //create new collection (or open existing) ConcurrentNavigableMap map = db.getTreeMap("collectionName"); map.put(1,"one"); map.put(2,"two"); //persist changes into disk, there is also rollback() method db.commit(); db.close();