#30 - Polishing.
Minor formatting. Add suggestions. Update src/test/java/org/springframework/data/r2dbc/dialect/PostgresDialectUnitTests.java Co-Authored-By: mp911de <mpaluch@paluch.biz> Original pull request: #31.
This commit is contained in:
@@ -118,7 +118,7 @@ public abstract class AbstractR2dbcConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional)
|
||||
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional, R2dbcCustomConversions)}
|
||||
* RelationalMappingContext}.
|
||||
*
|
||||
* @param mappingContext the configured {@link RelationalMappingContext}.
|
||||
|
||||
@@ -261,11 +261,13 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
|
||||
}
|
||||
|
||||
if (!dialect.supportsArrayColumns()) {
|
||||
|
||||
throw new InvalidDataAccessResourceUsageException(
|
||||
"Dialect " + dialect.getClass().getName() + " does not support array columns");
|
||||
}
|
||||
|
||||
if (!property.isArray()) {
|
||||
|
||||
Object zeroLengthArray = Array.newInstance(property.getActualType(), 0);
|
||||
return relationalConverter.getConversionService().convert(value, zeroLengthArray.getClass());
|
||||
}
|
||||
|
||||
@@ -42,5 +42,21 @@ public class PostgresDialectUnitTests {
|
||||
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
|
||||
|
||||
assertThat(holder.isSimpleType(String[].class)).isTrue();
|
||||
|
||||
@Test // gh-30
|
||||
public void shouldConsiderIntArrayTypeAsSimple() {
|
||||
|
||||
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
|
||||
|
||||
assertThat(holder.isSimpleType(int[].class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // gh-30
|
||||
public void shouldConsiderIntegerArrayTypeAsSimple() {
|
||||
|
||||
SimpleTypeHolder holder = PostgresDialect.INSTANCE.getSimpleTypeHolder();
|
||||
|
||||
assertThat(holder.isSimpleType(Integer[].class)).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ public class DefaultReactiveDataAccessStrategyUnitTests {
|
||||
.getColumnsToUpdate(new WithCollectionTypes(new String[] { "one", "two" }, null));
|
||||
|
||||
Object stringArray = columnsToUpdate.get("string_array").getValue();
|
||||
|
||||
assertThat(stringArray).isInstanceOf(String[].class);
|
||||
assertThat((String[]) stringArray).hasSize(2).contains("one", "two");
|
||||
}
|
||||
@@ -123,6 +124,7 @@ public class DefaultReactiveDataAccessStrategyUnitTests {
|
||||
.getColumnsToUpdate(new WithCollectionTypes(null, Arrays.asList("one", "two")));
|
||||
|
||||
Object stringArray = columnsToUpdate.get("string_collection").getValue();
|
||||
|
||||
assertThat(stringArray).isInstanceOf(String[].class);
|
||||
assertThat((String[]) stringArray).hasSize(2).contains("one", "two");
|
||||
}
|
||||
@@ -134,6 +136,7 @@ public class DefaultReactiveDataAccessStrategyUnitTests {
|
||||
List<String> stringCollection;
|
||||
|
||||
WithCollectionTypes(String[] stringArray, List<String> stringCollection) {
|
||||
|
||||
this.stringArray = stringArray;
|
||||
this.stringCollection = stringCollection;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,35 @@ public class EntityRowMapperUnitTests {
|
||||
assertThat(result.ids).contains("foo", "bar");
|
||||
}
|
||||
|
||||
@Test // gh-30
|
||||
public void shouldConvertArrayToSet() {
|
||||
|
||||
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
|
||||
when(rowMock.get("integerSet")).thenReturn((new int[] { 3, 14 }));
|
||||
|
||||
EntityWithCollection result = mapper.apply(rowMock, metadata);
|
||||
assertThat(result.integerSet).contains(3, 14);
|
||||
}
|
||||
|
||||
@Test // gh-30
|
||||
public void shouldConvertArrayMembers() {
|
||||
|
||||
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
|
||||
when(rowMock.get("primitiveIntegers")).thenReturn((new long[] { 3L, 14L }));
|
||||
|
||||
EntityWithCollection result = mapper.apply(rowMock, metadata);
|
||||
assertThat(result.primitiveIntegers).contains(3, 14);
|
||||
}
|
||||
|
||||
@Test // gh-30
|
||||
public void shouldConvertArrayToBoxedArray() {
|
||||
|
||||
EntityRowMapper<EntityWithCollection> mapper = getRowMapper(EntityWithCollection.class);
|
||||
when(rowMock.get("boxedIntegers")).thenReturn((new int[] { 3, 11 }));
|
||||
|
||||
EntityWithCollection result = mapper.apply(rowMock, metadata);
|
||||
assertThat(result.boxedIntegers).contains(3, 11);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> EntityRowMapper<T> getRowMapper(Class<T> type) {
|
||||
RelationalPersistentEntity<T> entity = (RelationalPersistentEntity<T>) strategy.getMappingContext()
|
||||
@@ -92,5 +121,8 @@ public class EntityRowMapperUnitTests {
|
||||
|
||||
static class EntityWithCollection {
|
||||
List<String> ids;
|
||||
Set<Integer> integerSet;
|
||||
Integer[] boxedIntegers;
|
||||
int[] primitiveIntegers;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user