Skip to content

Commit

Permalink
Revise RowMetaData#getColumnMetadata(String)
Browse files Browse the repository at this point in the history
Motivation:
The current behavior does not align with the specification

Modifications:
implement the intended behavior as per the specification.

Result:
Correct behavior
  • Loading branch information
jchrys committed Mar 6, 2024
1 parent dcbd67a commit 4fab3f6
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 541 deletions.
216 changes: 0 additions & 216 deletions r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/ColumnNameSet.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ final class InsertSyntheticRow implements MySqlRow, MySqlRowMetadata, MySqlColum

private final long lastInsertId;

private final ColumnNameSet nameSet;

InsertSyntheticRow(Codecs codecs, String keyName, long lastInsertId) {
this.codecs = requireNonNull(codecs, "codecs must not be null");
this.keyName = requireNonNull(keyName, "keyName must not be null");
// lastInsertId may be negative if key is BIGINT UNSIGNED and value overflow than signed int64.
this.lastInsertId = lastInsertId;
// Singleton name must be sorted.
this.nameSet = ColumnNameSet.of(keyName);
}

@Override
Expand Down Expand Up @@ -164,14 +160,14 @@ public <T> T get(String name, ParameterizedType type) {
lastInsertId < 0 ? Long.toUnsignedString(lastInsertId) : lastInsertId));
}

private void assertValidName(String name) {
if (!contains0(name)) {
throw new NoSuchElementException("Column name '" + name + "' does not exist in " + this.nameSet);
}
private boolean contains0(final String name) {
return keyName.equalsIgnoreCase(name);
}

private boolean contains0(String name) {
return nameSet.contains(name);
private void assertValidName(final String name) {
if (!contains0(name)) {
throw new NoSuchElementException("Column name '" + name + "' does not exist in {" + name + '}');
}
}

private <T> T get0(Class<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.asyncer.r2dbc.mysql.constant.MySqlType;
import io.asyncer.r2dbc.mysql.message.server.DefinitionMetadataMessage;
import io.r2dbc.spi.Nullability;
import org.jetbrains.annotations.VisibleForTesting;

import static io.asyncer.r2dbc.mysql.internal.util.AssertUtils.require;
import static io.asyncer.r2dbc.mysql.internal.util.AssertUtils.requireNonNull;
Expand Down Expand Up @@ -50,7 +51,8 @@ final class MySqlColumnDescriptor implements MySqlColumnMetadata {

private final int collationId;

private MySqlColumnDescriptor(int index, short typeId, String name, int definitions,
@VisibleForTesting
MySqlColumnDescriptor(int index, short typeId, String name, int definitions,
long size, int decimals, int collationId) {
require(index >= 0, "index must not be a negative integer");
require(size >= 0, "size must not be a negative integer");
Expand Down
Loading

0 comments on commit 4fab3f6

Please sign in to comment.