use of org.springframework.data.relational.core.sql.Column in project spring-data-jdbc by spring-projects.
the class ExpressionVisitorUnitTests method considersNamingStrategy.
// GH-1003
@Test
void considersNamingStrategy() {
ExpressionVisitor visitor = new ExpressionVisitor(new SimpleRenderContext(NamingStrategies.toUpper()));
Column expression = Column.create("col", Table.create("tab"));
expression.visit(visitor);
assertThat(visitor.getRenderedPart().toString()).isEqualTo("TAB.COL");
}
use of org.springframework.data.relational.core.sql.Column 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.Column 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;
}
use of org.springframework.data.relational.core.sql.Column in project spring-data-jdbc by spring-projects.
the class JoinVisitorTestsUnitTest method renderJoins.
static List<Fixture> renderJoins() {
Column colOne = Column.create("colOne", Table.create("tabOne"));
Table tabTwo = Table.create("tabTwo");
Column colTwo = Column.create("colTwo", tabTwo);
Column renamed = colOne.as("renamed");
Select select = Select.builder().select(renamed).from(colOne.getTable()).build();
InlineQuery inlineQuery = InlineQuery.create(select, "inline");
return Arrays.asList(fixture("simple join", new TestJoin(Join.JoinType.JOIN, tabTwo, colOne.isEqualTo(colTwo)), "JOIN tabTwo ON tabOne.colOne = tabTwo.colTwo"), fixture("inlineQuery", new TestJoin(Join.JoinType.JOIN, inlineQuery, colTwo.isEqualTo(inlineQuery.column("renamed"))), "JOIN (SELECT tabOne.colOne AS renamed FROM tabOne) inline ON tabTwo.colTwo = inline.renamed"));
}
use of org.springframework.data.relational.core.sql.Column in project spring-data-jdbc by spring-projects.
the class OrderByClauseVisitorUnitTests method shouldRenderOrderByAlias.
// DATAJDBC-309
@Test
void shouldRenderOrderByAlias() {
Table employee = SQL.table("employee").as("emp");
Column column = employee.column("name").as("emp_name");
Select select = Select.builder().select(column).from(employee).orderBy(OrderByField.from(column).asc()).build();
OrderByClauseVisitor visitor = new OrderByClauseVisitor(new SimpleRenderContext(NamingStrategies.asIs()));
select.visit(visitor);
assertThat(visitor.getRenderedPart().toString()).isEqualTo("emp_name ASC");
}
Aggregations