50
50
import org .springframework .data .relational .core .query .Criteria ;
51
51
import org .springframework .data .relational .core .query .Query ;
52
52
import org .springframework .data .relational .core .sql .Aliased ;
53
+ import org .springframework .data .relational .core .sql .Comparison ;
53
54
import org .springframework .data .relational .core .sql .LockMode ;
54
55
import org .springframework .data .relational .core .sql .SqlIdentifier ;
55
56
import org .springframework .data .relational .core .sql .Table ;
@@ -85,6 +86,22 @@ class SqlGeneratorUnitTests {
85
86
});
86
87
private SqlGenerator sqlGenerator ;
87
88
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
+
88
105
@ BeforeEach
89
106
void setUp () {
90
107
this .sqlGenerator = createSqlGenerator (DummyEntity .class );
@@ -716,10 +733,8 @@ void joinForSimpleReference() {
716
733
assertSoftly (softly -> {
717
734
718
735
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" )));
723
738
724
739
});
725
740
}
@@ -749,11 +764,8 @@ void joinForSecondLevelReference() {
749
764
assertSoftly (softly -> {
750
765
softly .assertThat (join .joinTable ().getName ()).isEqualTo (SqlIdentifier .quoted ("SECOND_LEVEL_REFERENCED_ENTITY" ));
751
766
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" )));
757
769
758
770
});
759
771
}
@@ -769,13 +781,8 @@ void joinForOneToOneWithoutId() {
769
781
softly .assertThat (joinTable .getName ()).isEqualTo (SqlIdentifier .quoted ("NO_ID_CHILD" ));
770
782
softly .assertThat (joinTable ).isInstanceOf (Aliased .class );
771
783
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" )));
779
786
});
780
787
}
781
788
0 commit comments