use of org.springframework.data.relational.core.sql.SelectBuilder 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.sql.SelectBuilder in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method createSelectClause.
SelectBuilder.SelectLimitOffset createSelectClause(RelationalPersistentEntity<?> entity, Table table) {
SelectBuilder.SelectJoin builder;
if (tree.isExistsProjection()) {
Column idColumn = table.column(entity.getIdColumn());
builder = Select.builder().select(idColumn).from(table);
} else if (tree.isCountProjection()) {
builder = Select.builder().select(Functions.count(Expressions.asterisk())).from(table);
} else {
builder = selectBuilder(table);
}
return (SelectBuilder.SelectLimitOffset) builder;
}
Aggregations