Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for JDK 1.8 #63

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.settings/
target/
build/
*.idea
*.iml
206 changes: 126 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Durable data storage is available via the Redis Append-only file (AOF). The defa
JOhm is still in active development. The following features are currently available:

- Basic attribute persistence (String, Integer, etc...)
- Enums
- Auto-numeric Ids
- References
- Arrays
Expand All @@ -28,110 +29,155 @@ Stay close! It is growing pretty fast!
You can download the latest build at [http://github.com/xetorthio/johm/downloads](http://github.com/xetorthio/johm/downloads)

And this is a small example (getters and setters are not included for the sake of simplicity):

@Model
class User {
@Id
private Long id;
@Attribute
private String name;
@Attribute
@Indexed
private int age;
@Reference
@Indexed
private Country country;
@CollectionList(of = Comment.class)
@Indexed
private List<Comment> comments;
@CollectionSet(of = Item.class)
@Indexed
private Set<Item> purchases;
@CollectionMap(key = Integer.class, value = Item.class)
@Indexed
private Map<Integer, Item> favoritePurchases;
@CollectionSortedSet(of = Item.class, by = "price")
@Indexed
private Set<Item> orderedPurchases;
@Array(of = Item.class, length = 3)
@Indexed
private Item[] threeLatestPurchases;
}

@Model
class Comment {
@Id
private Long id;
@Attribute
private String text;
}

@Model
class Item {
@Id
private Long id;
@Attribute
private String name;
}

```java
@Model
class User {
@Id
private Long id;
@Attribute
private String name;
@Attribute
@Indexed
private int age;
@Reference
@Indexed
private Country country;
@CollectionList(of = Comment.class)
@Indexed
private List<Comment> comments;
@CollectionSet(of = Item.class)
@Indexed
private Set<Item> purchases;
@CollectionMap(key = Integer.class, value = Item.class)
@Indexed
private Map<Integer, Item> favoritePurchases;
@CollectionSortedSet(of = Item.class, by = "price")
@Indexed
private Set<Item> orderedPurchases;
@Array(of = Item.class, length = 3)
@Indexed
private Item[] threeLatestPurchases;
}

// The value() of @Model can be used to use a specific key in redis
// If not set then the Java Class<?>.getSimpleName() is used as default
@Model("Com")
class Comment {
@Id
private Long id;
@Attribute
private String text;
@Attribute
private Status status;
}

@Model
class Item {
@Id
private Long id;
@Attribute
private String name;
}

enum Status {
WAITING_FOR_MODERATION, VALID, FLAGGED
}
```

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

```java
JedisPool jedisPool = new JedisPool(new GenericObjectPoolConfig(), "localhost");
JOhm.setPool(jedisPool);
```

Creating a User and persisting it:

User someOne = new User();
someOne.setName("Someone");
someOne.setAge(30);
JOhm.save(someOne);
```java
User someOne = new User();
someOne.setName("Someone");
someOne.setAge(30);
JOhm.save(someOne);
```

Loading a persisted User:

User storedUser = JOhm.get(User.class, 1);


```java
User storedUser = JOhm.get(User.class, 1);
```

You can avoid properties being loaded:

```java
User userWithoutComments = JOhm.get(User.class, 1, "comments");
```

Checking if a User exists:

```java
boolean user2Exists = JOhm.exists(User.class, 42);
```

Deleting a User:

JOhm.delete(User.class, 1);
```java
JOhm.delete(User.class, 1);
```

Search for all users of age 30:

List<User> users = JOhm.find(User.class, "age", "30");

```java
List<User> users = JOhm.find(User.class, "age", "30");
```

Search for all users of age 30, without returning their favorite purchases:

```java
List<User> users = JOhm.find(User.class, "age", "30", "favoritePurchases");
```

Model with a reference:

User someOne = new User();
...
JOhm.save(someOne);
```java
User someOne = new User();
...
JOhm.save(someOne);

Country someCountry = new Country();
...
JOhm.save(country);
Country someCountry = new Country();
...
JOhm.save(country);

someOne.setCountry(someCountry);
someOne.setCountry(someCountry);
```

Model with a list of nested models:

User someOne = new User();
...
JOhm.save(someOne);

Comment aComment = new Comment();
...
JOhm.save(aComment);

someOne.getComments.add(aComment);
```java
User someOne = new User();
...
JOhm.save(someOne);

Comment aComment = new Comment();
...
JOhm.save(aComment);

someOne.getComments().add(aComment);
```

Model with a set of nested models:

User someOne = new User();
...
JOhm.save(someOne);
```java
User someOne = new User();
...
JOhm.save(someOne);

Item anItem = new Item();
...
JOhm.save(anItem);
Item anItem = new Item();
...
JOhm.save(anItem);

someOne.getPurchases.add(anItem);
someOne.getPurchases().add(anItem);
```

For more usage examples check the tests.

Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>redis</groupId>
<artifactId>johm</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -15,11 +15,17 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>1.5.1</version>
<version>2.5.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
</dependencies>
Expand Down
Loading