10000 [r2dbc-mysql] Fix `getColumnMetadatas()` of `JasyncMetadata` by davin111 · Pull Request #391 · jasync-sql/jasync-sql · GitHub
[go: up one dir, main page]

Skip to content

[r2dbc-mysql] Fix getColumnMetadatas() of JasyncMetadata #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix getColumnMetadatas()
  • Loading branch information
davin111 committed Apr 13, 2023
commit 769a516f902b4fe432c087f76a826fd4aa1f9da9
13 changes: 7 additions & 6 deletions r2dbc-mysql/src/main/java/JasyncMetadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import io.r2dbc.spi.RowMetadata
import io.r2dbc.spi.Type

class JasyncMetadata(rows: ResultSet) : RowMetadata {
private val columnNames = rows.columnNames()
private val metadataList = columnNames.map { JasyncColumnMetadata(it) }
private val metadataMap = metadataList.reversed().associateBy { it.name }

override fun getColumnMetadata(index: Int): ColumnMetadata {
if (index >= this.columnNames.size) {
throw ArrayIndexOutOfBoundsException(
Expand All @@ -25,22 +29,19 @@ class JasyncMetadata(rows: ResultSet) : RowMetadata {
)
}

return this.metadata.getValue(columnNames[index])
return this.metadataList[index]
}

override fun getColumnMetadata(name: String): ColumnMetadata {
return this.metadata[name]
return this.metadataMap[name]
?: throw NoSuchElementException(
String
.format("Column name '%s' does not exist in column names %s", name, columnNames)
)
}

private val columnNames: List<String> = rows.columnNames()
private val metadata: Map<String, ColumnMetadata> = columnNames.map { it to JasyncColumnMetadata(it) }.toMap()

override fun getColumnMetadatas(): MutableList<out ColumnMetadata> {
return metadata.values.toMutableList()
return metadataList.toMutableList()
}

internal class JasyncColumnMetadata(private val name: String) : ColumnMetadata {
Expand Down
0