You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Karl Wettin <ka...@apache.org> on 2009/07/06 01:46:50 UTC

[ANN] New java bindings

Hi forum,

I've implemented a new Java bindings library with a consumer API  
similar to BDB JE, but without some of the limitations in the latter.

Except for beeing faster than any of the binding I've tried it also  
features normalization of aggregated entities, and "abortable  
sessions" with a limited set of features similar to those one can find  
in transactions: begin, commit and rollbacks but with conflict caveats.

http://kodapan.se/foo/couchdb-entitystore
http://kodapan.se/foo/couchdb-entitystore.tar.gz

The tarball contains a large and complex demo application with lots of  
data in XML-format, thus the file size.

Here is smaller example also available on the webpage:

public class Service {

   private EntityStore store;

   private PrimaryIndex<Long, Artist> artists;
   private PrimaryIndex<Long, Album> albums;
   private PrimaryIndex<Long, Track> tracks;

   public Service() {
     store = new EntityStore();
     store.open("localhost", 5984);

     artists = store.getPrimaryIndex(Long.class, Artist.class);
     albums = store.getPrimaryIndex(Long.class, Album.class);
     tracks = store.getPrimaryIndex(Long.class, Track.class);
   }

   public static void main(String[] args) throws Exception {
     Service service = new Service();

     Artist artist = new Artist();
     // create a graph
     service.artists.put(artist);

     Artist artist2 = service.get(artist.getId());
     assertFalse(artist == artist2);
     assertEquals(artist, artist2);
   }

}


@Entity
public class Artist {

   @PrimaryKey
   private Long id;

   private String name;

   @Normalized(paths={"name", "tracks.title"})
   private List<Album> albums;

   // getters and setters...
}

@Entity
public class Album {

   @PrimaryKey
   private Long id;

   private String name;

   @Normalized(paths={"name", "artist.name"})
   private List<Track> tracks;

   @Normalized(paths={"name"})
   private Artist mainArtist;

   // getters and setters...
}

@Entity
public class Track {

   @PrimaryKey
   private Long id;

   private String title;

   @Normalized(path={"name"});
   private Artist artist;

   private int length;

   private int discNumber;

   // getters and setters...

}




       karl