Skip to content

Commit 769a516

Browse files
committed
fix getColumnMetadatas()
1 parent 3f5dbad commit 769a516

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

r2dbc-mysql/src/main/java/JasyncMetadata.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import io.r2dbc.spi.RowMetadata
66
import io.r2dbc.spi.Type
77

88
class JasyncMetadata(rows: ResultSet) : RowMetadata {
9+
private val columnNames = rows.columnNames()
10+
private val metadataList = columnNames.map { JasyncColumnMetadata(it) }
11+
private val metadataMap = metadataList.reversed().associateBy { it.name }
12+
913
override fun getColumnMetadata(index: Int): ColumnMetadata {
1014
if (index >= this.columnNames.size) {
1115
throw ArrayIndexOutOfBoundsException(
@@ -25,22 +29,19 @@ class JasyncMetadata(rows: ResultSet) : RowMetadata {
2529
)
2630
}
2731

28-
return this.metadata.getValue(columnNames[index])
32+
return this.metadataList[index]
2933
}
3034

3135
override fun getColumnMetadata(name: String): ColumnMetadata {
32-
return this.metadata[name]
36+
return this.metadataMap[name]
3337
?: throw NoSuchElementException(
3438
String
3539
.format("Column name '%s' does not exist in column names %s", name, columnNames)
3640
)
3741
}
3842

39-
private val columnNames: List<String> = rows.columnNames()
40-
private val metadata: Map<String, ColumnMetadata> = columnNames.map { it to JasyncColumnMetadata(it) }.toMap()
41-
4243
override fun getColumnMetadatas(): MutableList<out ColumnMetadata> {
43-
return metadata.values.toMutableList()
44+
return metadataList.toMutableList()
4445
}
4546

4647
internal class JasyncColumnMetadata(private val name: String) : ColumnMetadata {

0 commit comments

Comments
 (0)