use of org.redisson.liveobject.resolver.NamingScheme in project redisson by redisson.
the class LiveObjectSearch method find.
public Set<Object> find(Class<?> entityClass, Condition condition) {
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass);
if (condition instanceof EQCondition) {
EQCondition c = (EQCondition) condition;
String indexName = namingScheme.getIndexName(entityClass, c.getName());
if (c.getValue() instanceof Number) {
RScoredSortedSet<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
double v = ((Number) c.getValue()).doubleValue();
Collection<Object> gtIds = set.valueRange(v, true, v, true);
return new HashSet<>(gtIds);
} else {
RSetMultimap<Object, Object> map = new RedissonSetMultimap<>(namingScheme.getCodec(), commandExecutor, indexName);
return map.getAll(c.getValue());
}
} else if (condition instanceof GTCondition) {
GTCondition c = (GTCondition) condition;
String indexName = namingScheme.getIndexName(entityClass, c.getName());
RScoredSortedSet<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
Collection<Object> gtIds = set.valueRange(c.getValue().doubleValue(), false, Double.POSITIVE_INFINITY, false);
return new HashSet<>(gtIds);
} else if (condition instanceof GECondition) {
GECondition c = (GECondition) condition;
String indexName = namingScheme.getIndexName(entityClass, c.getName());
RScoredSortedSet<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
Collection<Object> gtIds = set.valueRange(c.getValue().doubleValue(), true, Double.POSITIVE_INFINITY, false);
return new HashSet<>(gtIds);
} else if (condition instanceof LTCondition) {
LTCondition c = (LTCondition) condition;
String indexName = namingScheme.getIndexName(entityClass, c.getName());
RScoredSortedSet<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
Collection<Object> gtIds = set.valueRange(Double.NEGATIVE_INFINITY, false, c.getValue().doubleValue(), false);
return new HashSet<>(gtIds);
} else if (condition instanceof LECondition) {
LECondition c = (LECondition) condition;
String indexName = namingScheme.getIndexName(entityClass, c.getName());
RScoredSortedSet<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
Collection<Object> gtIds = set.valueRange(Double.NEGATIVE_INFINITY, false, c.getValue().doubleValue(), true);
return new HashSet<>(gtIds);
} else if (condition instanceof ORCondition) {
return traverseOr((ORCondition) condition, namingScheme, entityClass);
} else if (condition instanceof ANDCondition) {
return traverseAnd((ANDCondition) condition, namingScheme, entityClass);
}
throw new IllegalArgumentException();
}
use of org.redisson.liveobject.resolver.NamingScheme in project redisson by redisson.
the class AccessorInterceptor method removeIndex.
private void removeIndex(RMap<String, Object> liveMap, Object me, Field field) {
if (field.getAnnotation(RIndex.class) == null) {
return;
}
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(me.getClass().getSuperclass());
String indexName = namingScheme.getIndexName(me.getClass().getSuperclass(), field.getName());
CommandBatchService ce;
if (commandExecutor instanceof CommandBatchService) {
ce = (CommandBatchService) commandExecutor;
} else {
ce = new CommandBatchService(commandExecutor);
}
if (Number.class.isAssignableFrom(field.getType()) || PRIMITIVE_CLASSES.contains(field.getType())) {
RScoredSortedSetAsync<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), ce, indexName, null);
set.removeAsync(((RLiveObject) me).getLiveObjectId());
} else {
if (ClassUtils.isAnnotationPresent(field.getType(), REntity.class) || commandExecutor.getConnectionManager().isClusterMode()) {
Object value = liveMap.remove(field.getName());
if (value != null) {
RMultimapAsync<Object, Object> map = new RedissonSetMultimap<>(namingScheme.getCodec(), ce, indexName);
Object k = value;
if (ClassUtils.isAnnotationPresent(field.getType(), REntity.class)) {
k = ((RLiveObject) value).getLiveObjectId();
}
map.removeAsync(k, ((RLiveObject) me).getLiveObjectId());
}
} else {
removeAsync(ce, indexName, ((RedissonObject) liveMap).getRawName(), namingScheme.getCodec(), ((RLiveObject) me).getLiveObjectId(), field.getName());
}
}
if (ce != commandExecutor) {
ce.execute();
}
}
use of org.redisson.liveobject.resolver.NamingScheme in project redisson by redisson.
the class AccessorInterceptor method storeIndex.
private void storeIndex(Field field, Object me, Object arg) {
if (field.getAnnotation(RIndex.class) == null) {
return;
}
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(me.getClass().getSuperclass());
String indexName = namingScheme.getIndexName(me.getClass().getSuperclass(), field.getName());
boolean skipExecution = false;
CommandBatchService ce;
if (commandExecutor instanceof CommandBatchService) {
ce = (CommandBatchService) commandExecutor;
skipExecution = true;
} else {
ce = new CommandBatchService(commandExecutor);
}
if (arg instanceof Number) {
RScoredSortedSetAsync<Object> set = new RedissonScoredSortedSet<>(namingScheme.getCodec(), ce, indexName, null);
set.addAsync(((Number) arg).doubleValue(), ((RLiveObject) me).getLiveObjectId());
} else {
RMultimapAsync<Object, Object> map = new RedissonSetMultimap<>(namingScheme.getCodec(), ce, indexName);
map.putAsync(arg, ((RLiveObject) me).getLiveObjectId());
}
if (!skipExecution) {
ce.execute();
}
}
use of org.redisson.liveobject.resolver.NamingScheme in project redisson by redisson.
the class RedissonLiveObjectService method delete.
@Override
public <T> long delete(Class<T> entityClass, Object... ids) {
CommandBatchService ce = new CommandBatchService(commandExecutor);
FieldList<InDefinedShape> fields = Introspectior.getFieldsWithAnnotation(entityClass.getSuperclass(), RIndex.class);
Set<String> fieldNames = fields.stream().map(f -> f.getName()).collect(Collectors.toSet());
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass);
for (Object id : ids) {
delete(id, entityClass, namingScheme, ce, fieldNames);
}
BatchResult<Object> r = (BatchResult<Object>) ce.execute();
return r.getResponses().stream().filter(s -> s instanceof Long).mapToLong(s -> (Long) s).sum();
}
use of org.redisson.liveobject.resolver.NamingScheme in project redisson by redisson.
the class RedissonLiveObjectService method findIds.
@Override
public <K> Iterable<K> findIds(Class<?> entityClass, int count) {
NamingScheme namingScheme = commandExecutor.getObjectBuilder().getNamingScheme(entityClass);
String pattern = namingScheme.getNamePattern(entityClass);
RedissonKeys keys = new RedissonKeys(commandExecutor);
RedisCommand<ListScanResult<String>> command = new RedisCommand<>("SCAN", new ListMultiDecoder2(new ListScanResultReplayDecoder(), new ObjectListReplayDecoder<Object>()), new Convertor<Object>() {
@Override
public Object convert(Object obj) {
if (!(obj instanceof String)) {
return obj;
}
return namingScheme.resolveId(obj.toString());
}
});
return keys.getKeysByPattern(command, pattern, 0, count);
}
Aggregations