Skip to content

Commit

Permalink
Extract public API to api package
Browse files Browse the repository at this point in the history
- Use strongly typed interfaces
- Standardize R2DBC driver MySQL-specific API
  • Loading branch information
mirromutth committed Mar 1, 2024
1 parent 3f119eb commit f5fee04
Show file tree
Hide file tree
Showing 98 changed files with 2,288 additions and 940 deletions.
168 changes: 0 additions & 168 deletions r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/ColumnDefinition.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface ConnectionState {
void setIsolationLevel(IsolationLevel level);

/**
* Reutrns session lock wait timeout.
* Returns session lock wait timeout.
*
* @return Session lock wait timeout.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 asyncer.io projects
* Copyright 2024 asyncer.io projects
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,12 @@
/**
* The engine of {@code START TRANSACTION WITH CONSISTENT [engine] SNAPSHOT} for Facebook/MySQL or similar
* syntax.
*
* @deprecated use directly {@link String} instead, e.g. {@code "ROCKSDB"}
* @see io.asyncer.r2dbc.mysql.api.MySqlTransactionDefinition#consistent(String)
* @see io.asyncer.r2dbc.mysql.api.MySqlTransactionDefinition#consistent(String, long)
*/
@Deprecated
public enum ConsistentSnapshotEngine {

ROCKSDB,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

package io.asyncer.r2dbc.mysql;

import io.asyncer.r2dbc.mysql.api.MySqlColumnMetadata;
import io.asyncer.r2dbc.mysql.api.MySqlRow;
import io.asyncer.r2dbc.mysql.api.MySqlRowMetadata;
import io.asyncer.r2dbc.mysql.api.MySqlStatement;
import io.asyncer.r2dbc.mysql.codec.CodecContext;
import io.asyncer.r2dbc.mysql.codec.Codecs;
import io.asyncer.r2dbc.mysql.collation.CharCollation;
import io.asyncer.r2dbc.mysql.constant.MySqlType;
import io.r2dbc.spi.ColumnMetadata;
import io.r2dbc.spi.Nullability;
Expand All @@ -37,7 +43,7 @@
*
* @see MySqlStatement#returnGeneratedValues(String...) reading last inserted ID.
*/
final class InsertSyntheticRow implements Row, RowMetadata, ColumnMetadata {
final class InsertSyntheticRow implements MySqlRow, MySqlRowMetadata, MySqlColumnMetadata {

private final Codecs codecs;

Expand Down Expand Up @@ -96,27 +102,27 @@ public boolean contains(String name) {
}

@Override
public RowMetadata getMetadata() {
public MySqlRowMetadata getMetadata() {
return this;
}

@Override
public ColumnMetadata getColumnMetadata(int index) {
public MySqlColumnMetadata getColumnMetadata(int index) {
assertValidIndex(index);

return this;
}

@Override
public ColumnMetadata getColumnMetadata(String name) {
public MySqlColumnMetadata getColumnMetadata(String name) {
requireNonNull(name, "name must not be null");
assertValidName(name);

return this;
}

@Override
public List<ColumnMetadata> getColumnMetadatas() {
public List<MySqlColumnMetadata> getColumnMetadatas() {
return Collections.singletonList(this);
}

Expand All @@ -125,6 +131,11 @@ public MySqlType getType() {
return lastInsertId < 0 ? MySqlType.BIGINT_UNSIGNED : MySqlType.BIGINT;
}

@Override
public CharCollation getCharCollation(CodecContext context) {
return context.getClientCollation();
}

@Override
public String getName() {
return keyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.asyncer.r2dbc.mysql;

import io.asyncer.r2dbc.mysql.api.MySqlBatch;
import io.asyncer.r2dbc.mysql.api.MySqlResult;
import io.asyncer.r2dbc.mysql.client.Client;
import io.asyncer.r2dbc.mysql.codec.Codecs;
import reactor.core.publisher.Flux;
Expand All @@ -28,7 +30,7 @@
* An implementation of {@link MySqlBatch} for executing a collection of statements in a batch against the
* MySQL database.
*/
final class MySqlBatchingBatch extends MySqlBatch {
final class MySqlBatchingBatch implements MySqlBatch {

private final Client client;

Expand Down Expand Up @@ -63,7 +65,7 @@ public MySqlBatch add(String sql) {
@Override
public Flux<MySqlResult> execute() {
return QueryFlow.execute(client, getSql())
.map(messages -> MySqlResult.toResult(false, codecs, context, null, messages));
.map(messages -> MySqlSegmentResult.toResult(false, codecs, context, null, messages));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.asyncer.r2dbc.mysql;

import io.asyncer.r2dbc.mysql.api.MySqlColumnMetadata;
import io.asyncer.r2dbc.mysql.api.MySqlNativeTypeMetadata;
import io.asyncer.r2dbc.mysql.codec.CodecContext;
import io.asyncer.r2dbc.mysql.collation.CharCollation;
import io.asyncer.r2dbc.mysql.constant.MySqlType;
Expand Down Expand Up @@ -48,28 +50,28 @@ final class MySqlColumnDescriptor implements MySqlColumnMetadata {

private final int collationId;

private MySqlColumnDescriptor(int index, short typeId, String name, ColumnDefinition definition,
private 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");
require(decimals >= 0, "decimals must not be a negative integer");
requireNonNull(name, "name must not be null");
require(collationId > 0, "collationId must be a positive integer");
requireNonNull(definition, "definition must not be null");

MySqlTypeMetadata typeMetadata = new MySqlTypeMetadata(typeId, definitions, collationId);

this.index = index;
this.typeMetadata = new MySqlTypeMetadata(typeId, definition);
this.type = MySqlType.of(typeId, definition);
this.typeMetadata = typeMetadata;
this.type = MySqlType.of(typeMetadata);
this.name = name;
this.nullability = definition.isNotNull() ? Nullability.NON_NULL : Nullability.NULLABLE;
this.nullability = typeMetadata.isNotNull() ? Nullability.NON_NULL : Nullability.NULLABLE;
this.size = size;
this.decimals = decimals;
this.collationId = collationId;
}

static MySqlColumnDescriptor create(int index, DefinitionMetadataMessage message) {
ColumnDefinition definition = message.getDefinition();
return new MySqlColumnDescriptor(index, message.getTypeId(), message.getColumn(), definition,
int definitions = message.getDefinitions();
return new MySqlColumnDescriptor(index, message.getTypeId(), message.getColumn(), definitions,
message.getSize(), message.getDecimals(), message.getCollationId());
}

Expand All @@ -88,7 +90,7 @@ public String getName() {
}

@Override
public MySqlTypeMetadata getNativeTypeMetadata() {
public MySqlNativeTypeMetadata getNativeTypeMetadata() {
return typeMetadata;
}

Expand All @@ -99,14 +101,13 @@ public Nullability getNullability() {

@Override
public Integer getPrecision() {
// FIXME: NEW_DECIMAL and DECIMAL are "exact" fixed-point number.
// So the `size` have to subtract:
// 1. if signed, 1 byte for the sign
// 2. if decimals > 0, 1 byte for the dot
return (int) size;
}

@Override
public long getNativePrecision() {
return size;
}

@Override
public Integer getScale() {
// 0x00 means it is an integer or a static string.
Expand Down
Loading

0 comments on commit f5fee04

Please sign in to comment.