Reflectively invoke RowMetadata.getColumnMetadatas.
We now use reflection to call RowMetadata.getColumnMetadatas to avoid NoSuchMethodError when using R2DBC 0.9 as the return type has changed in newer R2DBC versions. Closes #699
This commit is contained in:
@@ -647,7 +647,7 @@ public class MappingR2dbcConverter extends BasicRelationalConverter implements R
|
||||
return row.get(idColumnName);
|
||||
}
|
||||
|
||||
Iterable<? extends ColumnMetadata> columns = metadata.getColumnMetadatas();
|
||||
Iterable<? extends ColumnMetadata> columns = RowMetadataUtils.getColumnMetadata(metadata);
|
||||
Iterator<? extends ColumnMetadata> it = columns.iterator();
|
||||
|
||||
if (it.hasNext()) {
|
||||
|
||||
@@ -18,6 +18,11 @@ package org.springframework.data.r2dbc.convert;
|
||||
import io.r2dbc.spi.ColumnMetadata;
|
||||
import io.r2dbc.spi.RowMetadata;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for {@link io.r2dbc.spi.RowMetadata}
|
||||
*
|
||||
@@ -26,6 +31,9 @@ import io.r2dbc.spi.RowMetadata;
|
||||
*/
|
||||
class RowMetadataUtils {
|
||||
|
||||
private static final @Nullable Method getColumnMetadatas = ReflectionUtils.findMethod(RowMetadata.class,
|
||||
"getColumnMetadatas");
|
||||
|
||||
/**
|
||||
* Check whether the column {@code name} is contained in {@link RowMetadata}. The check happens case-insensitive.
|
||||
*
|
||||
@@ -35,7 +43,9 @@ class RowMetadataUtils {
|
||||
*/
|
||||
public static boolean containsColumn(RowMetadata metadata, String name) {
|
||||
|
||||
for (ColumnMetadata columnMetadata : metadata.getColumnMetadatas()) {
|
||||
Iterable<? extends ColumnMetadata> columns = getColumnMetadata(metadata);
|
||||
|
||||
for (ColumnMetadata columnMetadata : columns) {
|
||||
if (name.equalsIgnoreCase(columnMetadata.getName())) {
|
||||
return true;
|
||||
}
|
||||
@@ -43,4 +53,22 @@ class RowMetadataUtils {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link Iterable} of {@link ColumnMetadata} from {@link RowMetadata}.
|
||||
*
|
||||
* @param metadata the metadata object to inspect.
|
||||
* @return
|
||||
* @since 1.3.8
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterable<? extends ColumnMetadata> getColumnMetadata(RowMetadata metadata) {
|
||||
|
||||
if (getColumnMetadatas != null) {
|
||||
// Return type of RowMetadata.getColumnMetadatas was updated with R2DBC 0.9.
|
||||
return (Iterable<? extends ColumnMetadata>) ReflectionUtils.invokeMethod(getColumnMetadatas, metadata);
|
||||
}
|
||||
|
||||
return metadata.getColumnMetadatas();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user