一個快速,易于使用的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();