use of org.springframework.data.relational.core.sql.Table 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.sql.Table in project spring-data-jdbc by spring-projects.
the class SqlContext method getTable.
Table getTable(PersistentPropertyPathExtension path) {
SqlIdentifier tableAlias = path.getTableAlias();
Table table = Table.create(path.getTableName());
return tableAlias == null ? table : table.as(tableAlias);
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class SqlGeneratorUnitTests method joinForOneToOneWithoutId.
// DATAJDBC-340
@Test
void joinForOneToOneWithoutId() {
SqlGenerator.Join join = generateJoin("child", ParentOfNoIdChild.class);
Table joinTable = join.getJoinTable();
assertSoftly(softly -> {
softly.assertThat(joinTable.getName()).isEqualTo(SqlIdentifier.quoted("NO_ID_CHILD"));
softly.assertThat(joinTable).isInstanceOf(Aliased.class);
softly.assertThat(((Aliased) joinTable).getAlias()).isEqualTo(SqlIdentifier.quoted("child"));
softly.assertThat(join.getJoinColumn().getTable()).isEqualTo(joinTable);
softly.assertThat(join.getJoinColumn().getName()).isEqualTo(SqlIdentifier.quoted("PARENT_OF_NO_ID_CHILD"));
softly.assertThat(join.getParentId().getName()).isEqualTo(SqlIdentifier.quoted("X_ID"));
softly.assertThat(join.getParentId().getTable().getName()).isEqualTo(SqlIdentifier.quoted("PARENT_OF_NO_ID_CHILD"));
});
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class DeleteRendererUnitTests method shouldConsiderTableAlias.
// DATAJDBC-335
@Test
public void shouldConsiderTableAlias() {
Table table = Table.create("bar").as("my_bar");
Delete delete = //
Delete.builder().from(table).where(//
table.column("foo").isEqualTo(table.column("baz"))).build();
assertThat(SqlRenderer.toString(delete)).isEqualTo("DELETE FROM bar my_bar WHERE my_bar.foo = my_bar.baz");
}
use of org.springframework.data.relational.core.sql.Table 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"));
}
Aggregations