Skip to content

Commit 7a1dc3c

Browse files
committed
Use TableLike in sqlgen
1 parent 4d86beb commit 7a1dc3c

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

spring-data-jdbc-plus-sql/src/main/java/com/navercorp/spring/data/jdbc/plus/sql/convert/SqlGenerator.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import org.springframework.data.relational.core.sql.SqlIdentifier;
7474
import org.springframework.data.relational.core.sql.StatementBuilder;
7575
import org.springframework.data.relational.core.sql.Table;
76+
import org.springframework.data.relational.core.sql.TableLike;
7677
import org.springframework.data.relational.core.sql.Update;
7778
import org.springframework.data.relational.core.sql.UpdateBuilder;
7879
import org.springframework.data.relational.core.sql.Visitor;
@@ -201,7 +202,7 @@ private Condition getSubselectCondition(PersistentPropertyPathExtension path,
201202
return rootCondition.apply(filterColumn);
202203
}
203204

204-
Table subSelectTable = Table.create(parentPath.getTableName());
205+
TableLike subSelectTable = Table.create(parentPath.getTableName());
205206
Column idColumn = subSelectTable.column(parentPath.getIdColumnName());
206207
Column selectFilterColumn = subSelectTable.column(parentPath.getEffectiveIdColumnName());
207208

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

293-
Table table = getTable();
294+
TableLike table = getTable();
294295

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

311-
private Condition buildConditionForBackReference(Identifier parentIdentifier, Table table) {
312+
private Condition buildConditionForBackReference(Identifier parentIdentifier, TableLike table) {
312313

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

480481
private String createAcquireLockById(LockMode lockMode) {
481482

482-
Table table = this.getTable();
483+
TableLike table = this.getTable();
483484

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

494495
private String createAcquireLockAll(LockMode lockMode) {
495496

496-
Table table = this.getTable();
497+
TableLike table = this.getTable();
497498

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

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

517-
Table table = getTable();
518+
TableLike table = getTable();
518519

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

@@ -611,7 +612,7 @@ String selectFrom() {
611612
return this.selectColumns();
612613
}
613614

614-
Table table = getTable();
615+
TableLike table = getTable();
615616

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

@@ -650,7 +651,7 @@ String selectFrom() {
650651
* Additional custom method for {@link SqlProvider}.
651652
*/
652653
String selectAggregateFrom() {
653-
Table table = getTable();
654+
TableLike table = getTable();
654655

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

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

664665
// add a join if necessary
665666
if (extPath.isEntity() && !extPath.isEmbedded()) {
666-
Table currentTable = sqlContext.getTable(extPath);
667+
TableLike currentTable = sqlContext.getTable(extPath);
667668

668669
PersistentPropertyPathExtension idDefiningParentPath =
669670
extPath.getIdDefiningParentPath();
670-
Table parentTable = sqlContext.getTable(idDefiningParentPath);
671+
TableLike parentTable = sqlContext.getTable(idDefiningParentPath);
671672

672673
joinTables.add(new Join( //
673674
currentTable, //
@@ -752,10 +753,10 @@ Join getJoin(PersistentPropertyPathExtension path) {
752753
return null;
753754
}
754755

755-
Table currentTable = sqlContext.getTable(path);
756+
TableLike currentTable = sqlContext.getTable(path);
756757

757758
PersistentPropertyPathExtension idDefiningParentPath = path.getIdDefiningParentPath();
758-
Table parentTable = sqlContext.getTable(idDefiningParentPath);
759+
TableLike parentTable = sqlContext.getTable(idDefiningParentPath);
759760

760761
return new Join( //
761762
currentTable, //
@@ -774,7 +775,7 @@ private String createFindAllInListSql() {
774775

775776
private String createExistsSql() {
776777

777-
Table table = getTable();
778+
TableLike table = getTable();
778779

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

788789
private String createCountSql() {
789790

790-
Table table = getTable();
791+
TableLike table = getTable();
791792

792793
Select select = StatementBuilder //
793794
.select(Functions.count(Expressions.asterisk())) //
@@ -1022,17 +1023,17 @@ private Expression getColumnExpression(
10221023
* DELOMBOK
10231024
*/
10241025
static class Join {
1025-
Table joinTable;
1026+
TableLike joinTable;
10261027
Column joinColumn;
10271028
Column parentId;
10281029

1029-
Join(Table joinTable, Column joinColumn, Column parentId) {
1030+
Join(TableLike joinTable, Column joinColumn, Column parentId) {
10301031
this.joinTable = joinTable;
10311032
this.joinColumn = joinColumn;
10321033
this.parentId = parentId;
10331034
}
10341035

1035-
Table getJoinTable() {
1036+
TableLike getJoinTable() {
10361037
return this.joinTable;
10371038
}
10381039

spring-data-jdbc-plus-sql/src/test/java/com/navercorp/spring/data/jdbc/plus/sql/convert/SqlGeneratorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.data.relational.core.sql.Aliased;
3333
import org.springframework.data.relational.core.sql.SqlIdentifier;
3434
import org.springframework.data.relational.core.sql.Table;
35+
import org.springframework.data.relational.core.sql.TableLike;
3536

3637
/**
3738
* COPY org.springframework.data.relational.core.convert.SqlGeneratorUnitTests
@@ -649,7 +650,7 @@ public void joinForSecondLevelReference() {
649650
public void joinForOneToOneWithoutId() {
650651

651652
SqlGenerator.Join join = generateJoin("child", ParentOfNoIdChild.class);
652-
Table joinTable = join.getJoinTable();
653+
TableLike joinTable = join.getJoinTable();
653654

654655
SoftAssertions.assertSoftly(softly -> {
655656

0 commit comments

Comments
 (0)