Project mangled field names.

Closes #2057.
This commit is contained in:
mikereiche
2025-06-12 15:48:02 -07:00
parent 5b5a8f6ede
commit 41f523368f
3 changed files with 13 additions and 2 deletions

View File

@@ -1154,7 +1154,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
}
String maybeMangle(PersistentProperty<?> property) {
public String maybeMangle(PersistentProperty<?> property) {
Assert.notNull(property, "property");
if (!conversions.hasValueConverter(property)) {
return ((CouchbasePersistentProperty) property).getFieldName();

View File

@@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
import org.springframework.data.couchbase.core.mapping.CouchbaseList;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
@@ -328,7 +329,13 @@ public class StringBasedN1qlQueryParser {
if (fieldList == null || fieldList.contains(prop.getFieldName())) {
PersistentPropertyPath<CouchbasePersistentProperty> path = couchbaseConverter.getMappingContext()
.getPersistentPropertyPath(prop.getName(), persistentEntity.getTypeInformation().getType());
projectField = N1qlQueryCreator.addMetaIfRequired(bucketName, path, prop, persistentEntity).toString();
String unmangled = prop.getFieldName();
String maybeMangled =((MappingCouchbaseConverter)couchbaseConverter).maybeMangle(prop);
if(maybeMangled.equals(unmangled)) {
projectField = N1qlQueryCreator.addMetaIfRequired(bucketName, path, prop, persistentEntity).toString();
} else {
projectField = i(maybeMangled).toString();
}
if (sb.length() > 0) {
sb.append(", ");
}

View File

@@ -154,10 +154,14 @@ public class CouchbaseRepositoryFieldLevelEncryptionIntegrationTests extends Clu
assertFalse(userEncryptedRepository.existsById(user.getId()));
userEncryptedRepository.save(user);
// read the user with Spring
Optional<UserEncrypted> writeSpringReadSpring = userEncryptedRepository.findById(user.getId());
assertTrue(writeSpringReadSpring.isPresent());
writeSpringReadSpring.ifPresent(u -> assertEquals(user, u));
List<UserEncrypted> writeSpringReadSpring2 = userEncryptedRepository.findAll();
assertEquals(user, writeSpringReadSpring2.stream().filter(u -> u.getId().equals(user.getId())).findFirst().get());
if (cleanAfter) {
try {
couchbaseTemplate.removeById(UserEncrypted.class).one(user.getId());