XFlat 是一个轻量级的嵌入式的非 SQL 的对象数据库,XFlat 将对象持久化到 XML 文件,相当于是 db4o 的开源替代品。要求 Java 7 支持。
示例代码:
//initialize with default config Database myDatabase = XFlatDatabase.Build(dir).create(); Foo myFoo = new Foo(); Table<Foo> fooTable = db.getTable(Foo.class); //inserts with unique automatically-generated ID fooTable.insert(myFoo); System.out.println("Stored foo in table Foo with ID " + myFoo.getId()); Foo myFoo2 = fooTable.find(myFoo.getId()); //myFoo2 is a new instance with the same data as myFoo
Maven:
<dependency> <groupId>org.xflatdb</groupId> <artifactId>xflat</artifactId> <version>0.9</version> <classifier>sources</classifier> </dependency>