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

Jedis dependency version changed from 1.5.1 to 2.5.1 #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.settings/
target/
build/
/bin
8 changes: 4 additions & 4 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,7 +15,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>1.5.1</version>
<version>2.5.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand All @@ -31,8 +31,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/redis/clients/johm/JOhm.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.JedisException;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.TransactionBlock;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.johm.collections.RedisArray;

/**
* JOhm serves as the delegate responsible for heavy-lifting all mapping
* operations between the Object Models at one end and Redis Persistence Models
* on the other.
*/
@SuppressWarnings("deprecation")
public final class JOhm {
private static JedisPool jedisPool;

Expand Down Expand Up @@ -50,7 +51,7 @@ public static boolean isNew(final Object model) {
public static <T> T get(Class<?> clazz, long id) {
JOhmUtils.Validator.checkValidModelClazz(clazz);

Nest nest = new Nest(clazz);
Nest<T> nest = (Nest<T>) new Nest<>(clazz);
nest.setJedisPool(jedisPool);
if (!nest.cat(id).exists()) {
return null;
Expand Down Expand Up @@ -115,7 +116,7 @@ public static <T> List<T> find(Class<?> clazz, String attributeName,
if (JOhmUtils.isNullOrEmpty(attributeValue)) {
throw new InvalidFieldException();
}
Nest nest = new Nest(clazz);
Nest<T> nest = (Nest<T>) new Nest<>(clazz);
nest.setJedisPool(jedisPool);
Set<String> modelIdStrings = nest.cat(attributeName)
.cat(attributeValue).smembers();
Expand Down Expand Up @@ -147,11 +148,11 @@ public static <T> T save(final Object model) {
}

@SuppressWarnings("unchecked")
public static <T> T save(final Object model, boolean saveChildren) {
public static <T> T save(final Object model, boolean saveChildren) {
if (!isNew(model)) {
delete(model.getClass(), JOhmUtils.getId(model));
}
final Nest nest = initIfNeeded(model);
final Nest<?> nest = initIfNeeded(model);

final Map<String, String> hashedObject = new HashMap<String, String>();
Map<RedisArray<Object>, Object[]> pendingArraysToPersist = null;
Expand All @@ -168,6 +169,7 @@ public static <T> T save(final Object model, boolean saveChildren) {
}
if (field.isAnnotationPresent(Array.class)) {
Object[] backingArray = (Object[]) field.get(model);
JOhmUtils.Validator.checkNotNull(backingArray, field);
int actualLength = backingArray == null ? 0
: backingArray.length;
JOhmUtils.Validator.checkValidArrayBounds(field,
Expand All @@ -188,8 +190,9 @@ public static <T> T save(final Object model, boolean saveChildren) {
if (fieldValueObject != null) {
hashedObject
.put(fieldName, fieldValueObject.toString());
} else {
JOhmUtils.Validator.checkNotNull(fieldValueObject, field);
}

}
if (field.isAnnotationPresent(Reference.class)) {
fieldName = JOhmUtils.getReferenceKeyName(field);
Expand All @@ -203,13 +206,17 @@ public static <T> T save(final Object model, boolean saveChildren) {
}
hashedObject.put(fieldName, String.valueOf(JOhmUtils
.getId(child)));
} else {
JOhmUtils.Validator.checkNotNull(child, field);
}
}
if (field.isAnnotationPresent(Indexed.class)) {
Object fieldValue = field.get(model);
if (fieldValue != null
&& field.isAnnotationPresent(Reference.class)) {
fieldValue = JOhmUtils.getId(fieldValue);
} else {
JOhmUtils.Validator.checkNotNull(fieldValue, field);
}
if (!JOhmUtils.isNullOrEmpty(fieldValue)) {
nest.cat(fieldName).cat(fieldValue).sadd(
Expand Down Expand Up @@ -254,14 +261,13 @@ public static boolean delete(Class<?> clazz, long id) {
return delete(clazz, id, true, false);
}

@SuppressWarnings("unchecked")
public static boolean delete(Class<?> clazz, long id,
boolean deleteIndexes, boolean deleteChildren) {
JOhmUtils.Validator.checkValidModelClazz(clazz);
boolean deleted = false;
Object persistedModel = get(clazz, id);
if (persistedModel != null) {
Nest nest = new Nest(persistedModel);
Nest<?> nest = new Nest<>(persistedModel);
nest.setJedisPool(jedisPool);
if (deleteIndexes) {
// think about promoting deleteChildren as default behavior so
Expand Down Expand Up @@ -309,7 +315,7 @@ public static boolean delete(Class<?> clazz, long id,
if (field.isAnnotationPresent(Array.class)) {
field.setAccessible(true);
Array annotation = field.getAnnotation(Array.class);
RedisArray redisArray = new RedisArray(annotation
RedisArray<?> redisArray = new RedisArray<>(annotation
.length(), annotation.of(), nest, field,
persistedModel);
redisArray.clear();
Expand Down Expand Up @@ -352,23 +358,21 @@ private static void fillField(final Map<String, String> hashedObject,
}
}

@SuppressWarnings("unchecked")
private static void fillArrayField(final Nest nest, final Object model,
private static void fillArrayField(final Nest<?> nest, final Object model,
final Field field) throws IllegalArgumentException,
IllegalAccessException {
if (field.isAnnotationPresent(Array.class)) {
field.setAccessible(true);
Array annotation = field.getAnnotation(Array.class);
RedisArray redisArray = new RedisArray(annotation.length(),
RedisArray<?> redisArray = new RedisArray<>(annotation.length(),
annotation.of(), nest, field, model);
field.set(model, redisArray.read());
}
}

@SuppressWarnings("unchecked")
private static Nest initIfNeeded(final Object model) {
private static Nest<?> initIfNeeded(final Object model) {
Long id = JOhmUtils.getId(model);
Nest nest = new Nest(model);
Nest<?> nest = new Nest<>(model);
nest.setJedisPool(jedisPool);
if (id == null) {
// lazily initialize id, nest, collections
Expand All @@ -383,7 +387,7 @@ private static Nest initIfNeeded(final Object model) {
public static <T> Set<T> getAll(Class<?> clazz) {
JOhmUtils.Validator.checkValidModelClazz(clazz);
Set<Object> results = null;
Nest nest = new Nest(clazz);
Nest<T> nest = (Nest<T>) new Nest<>(clazz);
nest.setJedisPool(jedisPool);
Set<String> modelIdStrings = nest.cat("all").smembers();
if (modelIdStrings != null) {
Expand Down
Loading