Skip to content

Commit

Permalink
Use TableLike in sqlgen
Browse files Browse the repository at this point in the history
  • Loading branch information
IAM20 committed Dec 9, 2021
1 parent 4d86beb commit 7a1dc3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.StatementBuilder;
import org.springframework.data.relational.core.sql.Table;
import org.springframework.data.relational.core.sql.TableLike;
import org.springframework.data.relational.core.sql.Update;
import org.springframework.data.relational.core.sql.UpdateBuilder;
import org.springframework.data.relational.core.sql.Visitor;
Expand Down Expand Up @@ -201,7 +202,7 @@ private Condition getSubselectCondition(PersistentPropertyPathExtension path,
return rootCondition.apply(filterColumn);
}

Table subSelectTable = Table.create(parentPath.getTableName());
TableLike subSelectTable = Table.create(parentPath.getTableName());
Column idColumn = subSelectTable.column(parentPath.getIdColumnName());
Column selectFilterColumn = subSelectTable.column(parentPath.getEffectiveIdColumnName());

Expand Down Expand Up @@ -290,7 +291,7 @@ String getFindAllByProperty(Identifier parentIdentifier, @Nullable SqlIdentifier
Assert.isTrue(keyColumn != null || !ordered,
"If the SQL statement should be ordered a keyColumn to order by must be provided.");

Table table = getTable();
TableLike table = getTable();

SelectBuilder.SelectWhere builder = selectBuilder(
keyColumn == null
Expand All @@ -308,7 +309,7 @@ String getFindAllByProperty(Identifier parentIdentifier, @Nullable SqlIdentifier
return render(select);
}

private Condition buildConditionForBackReference(Identifier parentIdentifier, Table table) {
private Condition buildConditionForBackReference(Identifier parentIdentifier, TableLike table) {

Condition condition = null;
for (SqlIdentifier backReferenceColumn : parentIdentifier.toMap().keySet()) {
Expand Down Expand Up @@ -479,7 +480,7 @@ private String createFindOneSql() {

private String createAcquireLockById(LockMode lockMode) {

Table table = this.getTable();
TableLike table = this.getTable();

Select select = StatementBuilder //
.select(getIdColumn()) //
Expand All @@ -493,7 +494,7 @@ private String createAcquireLockById(LockMode lockMode) {

private String createAcquireLockAll(LockMode lockMode) {

Table table = this.getTable();
TableLike table = this.getTable();

Select select = StatementBuilder //
.select(getIdColumn()) //
Expand All @@ -514,7 +515,7 @@ private SelectBuilder.SelectWhere selectBuilder() {

private SelectBuilder.SelectWhere selectBuilder(Collection<SqlIdentifier> keyColumns) {

Table table = getTable();
TableLike table = getTable();

List<Expression> columnExpressions = new ArrayList<>();

Expand Down Expand Up @@ -611,7 +612,7 @@ String selectFrom() {
return this.selectColumns();
}

Table table = getTable();
TableLike table = getTable();

List<Expression> columnExpressions = new ArrayList<>();

Expand Down Expand Up @@ -650,7 +651,7 @@ String selectFrom() {
* Additional custom method for {@link SqlProvider}.
*/
String selectAggregateFrom() {
Table table = getTable();
TableLike table = getTable();

List<Expression> columnExpressions = new ArrayList<>();

Expand All @@ -663,11 +664,11 @@ String selectAggregateFrom() {

// add a join if necessary
if (extPath.isEntity() && !extPath.isEmbedded()) {
Table currentTable = sqlContext.getTable(extPath);
TableLike currentTable = sqlContext.getTable(extPath);

PersistentPropertyPathExtension idDefiningParentPath =
extPath.getIdDefiningParentPath();
Table parentTable = sqlContext.getTable(idDefiningParentPath);
TableLike parentTable = sqlContext.getTable(idDefiningParentPath);

joinTables.add(new Join( //
currentTable, //
Expand Down Expand Up @@ -752,10 +753,10 @@ Join getJoin(PersistentPropertyPathExtension path) {
return null;
}

Table currentTable = sqlContext.getTable(path);
TableLike currentTable = sqlContext.getTable(path);

PersistentPropertyPathExtension idDefiningParentPath = path.getIdDefiningParentPath();
Table parentTable = sqlContext.getTable(idDefiningParentPath);
TableLike parentTable = sqlContext.getTable(idDefiningParentPath);

return new Join( //
currentTable, //
Expand All @@ -774,7 +775,7 @@ private String createFindAllInListSql() {

private String createExistsSql() {

Table table = getTable();
TableLike table = getTable();

Select select = StatementBuilder //
.select(Functions.count(getIdColumn())) //
Expand All @@ -787,7 +788,7 @@ private String createExistsSql() {

private String createCountSql() {

Table table = getTable();
TableLike table = getTable();

Select select = StatementBuilder //
.select(Functions.count(Expressions.asterisk())) //
Expand Down Expand Up @@ -1022,17 +1023,17 @@ private Expression getColumnExpression(
* DELOMBOK
*/
static class Join {
Table joinTable;
TableLike joinTable;
Column joinColumn;
Column parentId;

Join(Table joinTable, Column joinColumn, Column parentId) {
Join(TableLike joinTable, Column joinColumn, Column parentId) {
this.joinTable = joinTable;
this.joinColumn = joinColumn;
this.parentId = parentId;
}

Table getJoinTable() {
TableLike getJoinTable() {
return this.joinTable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.data.relational.core.sql.Aliased;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.Table;
import org.springframework.data.relational.core.sql.TableLike;

/**
* COPY org.springframework.data.relational.core.convert.SqlGeneratorUnitTests
Expand Down Expand Up @@ -649,7 +650,7 @@ public void joinForSecondLevelReference() {
public void joinForOneToOneWithoutId() {

SqlGenerator.Join join = generateJoin("child", ParentOfNoIdChild.class);
Table joinTable = join.getJoinTable();
TableLike joinTable = join.getJoinTable();

SoftAssertions.assertSoftly(softly -> {

Expand Down

0 comments on commit 7a1dc3c

Please sign in to comment.