Skip to content
gsharma edited this page Jan 15, 2011 · 9 revisions

Getting started

Installing JOhm

You can install JOhm by:

Downloading it from github

In order to do this you should go to the Downloads section https://github.com/xetorthio/johm/archives/master and download the latest JAR.

Compiling the JAR from the source code

Clone the master branch from github:

git clone git://github.com/xetorthio/johm.git

And run:

mvn package

This will compile everything, run the tests and generate the JAR. In order to be able to run the tests you should have an up to date Redis instance (compiling master branch should be enough) in the default port (6379).

Configuring JOhm

The very first thing that you have to do is to decorate your model with some annotations and make your models extend from Model class. As an example, lets use the very known User class:

@Model
class User {
    @Id
    private Long id;
    @Attribute
    private String name;
    @Attribute
    @Indexed
    private int age;
    @Reference
    private Country country;
    @CollectionList(of = Comment.class)
    private List<Comment> comments;
    @CollectionSet(of = Item.class)
    private Set<Item> purchases;
}

By doing this your are enabling your classes to be able to persist in Redis.

The next step is telling JOhm how to get to Redis. This is very easy to do. JOhm has zero configuration burden. You just need to instantiate a JedisPool and give it to JOhm, like in the following example:

JedisPool jedisPool = new JedisPool(new Config(), "localhost");
JOhm.setPool(jedisPool);

Now you are ready to start using JOhm!