Skip to content
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

Extract API to api package #253

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 since 1.1.3, 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,13 +16,20 @@

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;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;

import java.lang.reflect.ParameterizedType;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
Expand All @@ -37,7 +44,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 +103,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 +132,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 All @@ -140,6 +152,18 @@ public Nullability getNullability() {
return Nullability.NON_NULL;
}

@Override
public <T> T get(int index, ParameterizedType type) {
throw new IllegalArgumentException(String.format("Cannot decode %s with last inserted ID %s", type,
lastInsertId < 0 ? Long.toUnsignedString(lastInsertId) : lastInsertId));
}

@Override
public <T> T get(String name, ParameterizedType type) {
throw new IllegalArgumentException(String.format("Cannot decode %s with last inserted ID %s", 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);
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
Loading