EktorpFrom Libzter
ektorp
[edit] OverviewEktorp is a Java library that provides persistency functions similar to JPA using [[1]] as storage engine. Since couchDB is schemaless and document based, it allows for simplicity and flexibility of this persistens API. Under the hood it uses Jackson for object serialization. All communication is done by JSON over HTTP. As with couchDB, it uses javascript map reduce views for database queries.
[edit] Features
[edit] ExampleHere is a simple CRUD example application with persisted objects using ektorp and CouchDB. // A class that can be stored using ektorp. Revision and Id are needed values, // however, there is a base class to derive from to avoid annotations like this. @JsonWriteNullProperties(false) @JsonIgnoreProperties({"id", "revision"}) public class MyClass { @JsonProperty("_id") private String id; @JsonProperty("_rev") private String revision; private String value; private String type; public MyClass(String id){ setId(id); setType("MyClass"); } public MyClass(){ setType("MyClass");} public String setId(String s) { id = s; } public String getId() { return id; } public String getRevision() { return rev; } public void setValue(String s) { value = s; } public String getValue() { return value; } public void setType(String s) { type = s; } public String getType() { return type; } } // The repository class, the view "all" defines a Map view that retrieves all MyClass objects from //CouchDB. The property "type" or some other type identifier has to be added manually since couchDB //is schemaless, it cannot otherwise filter out all objects of a certain type. @View( name = "all", map = "function(doc) { if(doc.type == 'MyClass' ) emit( null, doc._id )}") public class MyRepository extends CouchDbRepositorySupport<MyClass> { public MyClassRepository(CouchDbConnector db) { super(MyClass.class, db); initStandardDesignDocument(); } } // test app. public class Test { public static void main(String arg[]){ HttpClient httpClient = new StdHttpClient.Builder() .host("localhost") .port(5984) .build(); CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); CouchDbConnector db = new StdCouchDbConnector("testdatabase", dbInstance); MyRepository repo = new MyRepository(db); MyClass s = new MyClass("myObject"); repo.add(s); MyClass s2 = repo.get("myObject"); repo.update(s2); repo.remove(s2); List<MyClass> repo.getAll(); } } [edit] Resourceshttp://code.google.com/p/ektorp/ - Website with download, documentations, source code etc. http://ektorp.org/ - Main website with links
[edit] See Also
User comments on this article (Ektorp) |
||
A lot easier to get going with this than hibernate or other ORM libraries. This also gives data persistency support to massively scalable/parallell document databa