Polishing.

Original pull request 1384
See #833
This commit is contained in:
Jens Schauder
2022-11-29 14:46:44 +01:00
parent 09f9da5128
commit e590dceede
2 changed files with 13 additions and 13 deletions

View File

@@ -57,6 +57,7 @@ import org.springframework.util.Assert;
* @author Chirag Tailor
* @author Diego Krupitza
* @author Hari Ohm Prasath
* @author Viktor Ardelean
*/
class SqlGenerator {
@@ -260,10 +261,10 @@ class SqlGenerator {
Condition condition = null;
for (SqlIdentifier backReferenceColumn : parentIdentifier.toMap().keySet()) {
if (SqlIdentifier.EMPTY.equals(backReferenceColumn)){
throw new UnsupportedOperationException(
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
}
Assert.isTrue(!SqlIdentifier.EMPTY.equals(backReferenceColumn),
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query");
Condition newCondition = table.column(backReferenceColumn).isEqualTo(getBindMarker(backReferenceColumn));
condition = condition == null ? newCondition : condition.and(newCondition);
}
@@ -1102,7 +1103,7 @@ class SqlGenerator {
if (!property.isWritable()) {
readOnlyColumnNames.add(columnName);
}
if (property.isInsertOnly()) {
if (property.isInsertOnly()) {
insertOnlyColumnNames.add(columnName);
}
}

View File

@@ -26,7 +26,6 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Version;
@@ -72,6 +71,7 @@ import org.springframework.lang.Nullable;
* @author Chirag Tailor
* @author Diego Krupitza
* @author Hari Ohm Prasath
* @author Viktor Ardelean
*/
@SuppressWarnings("Convert2MethodRef")
class SqlGeneratorUnitTests {
@@ -443,15 +443,14 @@ class SqlGeneratorUnitTests {
}
@Test // DATAJDBC-613
@Test // GH-833
void findAllByPropertyWithEmptyBackrefColumn() {
assertThatThrownBy(() -> {
sqlGenerator.getFindAllByProperty(Identifier.of(EMPTY, 0, Object.class),
unquoted("key-column"),
false);
}).isInstanceOf(UnsupportedOperationException.class)
.hasMessageContaining("An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query.");
Identifier emptyIdentifier = Identifier.of(EMPTY, 0, Object.class);
assertThatThrownBy(() -> sqlGenerator.getFindAllByProperty(emptyIdentifier, unquoted("key-column"), false)) //
.isInstanceOf(IllegalArgumentException.class) //
.hasMessageContaining(
"An empty SqlIdentifier can't be used in condition. Make sure that all composite primary keys are defined in the query");
}
@Test // DATAJDBC-219