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();
}
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;
}
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;
});
}
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");
}
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;
}
Aggregations