26
26
import org .springframework .data .jdbc .mapping .model .DefaultNamingStrategy ;
27
27
import org .springframework .data .jdbc .mapping .model .JdbcMappingContext ;
28
28
import org .springframework .data .jdbc .mapping .model .JdbcPersistentEntity ;
29
+ import org .springframework .data .jdbc .mapping .model .JdbcPersistentProperty ;
29
30
import org .springframework .data .jdbc .mapping .model .NamingStrategy ;
30
31
import org .springframework .data .mapping .PropertyPath ;
31
32
@@ -42,7 +43,7 @@ public class SqlGeneratorUnitTests {
42
43
@ Before
43
44
public void setUp () {
44
45
45
- NamingStrategy namingStrategy = new DefaultNamingStrategy ();
46
+ NamingStrategy namingStrategy = new PrefixingNamingStrategy ();
46
47
JdbcMappingContext context = new JdbcMappingContext (namingStrategy );
47
48
JdbcPersistentEntity <?> persistentEntity = context .getRequiredPersistentEntity (DummyEntity .class );
48
49
this .sqlGenerator = new SqlGenerator (context , persistentEntity , new SqlGeneratorSource (context ));
@@ -56,10 +57,10 @@ public void findOne() {
56
57
SoftAssertions softAssertions = new SoftAssertions ();
57
58
softAssertions .assertThat (sql ) //
58
59
.startsWith ("SELECT" ) //
59
- .contains ("DummyEntity.id AS id ," ) //
60
- .contains ("DummyEntity.name AS name ," ) //
61
- .contains ("ref.l1id AS ref_l1id " ) //
62
- .contains ("ref.content AS ref_content " ).contains (" FROM DummyEntity" ) //
60
+ .contains ("DummyEntity.x_id AS x_id ," ) //
61
+ .contains ("DummyEntity.x_name AS x_name ," ) //
62
+ .contains ("ref.x_l1id AS ref_x_l1id " ) //
63
+ .contains ("ref.x_content AS ref_x_content " ).contains (" FROM DummyEntity" ) //
63
64
// 1-N relationships do not get loaded via join
64
65
.doesNotContain ("Element AS elements" );
65
66
softAssertions .assertAll ();
@@ -79,7 +80,7 @@ public void cascadingDeleteAllSecondLevel() {
79
80
String sql = sqlGenerator .createDeleteByPath (PropertyPath .from ("ref.further" , DummyEntity .class ));
80
81
81
82
assertThat (sql ).isEqualTo (
82
- "DELETE FROM SecondLevelReferencedEntity WHERE ReferencedEntity IN (SELECT l1id FROM ReferencedEntity WHERE DummyEntity = :rootId)" );
83
+ "DELETE FROM SecondLevelReferencedEntity WHERE ReferencedEntity IN (SELECT x_l1id FROM ReferencedEntity WHERE DummyEntity = :rootId)" );
83
84
}
84
85
85
86
@ Test // DATAJDBC-112
@@ -104,7 +105,7 @@ public void cascadingDeleteSecondLevel() {
104
105
String sql = sqlGenerator .createDeleteAllSql (PropertyPath .from ("ref.further" , DummyEntity .class ));
105
106
106
107
assertThat (sql ).isEqualTo (
107
- "DELETE FROM SecondLevelReferencedEntity WHERE ReferencedEntity IN (SELECT l1id FROM ReferencedEntity WHERE DummyEntity IS NOT NULL)" );
108
+ "DELETE FROM SecondLevelReferencedEntity WHERE ReferencedEntity IN (SELECT x_l1id FROM ReferencedEntity WHERE DummyEntity IS NOT NULL)" );
108
109
}
109
110
110
111
@ SuppressWarnings ("unused" )
@@ -135,4 +136,13 @@ static class Element {
135
136
@ Id Long id ;
136
137
String content ;
137
138
}
139
+
140
+ private static class PrefixingNamingStrategy extends DefaultNamingStrategy {
141
+
142
+ @ Override
143
+ public String getColumnName (JdbcPersistentProperty property ) {
144
+ return "x_" + super .getColumnName (property );
145
+ }
146
+
147
+ }
138
148
}
0 commit comments