use of net.bytebuddy.description.field.FieldDescription.InDefinedShape 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 net.bytebuddy.description.field.FieldDescription.InDefinedShape in project redisson by redisson.
the class RedissonLiveObjectService method validateClass.
private <T> void validateClass(Class<T> entityClass) {
if (entityClass.isAnonymousClass() || entityClass.isLocalClass()) {
throw new IllegalArgumentException(entityClass.getName() + " is not publically accessable.");
}
if (!ClassUtils.isAnnotationPresent(entityClass, REntity.class)) {
throw new IllegalArgumentException("REntity annotation is missing from class type declaration.");
}
FieldList<FieldDescription.InDefinedShape> fields = Introspectior.getFieldsWithAnnotation(entityClass, RIndex.class);
fields = fields.filter(ElementMatchers.fieldType(ElementMatchers.hasSuperType(ElementMatchers.anyOf(Map.class, Collection.class, RObject.class))));
for (InDefinedShape field : fields) {
throw new IllegalArgumentException("RIndex annotation couldn't be defined for field '" + field.getName() + "' with type '" + field.getType() + "'");
}
FieldList<FieldDescription.InDefinedShape> fieldsWithRIdAnnotation = Introspectior.getFieldsWithAnnotation(entityClass, RId.class);
if (fieldsWithRIdAnnotation.size() == 0) {
throw new IllegalArgumentException("RId annotation is missing from class field declaration.");
}
if (fieldsWithRIdAnnotation.size() > 1) {
throw new IllegalArgumentException("Only one field with RId annotation is allowed in class field declaration.");
}
FieldDescription.InDefinedShape idFieldDescription = fieldsWithRIdAnnotation.getOnly();
String idFieldName = idFieldDescription.getName();
Field idField = null;
try {
idField = ClassUtils.getDeclaredField(entityClass, idFieldName);
} catch (Exception e) {
throw new IllegalStateException(e);
}
if (ClassUtils.isAnnotationPresent(idField.getType(), REntity.class)) {
throw new IllegalArgumentException("Field with RId annotation cannot be a type of which class is annotated with REntity.");
}
if (idField.getType().isAssignableFrom(RObject.class)) {
throw new IllegalArgumentException("Field with RId annotation cannot be a type of RObject");
}
}
Aggregations