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 @@ -16,7 +16,7 @@
import com.redis.om.spring.annotations.EnableRedisDocumentRepositories;

@SpringBootApplication
@EnableRedisDocumentRepositories(basePackages = "com.redis.om.documents.*")
@EnableRedisDocumentRepositories
public class RomsDocumentsApplication {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,32 @@ private Set<BeanDefinition> getBeanDefinitionsFor(ApplicationContext ac, Class..
if (app.isAnnotationPresent(EnableRedisDocumentRepositories.class)) {
EnableRedisDocumentRepositories edr = (EnableRedisDocumentRepositories) app
.getAnnotation(EnableRedisDocumentRepositories.class);
for (String pkg : edr.basePackages()) {
beanDefs.addAll(provider.findCandidateComponents(pkg));
if (edr.basePackages().length > 0) {
for (String pkg : edr.basePackages()) {
beanDefs.addAll(provider.findCandidateComponents(pkg));
}
} else if (edr.basePackageClasses().length > 0) {
for (Class<?> pkg : edr.basePackageClasses()) {
beanDefs.addAll(provider.findCandidateComponents(pkg.getPackageName()));
}
} else {
beanDefs.addAll(provider.findCandidateComponents(app.getPackageName()));
}
}

if (app.isAnnotationPresent(EnableRedisEnhancedRepositories.class)) {
EnableRedisEnhancedRepositories er = (EnableRedisEnhancedRepositories) app
.getAnnotation(EnableRedisEnhancedRepositories.class);
for (String pkg : er.basePackages()) {
beanDefs.addAll(provider.findCandidateComponents(pkg));
if (er.basePackages().length > 0) {
for (String pkg : er.basePackages()) {
beanDefs.addAll(provider.findCandidateComponents(pkg));
}
} else if (er.basePackageClasses().length > 0) {
for (Class<?> pkg : er.basePackageClasses()) {
beanDefs.addAll(provider.findCandidateComponents(pkg.getPackageName()));
}
} else {
beanDefs.addAll(provider.findCandidateComponents(app.getPackageName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ else if (targetCls == Point.class) {
blockBuilder.add(initCodeBlock);
}
blockBuilder.nextControlFlow("catch($T | $T e)", NoSuchFieldException.class, SecurityException.class);
blockBuilder.addStatement("System.err.println(\"e.getMessage()\")");
blockBuilder.addStatement("System.err.println(e.getMessage())");
blockBuilder.endControlFlow();

CodeBlock staticBlock = blockBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.keyvalue.repository.KeyValueRepository;
import org.springframework.data.repository.NoRepositoryBean;

import com.redis.om.spring.metamodel.FieldOperationInterceptor;
import com.redislabs.modules.rejson.Path;

@NoRepositoryBean
Expand All @@ -20,4 +21,6 @@ public interface RedisDocumentRepository<T, ID> extends KeyValueRepository<T, ID
Page<ID> getIds(Pageable pageable);

void deleteById(ID id, Path path);

void updateField(T entity, FieldOperationInterceptor<T, ?> field, Object value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.repository.core.EntityInformation;

import com.redis.om.spring.metamodel.FieldOperationInterceptor;
import com.redis.om.spring.ops.RedisModulesOperations;
import com.redis.om.spring.repository.RedisDocumentRepository;
import com.redislabs.modules.rejson.Path;
Expand Down Expand Up @@ -54,4 +55,9 @@ public void deleteById(ID id, Path path) {
modulesOperations.opsForJSON().del(metadata.getJavaType().getName() + ":" + id.toString(), path);
}

@Override
public void updateField(T entity, FieldOperationInterceptor<T, ?> field, Object value) {
modulesOperations.opsForJSON().set(metadata.getJavaType().getName() + ":" + metadata.getId(entity).toString(), value, Path.of("$." + field.getField().getName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.redis.om.spring.AbstractBaseDocumentTest;
import com.redis.om.spring.annotations.document.fixtures.Company;
import com.redis.om.spring.annotations.document.fixtures.Company$;
import com.redis.om.spring.annotations.document.fixtures.CompanyRepository;

public class BasicRedisDocumentMappingTest extends AbstractBaseDocumentTest {
Expand Down Expand Up @@ -52,6 +53,18 @@ public void testBasicCrudOperations() {
assertEquals(0, repository.count());
}

@Test
public void testUpdateSingleField() {
Company redisInc = repository.save(Company.of("RedisInc", 2011, new Point(-122.066540, 37.377690)));
repository.updateField(redisInc, Company$.NAME, "Redis");

Optional<Company> maybeRedis = repository.findById(redisInc.getId());

assertTrue(maybeRedis.isPresent());

assertEquals("Redis", maybeRedis.get().getName());
}

@Test
public void testAuditAnnotations() {
Company redis = repository.save(Company.of("RedisInc", 2011, new Point(-122.066540, 37.377690)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.redis.om.spring.AbstractBaseDocumentTest;
import com.redis.om.spring.ops.RedisModulesOperations;
import com.redislabs.modules.rejson.Path;

public class OpsForJSONTest extends AbstractBaseDocumentTest {

Expand Down Expand Up @@ -39,4 +40,21 @@ public void testJSONClient() {

assertEquals(obj, ops.get("obj", IRLObject.class));
}

@Test
public void testSetWithPath() {
JSONOperations<String> ops = modulesOperations.opsForJSON();

IRLObject obj = new IRLObject();
ops.set("obj", obj);

IRLObject obj1 = ops.get("obj", IRLObject.class);

assertEquals("string", obj1.str);

ops.set("obj", "String", Path.of("$.str"));
IRLObject obj2 = ops.get("obj", IRLObject.class);

assertEquals("String", obj2.str);
}
}