Skip to content

Commit be5383a

Browse files
committed
#30 - Polishing.
Minor formatting. Add suggestions. Update src/test/java/org/springframework/data/r2dbc/dialect/PostgresDialectUnitTests.java Co-Authored-By: mp911de <[email protected]> Original pull request: #31.
1 parent c357e5b commit be5383a

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

src/main/java/org/springframework/data/r2dbc/config/AbstractR2dbcConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public RelationalMappingContext r2dbcMappingContext(Optional<NamingStrategy> nam
118118
}
119119

120120
/**
121-
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional)
121+
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional, R2dbcCustomConversions)}
122122
* RelationalMappingContext}.
123123
*
124124
* @param mappingContext the configured {@link RelationalMappingContext}.

src/main/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,13 @@ private Object getWriteValue(PersistentPropertyAccessor propertyAccessor, Relati
261261
}
262262

263263
if (!dialect.supportsArrayColumns()) {
264+
264265
throw new InvalidDataAccessResourceUsageException(
265266
"Dialect " + dialect.getClass().getName() + " does not support array columns");
266267
}
267268

268269
if (!property.isArray()) {
270+
269271
Object zeroLengthArray = Array.newInstance(property.getActualType(), 0);
270272
return relationalConverter.getConversionService().convert(value, zeroLengthArray.getClass());
271273
}

src/test/java/org/springframework/data/r2dbc/dialect/PostgresDialectUnitTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,21 @@ public void shouldConsiderStringArrayTypeAsSimple() {
4242
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
4343

4444
assertThat(holder.isSimpleType(String[].class)).isTrue();
45+
46+
@Test // gh-30
47+
public void shouldConsiderIntArrayTypeAsSimple() {
48+
49+
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
50+
51+
assertThat(holder.isSimpleType(int[].class)).isTrue();
52+
}
53+
54+
@Test // gh-30
55+
public void shouldConsiderIntegerArrayTypeAsSimple() {
56+
57+
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
58+
59+
assertThat(holder.isSimpleType(Integer[].class)).isTrue();
60+
}
4561
}
4662
}

src/test/java/org/springframework/data/r2dbc/function/DefaultReactiveDataAccessStrategyUnitTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void shouldUpdateArray() {
112112
.getColumnsToUpdate(new WithCollectionTypes(new String[] { "one", "two" }, null));
113113

114114
Object stringArray = columnsToUpdate.get("string_array").getValue();
115+
115116
assertThat(stringArray).isInstanceOf(String[].class);
116117
assertThat((String[]) stringArray).hasSize(2).contains("one", "two");
117118
}
@@ -123,6 +124,7 @@ public void shouldConvertListToArray() {
123124
.getColumnsToUpdate(new WithCollectionTypes(null, Arrays.asList("one", "two")));
124125

125126
Object stringArray = columnsToUpdate.get("string_collection").getValue();
127+
126128
assertThat(stringArray).isInstanceOf(String[].class);
127129
assertThat((String[]) stringArray).hasSize(2).contains("one", "two");
128130
}
@@ -134,6 +136,7 @@ static class WithCollectionTypes {
134136
List<String> stringCollection;
135137

136138
WithCollectionTypes(String[] stringArray, List<String> stringCollection) {
139+
137140
this.stringArray = stringArray;
138141
this.stringCollection = stringCollection;
139142
}

src/test/java/org/springframework/data/r2dbc/function/convert/EntityRowMapperUnitTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ public void shouldConvertArrayToCollection() {
6969
assertThat(result.ids).contains("foo", "bar");
7070
}
7171

72+
@Test // gh-30
73+
public void shouldConvertArrayToSet() {
74+
75+
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
76+
when(rowMock.get("integerSet")).thenReturn((new int[] { 3, 14 }));
77+
78+
EntityWithCollection result = mapper.apply(rowMock, metadata);
79+
assertThat(result.integerSet).contains(3, 14);
80+
}
81+
82+
@Test // gh-30
83+
public void shouldConvertArrayMembers() {
84+
85+
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
86+
when(rowMock.get("primitiveIntegers")).thenReturn((new long[] { 3L, 14L }));
87+
88+
EntityWithCollection result = mapper.apply(rowMock, metadata);
89+
assertThat(result.primitiveIntegers).contains(3, 14);
90+
}
91+
92+
@Test // gh-30
93+
public void shouldConvertArrayToBoxedArray() {
94+
95+
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
96+
when(rowMock.get("boxedIntegers")).thenReturn((new int[] { 3, 11 }));
97+
98+
EntityWithCollection result = mapper.apply(rowMock, metadata);
99+
assertThat(result.boxedIntegers).contains(3, 11);
100+
}
72101
@SuppressWarnings("unchecked")
73102
private <T> EntityRowMapper<T> getRowMapper(Class<T> type) {
74103
RelationalPersistentEntity<T> entity = (RelationalPersistentEntity<T>) strategy.getMappingContext()
@@ -92,5 +121,8 @@ static class ConversionWithConstructorCreation {
92121

93122
static class EntityWithCollection {
94123
List<String> ids;
124+
Set<Integer> integerSet;
125+
Integer[] boxedIntegers;
126+
int[] primitiveIntegers;
95127
}
96128
}

0 commit comments

Comments
 (0)