use of org.springframework.data.mapping.PersistentPropertyPath in project spring-data-mongodb by spring-projects.
the class QueryMapper method filterUnwrappedObjects.
private Document filterUnwrappedObjects(Document fieldsObject, @Nullable MongoPersistentEntity<?> entity) {
if (fieldsObject.isEmpty() || entity == null) {
return fieldsObject;
}
Document target = new Document();
for (Entry<String, Object> field : fieldsObject.entrySet()) {
try {
PropertyPath path = PropertyPath.from(field.getKey(), entity.getTypeInformation());
PersistentPropertyPath<MongoPersistentProperty> persistentPropertyPath = mappingContext.getPersistentPropertyPath(path);
MongoPersistentProperty property = mappingContext.getPersistentPropertyPath(path).getRequiredLeafProperty();
if (property.isUnwrapped() && property.isEntity()) {
MongoPersistentEntity<?> unwrappedEntity = mappingContext.getRequiredPersistentEntity(property);
for (MongoPersistentProperty unwrappedProperty : unwrappedEntity) {
DotPath dotPath = DotPath.from(persistentPropertyPath.toDotPath()).append(unwrappedProperty.getName());
target.put(dotPath.toString(), field.getValue());
}
} else {
target.put(field.getKey(), field.getValue());
}
} catch (RuntimeException e) {
target.put(field.getKey(), field.getValue());
}
}
return target;
}
use of org.springframework.data.mapping.PersistentPropertyPath in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method getParentKeys.
private Identifier getParentKeys(DbAction.WithDependingOn<?> action, JdbcConverter converter) {
Object id = getParentId(action);
JdbcIdentifierBuilder identifier = //
JdbcIdentifierBuilder.forBackReferences(converter, new PersistentPropertyPathExtension(context, action.getPropertyPath()), id);
for (Map.Entry<PersistentPropertyPath<RelationalPersistentProperty>, Object> qualifier : action.getQualifiers().entrySet()) {
identifier = identifier.withQualifier(new PersistentPropertyPathExtension(context, qualifier.getKey()), qualifier.getValue());
}
return identifier.build();
}
use of org.springframework.data.mapping.PersistentPropertyPath in project spring-data-jdbc by spring-projects.
the class MyBatisDataAccessStrategyUnitTests method findAllByPath.
@SuppressWarnings("unchecked")
// DATAJDBC-384
@Test
public void findAllByPath() {
RelationalPersistentProperty property = mock(RelationalPersistentProperty.class, RETURNS_DEEP_STUBS);
PersistentPropertyPath path = mock(PersistentPropertyPath.class, RETURNS_DEEP_STUBS);
when(path.getBaseProperty()).thenReturn(property);
when(property.getOwner().getType()).thenReturn((Class) String.class);
when(path.getRequiredLeafProperty()).thenReturn(property);
when(property.getType()).thenReturn((Class) Number.class);
when(path.toDotPath()).thenReturn("dot.path");
accessStrategy.findAllByPath(Identifier.empty(), path);
verify(session).selectList(eq("java.lang.StringMapper.findAllByPath-dot.path"), captor.capture());
//
assertThat(captor.getValue()).isNotNull().extracting(//
MyBatisContext::getInstance, //
MyBatisContext::getId, //
MyBatisContext::getIdentifier, //
MyBatisContext::getDomainType, //
c -> c.get("key")).containsExactly(//
null, //
null, //
Identifier.empty(), //
Number.class, //
null);
}
Aggregations