use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method getJoin.
@Nullable
Join getJoin(SqlContext sqlContext, PersistentPropertyPathExtension path) {
if (!path.isEntity() || path.isEmbedded() || path.isMultiValued()) {
return null;
}
Table currentTable = sqlContext.getTable(path);
PersistentPropertyPathExtension idDefiningParentPath = path.getIdDefiningParentPath();
Table parentTable = sqlContext.getTable(idDefiningParentPath);
return new //
Join(//
currentTable, //
currentTable.column(path.getReverseColumnName()), //
parentTable.column(idDefiningParentPath.getIdColumnName()));
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method validate.
/**
* Validate parameters for the derived query. Specifically checking that the query method defines scalar parameters
* and collection parameters where required and that invalid parameter declarations are rejected.
*
* @param tree the tree structure defining the predicate of the query.
* @param parameters parameters for the predicate.
*/
static void validate(PartTree tree, Parameters<?, ?> parameters, MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context) {
RelationalQueryCreator.validate(tree, parameters);
for (PartTree.OrPart parts : tree) {
for (Part part : parts) {
PersistentPropertyPath<? extends RelationalPersistentProperty> propertyPath = context.getPersistentPropertyPath(part.getProperty());
PersistentPropertyPathExtension path = new PersistentPropertyPathExtension(context, propertyPath);
for (PersistentPropertyPathExtension pathToValidate = path; path.getLength() > 0; path = path.getParentPath()) {
validateProperty(pathToValidate);
}
}
}
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension 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.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method findAllByPath.
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.jdbc.support.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
@SuppressWarnings("unchecked")
public Iterable<Object> findAllByPath(Identifier identifier, PersistentPropertyPath<? extends RelationalPersistentProperty> propertyPath) {
Assert.notNull(identifier, "identifier must not be null.");
Assert.notNull(propertyPath, "propertyPath must not be null.");
PersistentPropertyPathExtension path = new PersistentPropertyPathExtension(context, propertyPath);
Class<?> actualType = path.getActualType();
String findAllByProperty = //
sql(actualType).getFindAllByProperty(identifier, path.getQualifierColumn(), path.isOrdered());
RowMapper<?> rowMapper = path.isMap() ? this.getMapEntityRowMapper(path, identifier) : this.getEntityRowMapper(path, identifier);
return operations.query(findAllByProperty, createParameterSource(identifier, getIdentifierProcessing()), (RowMapper<Object>) rowMapper);
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class SqlGenerator method getSubselectCondition.
/**
* Construct a IN-condition based on a {@link Select Sub-Select} which selects the ids (or stand ins for ids) of the
* given {@literal path} to those that reference the root entities specified by the {@literal rootCondition}.
*
* @param path specifies the table and id to select
* @param rootCondition the condition on the root of the path determining what to select
* @param filterColumn the column to apply the IN-condition to.
* @return the IN condition
*/
private Condition getSubselectCondition(PersistentPropertyPathExtension path, Function<Column, Condition> rootCondition, Column filterColumn) {
PersistentPropertyPathExtension parentPath = path.getParentPath();
if (!parentPath.hasIdProperty()) {
if (parentPath.getLength() > 1) {
return getSubselectCondition(parentPath, rootCondition, filterColumn);
}
return rootCondition.apply(filterColumn);
}
Table subSelectTable = Table.create(parentPath.getTableName());
Column idColumn = subSelectTable.column(parentPath.getIdColumnName());
Column selectFilterColumn = subSelectTable.column(parentPath.getEffectiveIdColumnName());
Condition innerCondition;
if (parentPath.getLength() == 1) {
// if the parent is the root of the path
// apply the rootCondition
innerCondition = rootCondition.apply(selectFilterColumn);
} else {
// otherwise we need another layer of subselect
innerCondition = getSubselectCondition(parentPath, rootCondition, selectFilterColumn);
}
Select select = //
Select.builder().select(//
idColumn).from(//
subSelectTable).where(innerCondition).build();
return filterColumn.in(select);
}
Aggregations