Skip to content

Commit 457fdb9

Browse files
committed
Use SqlIdentifier.getReference() when calling Row.get(…).
We now use the referencename instead of toString() when obtaining values from Row. Closes #530.
1 parent c54bd76 commit 457fdb9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private Object readFrom(Row row, @Nullable RowMetadata metadata, RelationalPersi
164164
return readEntityFrom(row, metadata, property);
165165
}
166166

167-
String identifier = prefix + property.getColumnName();
167+
String identifier = prefix + property.getColumnName().getReference();
168168
if (metadata != null && !metadata.getColumnNames().contains(identifier)) {
169169
return null;
170170
}

src/test/java/org/springframework/data/r2dbc/convert/MappingR2dbcConverterUnitTests.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import io.r2dbc.spi.test.MockRow;
2424
import io.r2dbc.spi.test.MockRowMetadata;
2525
import lombok.AllArgsConstructor;
26+
import lombok.Getter;
2627
import lombok.RequiredArgsConstructor;
28+
import lombok.Setter;
2729

2830
import java.time.Instant;
2931
import java.time.LocalDateTime;
@@ -182,9 +184,24 @@ public void shouldWriteTopLevelEntity() {
182184
.containsEntry(SqlIdentifier.unquoted("entity"), Parameter.from("nested_entity"));
183185
}
184186

185-
@Test // gh-59
187+
@Test // gh-530
186188
public void shouldReadTopLevelEntity() {
187189

190+
mappingContext.setForceQuote(true);
191+
192+
Row rowMock = mock(Row.class);
193+
when(rowMock.get("firstname")).thenReturn("Walter");
194+
when(rowMock.get("lastname")).thenReturn("White");
195+
196+
ConstructorAndPropertyPopulation result = converter.read(ConstructorAndPropertyPopulation.class, rowMock);
197+
198+
assertThat(result.firstname).isEqualTo("Walter");
199+
assertThat(result.lastname).isEqualTo("White");
200+
}
201+
202+
@Test // gh-59
203+
public void shouldReadTopLevelEntityWithConverter() {
204+
188205
Row rowMock = mock(Row.class);
189206
when(rowMock.get("foo_column", String.class)).thenReturn("bar");
190207
when(rowMock.get("nested_entity")).thenReturn("map");
@@ -236,6 +253,14 @@ static class Person {
236253
LocalDateTime localDateTime;
237254
}
238255

256+
@Getter
257+
@Setter
258+
@RequiredArgsConstructor
259+
static class ConstructorAndPropertyPopulation {
260+
final String firstname;
261+
String lastname;
262+
}
263+
239264
@AllArgsConstructor
240265
static class WithEnum {
241266
@Id String id;

0 commit comments

Comments
 (0)