Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public SimpleRedisDocumentRepository( //

@Override
public Iterable<ID> getIds() {
List<ID> result = List.of();
Gson gson = gsonBuilder.create();
Optional<Field> maybeIdField = ObjectUtils.getIdFieldForEntityClass(metadata.getJavaType());
String idField = maybeIdField.map(Field::getName).orElse("id");
Expand Down Expand Up @@ -141,7 +140,7 @@ public void deleteById(ID id, Path path) {
@Override
public void updateField(T entity, MetamodelField<T, ?> field, Object value) {
modulesOperations.opsForJSON().set(getKey(Objects.requireNonNull(metadata.getId(entity))), value,
Path.of("$." + field.getSearchAlias()));
Path.of("$." + field.getSearchAlias().replace("_", ".")));
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -413,91 +412,4 @@ private SearchOperations<String> getSearchOps() {
return modulesOperations.opsForSearch(maybeSearchIndex.get());
}

// static class FluentQueryByExample<T> implements FluentQuery.FetchableFluentQuery<T> {
// private final SearchStream<T> searchStream;
// private final Class<T> probeType;
//
// private final SearchOperations<String> searchOps;
//
// public FluentQueryByExample( //
// Example<T> example, //
// Class<T> probeType, //
// EntityStream entityStream, //
// SearchOperations<String> searchOps //
// ) {
// this.probeType = probeType;
// this.searchOps = searchOps;
// this.searchStream = entityStream.of(probeType);
// searchStream.filter(example);
// }
//
// @Override
// public FetchableFluentQuery<T> sortBy(Sort sort) {
// searchStream.sorted(sort);
// return this;
// }
//
// @Override
// public <R> FetchableFluentQuery<R> as(Class<R> resultType) {
// throw new UnsupportedOperationException("`as` is not supported on a Redis Repositories");
// }
//
// @Override
// public FetchableFluentQuery<T> project(Collection<String> properties) {
// List<MetamodelField<?, ?>> metamodelFields = MetamodelUtils.getMetamodelFieldsForProperties(probeType,
// properties);
// metamodelFields.forEach(mmf -> searchStream.project((MetamodelField<? super T, ?>) mmf));
// return this;
// }
//
// @Override
// public T oneValue() {
// var result = searchStream.collect(Collectors.toList());
//
// if (org.springframework.util.ObjectUtils.isEmpty(result)) {
// return null;
// }
//
// if (result.size() > 1) {
// throw new IncorrectResultSizeDataAccessException("Query returned non unique result", 1);
// }
//
// return result.iterator().next();
// }
//
// @Override
// public T firstValue() {
// return searchStream.findFirst().orElse(null);
// }
//
// @Override
// public List<T> all() {
// return searchStream.collect(Collectors.toList());
// }
//
// @Override
// public Page<T> page(Pageable pageable) {
// Query query = (searchStream.backingQuery().isBlank()) ? new Query() : new Query(searchStream.backingQuery());
// query.limit(0, 0);
// SearchResult searchResult = searchOps.search(query);
// var count = searchResult.getTotalResults();
// var pageContents = searchStream.limit(pageable.getPageSize()).skip(pageable.getOffset()).collect(Collectors.toList());
// return new PageImpl<>(pageContents, pageable, count);
// }
//
// @Override
// public Stream<T> stream() {
// return all().stream();
// }
//
// @Override
// public long count() {
// return searchStream.count();
// }
//
// @Override
// public boolean exists() {
// return searchStream.count() > 0;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,20 @@ class BasicRedisDocumentMappingTest extends AbstractBaseDocumentTest {
@Autowired
SomeDocumentRepository someDocumentRepository;

@Autowired
DeepNestRepository deepNestRepository;

@BeforeEach
void cleanUp() {
flushSearchIndexFor(Company.class);
flushSearchIndexFor(DocWithSets.class);

if (deepNestRepository.count() == 0) {
DeepNest dn1 = DeepNest.of("dn-1", NestLevel1.of("nl-1-1", "Louis, I think this is the beginning of a beautiful friendship.", NestLevel2.of("nl-2-1", "Here's looking at you, kid.")));
DeepNest dn2 = DeepNest.of("dn-2", NestLevel1.of("nl-1-2", "Whoever you are, I have always depended on the kindness of strangers.", NestLevel2.of("nl-2-2", "Hey, you hens! Cut out the cackling in there!")));
DeepNest dn3 = DeepNest.of("dn-3", NestLevel1.of("nl-1-3", "A good body with a dull brain is as cheap as life itself.", NestLevel2.of("nl-2-3", "I'm Spartacus!")));
deepNestRepository.saveAll(List.of(dn1, dn2, dn3));
}
}

@Test
Expand Down Expand Up @@ -623,4 +633,18 @@ void testOrderByInMethodName() {
() -> assertThat(onlyVal3).containsExactly(doc3) //
);
}

@Test
void testUpdateDeepNestedField() {
Optional<DeepNest> dn1 = deepNestRepository.findFirstByNameIs("dn-1");
assertTrue(dn1.isPresent());
deepNestRepository.updateField(dn1.get(), DeepNest$.NEST_LEVEL1_NEST_LEVEL2_NAME, "dos-uno");

Optional<DeepNest> dn1After = deepNestRepository.findFirstByNameIs("dn-1");

assertAll( //
() -> assertTrue(dn1After.isPresent()), //
() -> assertEquals("dos-uno", dn1After.get().getNestLevel1().getNestLevel2().getName()) //
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.redis.om.spring.repository.RedisDocumentRepository;

@SuppressWarnings("unused") public interface DeepNestRepository extends RedisDocumentRepository<DeepNest, String> {
import java.util.Optional;

@SuppressWarnings("unused") public interface DeepNestRepository extends RedisDocumentRepository<DeepNest, String> {
Optional<DeepNest> findFirstByNameIs(String name);
}