Skip to content

Commit e590dce

Browse files
committed
Polishing.
Original pull request 1384 See #833
1 parent 09f9da5 commit e590dce

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* @author Chirag Tailor
5858
* @author Diego Krupitza
5959
* @author Hari Ohm Prasath
60+
* @author Viktor Ardelean
6061
*/
6162
class SqlGenerator {
6263

@@ -260,10 +261,10 @@ private Condition buildConditionForBackReference(Identifier parentIdentifier, Ta
260261

261262
Condition condition = null;
262263
for (SqlIdentifier backReferenceColumn : parentIdentifier.toMap().keySet()) {
263-
if (SqlIdentifier.EMPTY.equals(backReferenceColumn)){
264-
throw new UnsupportedOperationException(
265-
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
266-
}
264+
265+
Assert.isTrue(!SqlIdentifier.EMPTY.equals(backReferenceColumn),
266+
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query");
267+
267268
Condition newCondition = table.column(backReferenceColumn).isEqualTo(getBindMarker(backReferenceColumn));
268269
condition = condition == null ? newCondition : condition.and(newCondition);
269270
}
@@ -1102,7 +1103,7 @@ private void initSimpleColumnName(RelationalPersistentProperty property, String
11021103
if (!property.isWritable()) {
11031104
readOnlyColumnNames.add(columnName);
11041105
}
1105-
if (property.isInsertOnly()) {
1106+
if (property.isInsertOnly()) {
11061107
insertOnlyColumnNames.add(columnName);
11071108
}
11081109
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import org.junit.jupiter.api.BeforeEach;
2828
import org.junit.jupiter.api.Test;
29-
3029
import org.springframework.data.annotation.Id;
3130
import org.springframework.data.annotation.ReadOnlyProperty;
3231
import org.springframework.data.annotation.Version;
@@ -72,6 +71,7 @@
7271
* @author Chirag Tailor
7372
* @author Diego Krupitza
7473
* @author Hari Ohm Prasath
74+
* @author Viktor Ardelean
7575
*/
7676
@SuppressWarnings("Convert2MethodRef")
7777
class SqlGeneratorUnitTests {
@@ -443,15 +443,14 @@ public void findAllByPropertyAvoidsDuplicateColumns() {
443443

444444
}
445445

446-
@Test // DATAJDBC-613
446+
@Test // GH-833
447447
void findAllByPropertyWithEmptyBackrefColumn() {
448448

449-
assertThatThrownBy(() -> {
450-
sqlGenerator.getFindAllByProperty(Identifier.of(EMPTY, 0, Object.class),
451-
unquoted("key-column"),
452-
false);
453-
}).isInstanceOf(UnsupportedOperationException.class)
454-
.hasMessageContaining("An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
449+
Identifier emptyIdentifier = Identifier.of(EMPTY, 0, Object.class);
450+
assertThatThrownBy(() -> sqlGenerator.getFindAllByProperty(emptyIdentifier, unquoted("key-column"), false)) //
451+
.isInstanceOf(IllegalArgumentException.class) //
452+
.hasMessageContaining(
453+
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query");
455454
}
456455

457456
@Test // DATAJDBC-219

0 commit comments

Comments
 (0)