|
15 | 15 | */ |
16 | 16 | package org.springframework.data.relational.core.mapping; |
17 | 17 |
|
| 18 | +import java.util.Objects; |
| 19 | + |
18 | 20 | import org.springframework.data.mapping.PersistentProperty; |
19 | 21 | import org.springframework.data.mapping.PersistentPropertyPath; |
20 | 22 | import org.springframework.data.mapping.context.MappingContext; |
|
23 | 25 | import org.springframework.data.util.Lazy; |
24 | 26 | import org.springframework.lang.Nullable; |
25 | 27 | import org.springframework.util.Assert; |
26 | | - |
27 | | -import java.util.Objects; |
| 28 | +import org.springframework.util.StringUtils; |
28 | 29 |
|
29 | 30 | /** |
30 | 31 | * A wrapper around a {@link org.springframework.data.mapping.PersistentPropertyPath} for making common operations |
@@ -385,28 +386,34 @@ private PersistentPropertyPathExtension getTableOwningAncestor() { |
385 | 386 | return isEntity() && !isEmbedded() ? this : getParentPath().getTableOwningAncestor(); |
386 | 387 | } |
387 | 388 |
|
| 389 | +@Nullable |
388 | 390 | private SqlIdentifier assembleTableAlias() { |
389 | 391 |
|
390 | 392 | Assert.state(path != null, "Path is null"); |
391 | 393 |
|
392 | 394 | RelationalPersistentProperty leafProperty = path.getRequiredLeafProperty(); |
393 | 395 | String prefix; |
394 | | -if (isEmbedded() && (leafProperty.getEmbeddedPrefix() == null || !leafProperty.getEmbeddedPrefix().isEmpty())) { |
| 396 | +if (isEmbedded()) { |
395 | 397 | prefix = leafProperty.getEmbeddedPrefix(); |
| 398 | + |
396 | 399 | } else { |
397 | 400 | prefix = leafProperty.getName(); |
398 | 401 | } |
399 | 402 |
|
400 | 403 | if (path.getLength() == 1) { |
401 | 404 | Assert.notNull(prefix, "Prefix mus not be null."); |
402 | | -return SqlIdentifier.quoted(prefix); |
| 405 | +return StringUtils.hasText(prefix) ? SqlIdentifier.quoted(prefix) : null; |
403 | 406 | } |
404 | 407 |
|
405 | 408 | PersistentPropertyPathExtension parentPath = getParentPath(); |
406 | 409 | SqlIdentifier sqlIdentifier = parentPath.assembleTableAlias(); |
407 | 410 |
|
408 | | -return parentPath.isEmbedded() ? sqlIdentifier.transform(name -> name.concat(prefix)) |
409 | | -: sqlIdentifier.transform(name -> name + "_" + prefix); |
| 411 | +if (sqlIdentifier != null) { |
| 412 | + |
| 413 | +return parentPath.isEmbedded() ? sqlIdentifier.transform(name -> name.concat(prefix)) |
| 414 | +: sqlIdentifier.transform(name -> name + "_" + prefix); |
| 415 | +} |
| 416 | +return SqlIdentifier.quoted(prefix); |
410 | 417 |
|
411 | 418 | } |
412 | 419 |
|
@@ -444,11 +451,12 @@ private SqlIdentifier prefixWithTableAlias(SqlIdentifier columnName) { |
444 | 451 | @Override |
445 | 452 | public boolean equals(Object o) { |
446 | 453 |
|
447 | | -if (this == o) return true; |
448 | | -if (o == null || getClass() != o.getClass()) return false; |
| 454 | +if (this == o) |
| 455 | +return true; |
| 456 | +if (o == null || getClass() != o.getClass()) |
| 457 | +return false; |
449 | 458 | PersistentPropertyPathExtension that = (PersistentPropertyPathExtension) o; |
450 | | -return entity.equals(that.entity) && |
451 | | -Objects.equals(path, that.path); |
| 459 | +return entity.equals(that.entity) && Objects.equals(path, that.path); |
452 | 460 | } |
453 | 461 |
|
454 | 462 | @Override |
|
0 commit comments