5050import org .springframework .data .relational .core .query .Criteria ;
5151import org .springframework .data .relational .core .query .Query ;
5252import org .springframework .data .relational .core .sql .Aliased ;
53+ import org .springframework .data .relational .core .sql .Comparison ;
5354import org .springframework .data .relational .core .sql .LockMode ;
5455import org .springframework .data .relational .core .sql .SqlIdentifier ;
5556import org .springframework .data .relational .core .sql .Table ;
@@ -85,6 +86,22 @@ class SqlGeneratorUnitTests {
8586 });
8687 private SqlGenerator sqlGenerator ;
8788
89+ static Comparison equalsCondition (Table parentTable , SqlIdentifier parentId , Table joinedTable ,
90+ SqlIdentifier joinedColumn ) {
91+ return org .springframework .data .relational .core .sql .Column .create (joinedColumn , joinedTable )
92+ .isEqualTo (org .springframework .data .relational .core .sql .Column .create (parentId , parentTable ));
93+ }
94+
95+ static Comparison equalsCondition (SqlIdentifier parentTable , SqlIdentifier parentId , Table joinedTable ,
96+ SqlIdentifier joinedColumn ) {
97+ return equalsCondition (Table .create (parentTable ), parentId , joinedTable , joinedColumn );
98+ }
99+
100+ static Comparison equalsCondition (String parentTable , String parentId , Table joinedTable , String joinedColumn ) {
101+ return equalsCondition (SqlIdentifier .unquoted (parentTable ), SqlIdentifier .unquoted (parentId ), joinedTable ,
102+ SqlIdentifier .unquoted (joinedColumn ));
103+ }
104+
88105 @ BeforeEach
89106 void setUp () {
90107 this .sqlGenerator = createSqlGenerator (DummyEntity .class );
@@ -716,10 +733,8 @@ void joinForSimpleReference() {
716733 assertSoftly (softly -> {
717734
718735 softly .assertThat (join .joinTable ().getName ()).isEqualTo (SqlIdentifier .quoted ("REFERENCED_ENTITY" ));
719- softly .assertThat (join .condition ())
720- .isEqualTo (org .springframework .data .relational .core .sql .Column .create (SqlIdentifier .quoted ("DUMMY_ENTITY" ), join .joinTable ())
721- .isEqualTo (org .springframework .data .relational .core .sql .Column .create (SqlIdentifier .quoted ("id1" ),
722- org .springframework .data .relational .core .sql .Table .create (SqlIdentifier .quoted ("DUMMY_ENTITY" )))));
736+ softly .assertThat (join .condition ()).isEqualTo (equalsCondition (SqlIdentifier .quoted ("DUMMY_ENTITY" ),
737+ SqlIdentifier .quoted ("id1" ), join .joinTable (), SqlIdentifier .quoted ("DUMMY_ENTITY" )));
723738
724739 });
725740 }
@@ -749,11 +764,8 @@ void joinForSecondLevelReference() {
749764 assertSoftly (softly -> {
750765 softly .assertThat (join .joinTable ().getName ()).isEqualTo (SqlIdentifier .quoted ("SECOND_LEVEL_REFERENCED_ENTITY" ));
751766 softly .assertThat (join .condition ())
752- .isEqualTo (org .springframework .data .relational .core .sql .Column
753- .create (SqlIdentifier .quoted ("REFERENCED_ENTITY" ), join .joinTable ())
754- .isEqualTo (org .springframework .data .relational .core .sql .Column .create (SqlIdentifier .quoted ("X_L1ID" ),
755- org .springframework .data .relational .core .sql .Table .create ("REFERENCED_ENTITY" )
756- .as (SqlIdentifier .quoted ("ref" )))));
767+ .isEqualTo (equalsCondition (Table .create ("REFERENCED_ENTITY" ).as (SqlIdentifier .quoted ("ref" )),
768+ SqlIdentifier .quoted ("X_L1ID" ), join .joinTable (), SqlIdentifier .quoted ("REFERENCED_ENTITY" )));
757769
758770 });
759771 }
@@ -769,13 +781,8 @@ void joinForOneToOneWithoutId() {
769781 softly .assertThat (joinTable .getName ()).isEqualTo (SqlIdentifier .quoted ("NO_ID_CHILD" ));
770782 softly .assertThat (joinTable ).isInstanceOf (Aliased .class );
771783 softly .assertThat (((Aliased ) joinTable ).getAlias ()).isEqualTo (SqlIdentifier .quoted ("child" ));
772- softly .assertThat (join .condition ())
773- .isEqualTo (org .springframework .data .relational .core .sql .Column
774- .create (SqlIdentifier .quoted ("PARENT_OF_NO_ID_CHILD" ), join .joinTable ())
775- .isEqualTo (org .springframework .data .relational .core .sql .Column .create (SqlIdentifier .quoted ("X_ID" ),
776- org .springframework .data .relational .core .sql .Table
777- .create (SqlIdentifier .quoted ("PARENT_OF_NO_ID_CHILD" )))));
778-
784+ softly .assertThat (join .condition ()).isEqualTo (equalsCondition (SqlIdentifier .quoted ("PARENT_OF_NO_ID_CHILD" ),
785+ SqlIdentifier .quoted ("X_ID" ), join .joinTable (), SqlIdentifier .quoted ("PARENT_OF_NO_ID_CHILD" )));
779786 });
780787 }
781788
0 commit comments