Search in sources :

Example 1 with PersistentPropertyPath

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;
}
Also used : DotPath(org.springframework.data.mongodb.util.DotPath) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) InvalidPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) PropertyPath(org.springframework.data.mapping.PropertyPath) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Document(org.bson.Document) NestedDocument(org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument)

Example 2 with PersistentPropertyPath

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();
}
Also used : JdbcIdentifierBuilder(org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder) PersistentPropertyPathExtension(org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with PersistentPropertyPath

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) PageRequest(org.springframework.data.domain.PageRequest) PropertyPathTestingUtils(org.springframework.data.jdbc.core.PropertyPathTestingUtils) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ArgumentCaptor(org.mockito.ArgumentCaptor) IdentifierProcessing(org.springframework.data.relational.core.sql.IdentifierProcessing) Assertions(org.assertj.core.api.Assertions) Sort(org.springframework.data.domain.Sort) Collections(java.util.Collections) SqlSession(org.apache.ibatis.session.SqlSession) JdbcConverter(org.springframework.data.jdbc.core.convert.JdbcConverter) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier) Identifier(org.springframework.data.jdbc.core.convert.Identifier) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) Test(org.junit.jupiter.api.Test)

Aggregations

PersistentPropertyPath (org.springframework.data.mapping.PersistentPropertyPath)3 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Assertions (org.assertj.core.api.Assertions)1 Document (org.bson.Document)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Mockito (org.mockito.Mockito)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 PropertyPathTestingUtils (org.springframework.data.jdbc.core.PropertyPathTestingUtils)1 BasicJdbcConverter (org.springframework.data.jdbc.core.convert.BasicJdbcConverter)1