Search in sources :

Example 1 with PropertyPath

use of org.springframework.data.mapping.PropertyPath in project spring-data-jdbc by spring-projects.

the class DefaultJdbcInterpreter method getColumnNameForReverseColumn.

private <T> String getColumnNameForReverseColumn(Insert<T> insert, JdbcPersistentEntity<?> persistentEntity) {
    PropertyPath path = insert.getPropertyPath().getPath();
    Assert.notNull(path, "There shouldn't be an insert depending on another insert without having a PropertyPath.");
    return persistentEntity.getRequiredPersistentProperty(path.getSegment()).getReverseColumnName();
}
Also used : PropertyPath(org.springframework.data.mapping.PropertyPath)

Example 2 with PropertyPath

use of org.springframework.data.mapping.PropertyPath in project spring-data-keyvalue by spring-projects.

the class KeyValueQuerydslUtils method buildOrderPropertyPathFrom.

/**
 * Creates an {@link Expression} for the given {@link Order} property.
 *
 * @param order must not be {@literal null}.
 * @param builder must not be {@literal null}.
 * @return
 */
private static Expression<?> buildOrderPropertyPathFrom(Order order, PathBuilder<?> builder) {
    Assert.notNull(order, "Order must not be null!");
    Assert.notNull(builder, "Builder must not be null!");
    PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
    Expression<?> sortPropertyExpression = builder;
    while (path != null) {
        if (!path.hasNext() && order.isIgnoreCase()) {
            // if order is ignore-case we have to treat the last path segment as a String.
            sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
        } else {
            sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
        }
        path = path.next();
    }
    return sortPropertyExpression;
}
Also used : Path(com.querydsl.core.types.Path) PropertyPath(org.springframework.data.mapping.PropertyPath) PropertyPath(org.springframework.data.mapping.PropertyPath)

Example 3 with PropertyPath

use of org.springframework.data.mapping.PropertyPath in project spring-data-commons by spring-projects.

the class PropertyPathInformation method reifyPath.

private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) {
    Optional<Path<?>> map = // 
    base.filter(it -> it instanceof CollectionPathBase).map(CollectionPathBase.class::cast).map(// 
    CollectionPathBase::any).map(// 
    Path.class::cast).map(it -> reifyPath(resolver, path, Optional.of(it)));
    return map.orElseGet(() -> {
        Path<?> entityPath = base.orElseGet(() -> resolver.createPath(path.getOwningType().getType()));
        Field field = org.springframework.data.util.ReflectionUtils.findRequiredField(entityPath.getClass(), path.getSegment());
        Object value = ReflectionUtils.getField(field, entityPath);
        PropertyPath next = path.next();
        if (next != null) {
            return reifyPath(resolver, next, Optional.of((Path<?>) value));
        }
        return (Path<?>) value;
    });
}
Also used : Path(com.querydsl.core.types.Path) PropertyPath(org.springframework.data.mapping.PropertyPath) Field(java.lang.reflect.Field) PropertyPath(org.springframework.data.mapping.PropertyPath) CollectionPathBase(com.querydsl.core.types.dsl.CollectionPathBase)

Example 4 with PropertyPath

use of org.springframework.data.mapping.PropertyPath in project spring-data-mongodb by spring-projects.

the class DbRefMappingMongoConverterUnitTests method createsDBRefWithClientSpecCorrectly.

// DATAMONGO-347
@Test
void createsDBRefWithClientSpecCorrectly() {
    PropertyPath path = PropertyPath.from("person", PersonClient.class);
    MongoPersistentProperty property = mappingContext.getPersistentPropertyPath(path).getLeafProperty();
    Person person = new Person();
    person.id = "foo";
    DBRef dbRef = converter.toDBRef(person, property);
    assertThat(dbRef.getId()).isEqualTo("foo");
    assertThat(dbRef.getCollectionName()).isEqualTo("person");
}
Also used : MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) PropertyPath(org.springframework.data.mapping.PropertyPath) DBRef(com.mongodb.DBRef) Person(org.springframework.data.mongodb.core.convert.MappingMongoConverterUnitTests.Person) Test(org.junit.jupiter.api.Test)

Example 5 with PropertyPath

use of org.springframework.data.mapping.PropertyPath in project spring-data-jdbc by spring-projects.

the class JdbcMappingContext method referencedEntities.

public List<PropertyPath> referencedEntities(Class<?> rootType, PropertyPath path) {
    List<PropertyPath> paths = new ArrayList<>();
    Class<?> currentType = path == null ? rootType : path.getLeafType();
    JdbcPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(currentType);
    for (JdbcPersistentProperty property : persistentEntity) {
        if (property.isEntity()) {
            PropertyPath nextPath = path == null ? PropertyPath.from(property.getName(), rootType) : path.nested(property.getName());
            paths.add(nextPath);
            paths.addAll(referencedEntities(rootType, nextPath));
        }
    }
    Collections.reverse(paths);
    return paths;
}
Also used : PropertyPath(org.springframework.data.mapping.PropertyPath) ArrayList(java.util.ArrayList)

Aggregations

PropertyPath (org.springframework.data.mapping.PropertyPath)6 Path (com.querydsl.core.types.Path)2 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 DBRef (com.mongodb.DBRef)1 CollectionPathBase (com.querydsl.core.types.dsl.CollectionPathBase)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Document (org.bson.Document)1 Test (org.junit.jupiter.api.Test)1 PersistentPropertyPath (org.springframework.data.mapping.PersistentPropertyPath)1 InvalidPersistentPropertyPath (org.springframework.data.mapping.context.InvalidPersistentPropertyPath)1 NestedDocument (org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument)1 Person (org.springframework.data.mongodb.core.convert.MappingMongoConverterUnitTests.Person)1 DotPath (org.springframework.data.mongodb.util.DotPath)1