use of org.springframework.data.relational.core.sql.Expression 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.Expression in project spring-data-jdbc by spring-projects.
the class QueryMapperUnitTests method shouldMapCountFunction.
// DATAJDBC-318
@Test
public void shouldMapCountFunction() {
Table table = Table.create("my_table").as("my_aliased_table");
Expression mappedObject = mapper.getMappedObject(Functions.count(table.column("alternative")), context.getRequiredPersistentEntity(Person.class));
assertThat(mappedObject).hasToString("COUNT(my_aliased_table.\"another_name\")");
}
use of org.springframework.data.relational.core.sql.Expression in project spring-data-jdbc by spring-projects.
the class QueryMapperUnitTests method shouldMapExpression.
// DATAJDBC-318
@Test
public void shouldMapExpression() {
Table table = Table.create("my_table").as("my_aliased_table");
Expression mappedObject = mapper.getMappedObject(table.column("alternative").as("my_aliased_col"), context.getRequiredPersistentEntity(Person.class));
assertThat(mappedObject).hasToString("my_aliased_table.\"another_name\" AS my_aliased_col");
}
use of org.springframework.data.relational.core.sql.Expression in project spring-data-jdbc by spring-projects.
the class QueryMapperUnitTests method shouldMapExpressionWithoutEntity.
// DATAJDBC-318
@Test
public void shouldMapExpressionWithoutEntity() {
Table table = Table.create("my_table").as("my_aliased_table");
Expression mappedObject = mapper.getMappedObject(table.column("my_col").as("my_aliased_col"), null);
assertThat(mappedObject).hasToString("my_aliased_table.my_col AS my_aliased_col");
}
use of org.springframework.data.relational.core.sql.Expression in project spring-data-jdbc by spring-projects.
the class QueryMapperUnitTests method shouldMapExpressionToUnknownColumn.
// DATAJDBC-318
@Test
public void shouldMapExpressionToUnknownColumn() {
Table table = Table.create("my_table").as("my_aliased_table");
Expression mappedObject = mapper.getMappedObject(table.column("unknown").as("my_aliased_col"), context.getRequiredPersistentEntity(Person.class));
assertThat(mappedObject).hasToString("my_aliased_table.unknown AS my_aliased_col");
}
Aggregations