33import static java .util .Collections .*;
44import static org .assertj .core .api .Assertions .*;
55import static org .springframework .data .relational .core .mapping .Embedded .*;
6+ import static org .springframework .data .relational .core .sql .SqlIdentifier .quoted ;
7+ import static org .springframework .data .relational .core .sql .SqlIdentifier .unquoted ;
68
79import org .assertj .core .api .SoftAssertions ;
810import org .junit .jupiter .api .BeforeEach ;
1214import org .springframework .data .jdbc .core .convert .BasicJdbcConverter ;
1315import org .springframework .data .jdbc .core .convert .JdbcConverter ;
1416import org .springframework .data .jdbc .core .mapping .JdbcMappingContext ;
17+ import org .springframework .data .mapping .PersistentPropertyPath ;
1518import org .springframework .data .relational .core .mapping .Column ;
1619import org .springframework .data .relational .core .mapping .Embedded ;
1720import org .springframework .data .relational .core .mapping .PersistentPropertyPathExtension ;
1821import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
1922import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
23+ import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
2024import org .springframework .data .relational .core .sql .Aliased ;
2125import org .springframework .data .relational .core .sql .SqlIdentifier ;
2226
@@ -195,10 +199,10 @@ public void columnForEmbeddedProperty() {
195199 c -> getAlias (c .getTable ()), //
196200 this ::getAlias ) //
197201 .containsExactly ( //
198- SqlIdentifier . unquoted ("test" ), //
199- SqlIdentifier . unquoted ("dummy_entity" ), //
202+ unquoted ("test" ), //
203+ unquoted ("dummy_entity" ), //
200204 null , //
201- SqlIdentifier . unquoted ("test" ));
205+ unquoted ("test" ));
202206 }
203207
204208 @ Test // DATAJDBC-340
@@ -226,10 +230,10 @@ public void columnForPrefixedEmbeddedProperty() {
226230 c -> getAlias (c .getTable ()), //
227231 this ::getAlias ) //
228232 .containsExactly ( //
229- SqlIdentifier . unquoted ("prefix_test" ), //
230- SqlIdentifier . unquoted ("dummy_entity" ), //
233+ unquoted ("prefix_test" ), //
234+ unquoted ("dummy_entity" ), //
231235 null , //
232- SqlIdentifier . unquoted ("prefix_test" ));
236+ unquoted ("prefix_test" ));
233237 }
234238
235239 @ Test // DATAJDBC-340
@@ -249,8 +253,8 @@ public void columnForCascadedEmbeddedProperty() {
249253 c -> c .getTable ().getName (),
250254 c -> getAlias (c .getTable ()),
251255 this ::getAlias )
252- .containsExactly (SqlIdentifier . unquoted ("attr1" ), SqlIdentifier . unquoted ("dummy_entity" ), null ,
253- SqlIdentifier . unquoted ("attr1" ));
256+ .containsExactly (unquoted ("attr1" ), unquoted ("dummy_entity" ), null ,
257+ unquoted ("attr1" ));
254258 }
255259
256260 @ Test // DATAJDBC-340
@@ -261,14 +265,14 @@ public void joinForEmbeddedWithReference() {
261265 SoftAssertions .assertSoftly (softly -> {
262266
263267 softly .assertThat (join .getJoinTable ().getName ())
264- .isEqualTo (SqlIdentifier . unquoted ("other_entity" ));
268+ .isEqualTo (unquoted ("other_entity" ));
265269 softly .assertThat (join .getJoinColumn ().getTable ()).isEqualTo (join .getJoinTable ());
266270 softly .assertThat (join .getJoinColumn ().getName ())
267- .isEqualTo (SqlIdentifier . unquoted ("dummy_entity2" ));
271+ .isEqualTo (unquoted ("dummy_entity2" ));
268272 softly .assertThat (join .getParentId ().getName ())
269- .isEqualTo (SqlIdentifier . unquoted ("id" ));
273+ .isEqualTo (unquoted ("id" ));
270274 softly .assertThat (join .getParentId ().getTable ().getName ())
271- .isEqualTo (SqlIdentifier . unquoted ("dummy_entity2" ));
275+ .isEqualTo (unquoted ("dummy_entity2" ));
272276 });
273277 }
274278
@@ -282,10 +286,20 @@ public void columnForEmbeddedWithReferenceProperty() {
282286 c -> getAlias (c .getTable ()), //
283287 this ::getAlias ) //
284288 .containsExactly ( //
285- SqlIdentifier .unquoted ("value" ), //
286- SqlIdentifier .unquoted ("other_entity" ), //
287- SqlIdentifier .quoted ("prefix_other" ), //
288- SqlIdentifier .unquoted ("prefix_other_value" ));
289+ unquoted ("value" ), //
290+ unquoted ("other_entity" ), //
291+ quoted ("prefix_other" ), //
292+ unquoted ("prefix_other_value" ));
293+ }
294+
295+ @ Test
296+ public void getTableAlias () {
297+ SoftAssertions .assertSoftly (softly -> {
298+ softly .assertThat (PropertyPathUtils .getTableAlias (extPath ("prefixEmbeddable.other" )))
299+ .isEqualTo (quoted ("prefix_other" ));
300+ softly .assertThat (PropertyPathUtils .getTableAlias (extPath ("embeddable.other" )))
301+ .isEqualTo (quoted ("other" ));
302+ });
289303 }
290304
291305 private SqlGenerator .Join generateJoin (String path , Class <?> type ) {
@@ -303,6 +317,17 @@ private SqlIdentifier getAlias(Object maybeAliased) {
303317 return null ;
304318 }
305319
320+ private PersistentPropertyPathExtension extPath (RelationalPersistentEntity <?> entity ) {
321+ return new PersistentPropertyPathExtension (context , entity );
322+ }
323+ private PersistentPropertyPathExtension extPath (String path ) {
324+ return new PersistentPropertyPathExtension (context , createSimplePath (path ));
325+ }
326+
327+ PersistentPropertyPath <RelationalPersistentProperty > createSimplePath (String path ) {
328+ return PropertyPathTestingUtils .toPath (path , DummyEntity3 .class , context );
329+ }
330+
306331 private org .springframework .data .relational .core .sql .Column generatedColumn (
307332 String path , Class <?> type ) {
308333
@@ -350,6 +375,17 @@ static class DummyEntity2 {
350375 EmbeddedWithReference embedded ;
351376 }
352377
378+ static class DummyEntity3 {
379+ @ Id
380+ Long id ;
381+
382+ @ Embedded (onEmpty = OnEmpty .USE_NULL , prefix = "prefix_" )
383+ EmbeddedWithReference prefixEmbeddable ;
384+
385+ @ Embedded (onEmpty = OnEmpty .USE_NULL )
386+ EmbeddedWithReference embeddable ;
387+ }
388+
353389 static class EmbeddedWithReference {
354390 OtherEntity other ;
355391 }
0 commit comments