use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method getParentId.
private Object getParentId(DbAction.WithDependingOn<?> action) {
PersistentPropertyPathExtension path = new PersistentPropertyPathExtension(context, action.getPropertyPath());
PersistentPropertyPathExtension idPath = path.getIdDefiningParentPath();
DbAction.WithEntity<?> idOwningAction = getIdOwningAction(action, idPath);
return getPotentialGeneratedIdFrom(idOwningAction);
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method selectBuilder.
private SelectBuilder.SelectJoin selectBuilder(Table table) {
List<Expression> columnExpressions = new ArrayList<>();
RelationalPersistentEntity<?> entity = entityMetadata.getTableEntity();
SqlContext sqlContext = new SqlContext(entity);
List<Join> joinTables = new ArrayList<>();
for (PersistentPropertyPath<RelationalPersistentProperty> path : context.findPersistentPropertyPaths(entity.getType(), p -> true)) {
PersistentPropertyPathExtension extPath = new PersistentPropertyPathExtension(context, path);
if (returnedType.needsCustomConstruction()) {
if (!returnedType.getInputProperties().contains(extPath.getRequiredPersistentPropertyPath().getBaseProperty().getName())) {
continue;
}
}
// add a join if necessary
Join join = getJoin(sqlContext, extPath);
if (join != null) {
joinTables.add(join);
}
Column column = getColumn(sqlContext, extPath);
if (column != null) {
columnExpressions.add(column);
}
}
SelectBuilder.SelectAndFrom selectBuilder = StatementBuilder.select(columnExpressions);
SelectBuilder.SelectJoin baseSelect = selectBuilder.from(table);
for (Join join : joinTables) {
baseSelect = baseSelect.leftOuterJoin(join.joinTable).on(join.joinColumn).equals(join.parentId);
}
return baseSelect;
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class SqlGenerator method selectBuilder.
private SelectBuilder.SelectWhere selectBuilder(Collection<SqlIdentifier> keyColumns) {
Table table = getTable();
List<Expression> columnExpressions = new ArrayList<>();
List<Join> joinTables = new ArrayList<>();
for (PersistentPropertyPath<RelationalPersistentProperty> path : mappingContext.findPersistentPropertyPaths(entity.getType(), p -> true)) {
PersistentPropertyPathExtension extPath = new PersistentPropertyPathExtension(mappingContext, path);
// add a join if necessary
Join join = getJoin(extPath);
if (join != null) {
joinTables.add(join);
}
Column column = getColumn(extPath);
if (column != null) {
columnExpressions.add(column);
}
}
for (SqlIdentifier keyColumn : keyColumns) {
columnExpressions.add(table.column(keyColumn).as(keyColumn));
}
SelectBuilder.SelectAndFrom selectBuilder = StatementBuilder.select(columnExpressions);
SelectBuilder.SelectJoin baseSelect = selectBuilder.from(table);
for (Join join : joinTables) {
baseSelect = baseSelect.leftOuterJoin(join.joinTable).on(join.joinColumn).equals(join.parentId);
}
return (SelectBuilder.SelectWhere) baseSelect;
}
use of org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension in project spring-data-jdbc by spring-projects.
the class SqlGenerator method getJoin.
@Nullable
Join getJoin(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 SqlGenerator method createDeleteAllSql.
/**
* Create a {@code DELETE} query and optionally filter by {@link PersistentPropertyPath}.
*
* @param path can be {@literal null}.
* @return the statement as a {@link String}. Guaranteed to be not {@literal null}.
*/
String createDeleteAllSql(@Nullable PersistentPropertyPath<RelationalPersistentProperty> path) {
Table table = getTable();
DeleteBuilder.DeleteWhere deleteAll = Delete.builder().from(table);
if (path == null) {
return render(deleteAll.build());
}
return createDeleteByPathAndCriteria(new PersistentPropertyPathExtension(mappingContext, path), Column::isNotNull);
}
Aggregations