@@ -6,6 +6,10 @@ import io.r2dbc.spi.RowMetadata
6
6
import io.r2dbc.spi.Type
7
7
8
8
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
+
9
13
override fun getColumnMetadata (index : Int ): ColumnMetadata {
10
14
if (index >= this .columnNames.size) {
11
15
throw ArrayIndexOutOfBoundsException (
@@ -25,22 +29,19 @@ class JasyncMetadata(rows: ResultSet) : RowMetadata {
25
29
)
26
30
}
27
31
28
- return this .metadata.getValue(columnNames [index])
32
+ return this .metadataList [index]
29
33
}
30
34
31
35
override fun getColumnMetadata (name : String ): ColumnMetadata {
32
- return this .metadata [name]
36
+ return this .metadataMap [name]
33
37
? : throw NoSuchElementException (
34
38
String
35
39
.format(" Column name '%s' does not exist in column names %s" , name, columnNames)
36
40
)
37
41
}
38
42
39
- private val columnNames: List <String > = rows.columnNames()
40
- private val metadata: Map <String , ColumnMetadata > = columnNames.map { it to JasyncColumnMetadata (it) }.toMap()
41
-
42
43
override fun getColumnMetadatas (): MutableList <out ColumnMetadata > {
43
- return metadata.values .toMutableList()
44
+ return metadataList .toMutableList()
44
45
}
45
46
46
47
internal class JasyncColumnMetadata (private val name : String ) : ColumnMetadata {
0 commit comments