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

Usage

Configuration

riak.url = http://127.0.0.1:8091/riak

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

Create Model

@RiakEntity(key="name")
public class MusicBand extends RiakModel{

	public String name;
	public String description;
	
	public MusicBand(String name, String description) {
		super();
		this.name = 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

Create

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

In database view that means:

curl http://127.0.0.1:8091/riak/MusicBand/ArcadeFire
{"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");
m.save();

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

//delete one element
m.delete();

// 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);

TODO List