Community contributed extensions

Riak module

The Riak module allow to use riak-java-client in play way. All java properties is encode in JSON and save in riak with bucket and key declare in Annotation



riak.url =

At startup the module check {riak.url}/stats for assure the right status of your Riak cluster

Create Model

public class MusicBand extends RiakModel{

	public String name;
	public String description;
	public MusicBand(String name, String description) {
		super(); = name;
		this.description = description;

Your model must extends RiakModel and annotating with @RiakEntity.
@RiakEntity contains two properties: bucket and key like {riak.url}/[bucket]/[key]

Usage sample


MusicBand m = new Album("Arcade Fire", "Rock band from Montreal");;

In database view that means:

{"name":"ArcadeFire","description":"Rock band from Montreal"}   

Misc posibility

Basic example :
// retrieve all element
List<MusicBand> list = MusicBand.findAll(MusicBand.class);

// find one element with that key
MusicBand m = MusicBand.find(MusicBand.class, "key");;

// use raw riak object
RiakObject riakObject = m.getObj();

//delete one element

// find all keys for one bucket
Collection<String> allKeys = MusicBand.findKeys(MusicBand.class);

Link example :
// add link
m.addLink(Album.class, "key", "tag");

// simple link walking
List<RiakModel> links = m.getLink();

Map/reduce example :
// count element with map/reduce query
long nbElement = RiakMP.count(MusicBand.class);

// retrieve order element by field 
Type listType = new TypeToken<List<MusicBand>>() {}.getType();
List<MusicBand> orderList = MusicBand.orderBy(MusicBand.class, "name", true, listType);

// find element order by last edit date
List<MusicBand> orderByDateList = MusicBand.findOrderByDate(MusicBand.class, listType);