Catch errs for Redis
This commit is contained in:
parent
2ec91e3dcf
commit
6b215cc337
@ -113,8 +113,12 @@ public class Document<V> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public Map<String, V> toMappedData() {
|
public Map<String, V> toMappedData() {
|
||||||
Map<String, V> mappedData = new LinkedHashMap<>(); // The mapped data
|
Map<String, V> mappedData = new LinkedHashMap<>(); // The mapped data
|
||||||
for (Map.Entry<String, Tuple<java.lang.reflect.Field, V>> entry : this.mappedData.entrySet()) {
|
try {
|
||||||
mappedData.put(entry.getKey(), entry.getValue().getRight());
|
for (Map.Entry<String, Tuple<java.lang.reflect.Field, V>> entry : this.mappedData.entrySet()) {
|
||||||
|
mappedData.put(entry.getKey(), entry.getValue().getRight());
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return mappedData;
|
return mappedData;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,6 @@ public abstract class Repository<D extends IDatabase<?, ?>, ID, E> {
|
|||||||
rawDataField = field;
|
rawDataField = field;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not the field we're looking for
|
// Not the field we're looking for
|
||||||
if (!field.isAnnotationPresent(me.braydon.feather.annotation.Field.class)) {
|
if (!field.isAnnotationPresent(me.braydon.feather.annotation.Field.class)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -7,12 +7,10 @@ package me.braydon.feather.database.impl.redis;
|
|||||||
|
|
||||||
import io.lettuce.core.api.sync.RedisCommands;
|
import io.lettuce.core.api.sync.RedisCommands;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.braydon.feather.common.Tuple;
|
|
||||||
import me.braydon.feather.data.Document;
|
import me.braydon.feather.data.Document;
|
||||||
import me.braydon.feather.database.Repository;
|
import me.braydon.feather.database.Repository;
|
||||||
import me.braydon.feather.database.impl.redis.annotation.TTL;
|
import me.braydon.feather.database.impl.redis.annotation.TTL;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -86,15 +84,13 @@ public class RedisRepository<ID, E> extends Repository<Redis, ID, E> {
|
|||||||
commands.hmset(key, document.toMappedData()); // Set the mapped document in the database
|
commands.hmset(key, document.toMappedData()); // Set the mapped document in the database
|
||||||
|
|
||||||
// Handling @TTL annotations
|
// Handling @TTL annotations
|
||||||
for (Tuple<Field, String> tuple : document.getMappedData().values()) {
|
Class<?> clazz = entity.getClass(); // The entity class
|
||||||
Field field = tuple.getLeft();
|
if (!clazz.isAnnotationPresent(TTL.class)) { // Missing @TTL
|
||||||
if (!field.isAnnotationPresent(TTL.class)) { // Missing @TTL
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
long ttl = clazz.getAnnotation(TTL.class).value(); // Get the ttl value
|
||||||
long ttl = field.getAnnotation(TTL.class).value(); // Get the ttl value
|
if (ttl > 0L) { // Value is above zero, set it
|
||||||
if (ttl > 0L) { // Value is above zero, set it
|
commands.expire(key, ttl);
|
||||||
commands.expire(key, ttl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (multi) { // Execute the commands in bulk
|
if (multi) { // Execute the commands in bulk
|
||||||
|
@ -8,7 +8,7 @@ package me.braydon.feather.database.impl.redis.annotation;
|
|||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fields flagged with this annotation will
|
* Entities tagged with this annotation will
|
||||||
* expire after the amount of defined seconds.
|
* expire after the amount of defined seconds.
|
||||||
*
|
*
|
||||||
* @author Braydon
|
* @author Braydon
|
||||||
|
Loading…
Reference in New Issue
Block a user