Skip to content

Commit 62666b9

Browse files
committed
Extract public API to api package
- Use strongly typed interfaces - Standardize R2DBC driver MySQL-specific API
1 parent 3f119eb commit 62666b9

File tree

98 files changed

+2295
-940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2295
-940
lines changed

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/ColumnDefinition.java

Lines changed: 0 additions & 168 deletions
This file was deleted.

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/ConnectionState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface ConnectionState {
3131
void setIsolationLevel(IsolationLevel level);
3232

3333
/**
34-
* Reutrns session lock wait timeout.
34+
* Returns session lock wait timeout.
3535
*
3636
* @return Session lock wait timeout.
3737
*/

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/ConsistentSnapshotEngine.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 asyncer.io projects
2+
* Copyright 2024 asyncer.io projects
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,12 @@
1919
/**
2020
* The engine of {@code START TRANSACTION WITH CONSISTENT [engine] SNAPSHOT} for Facebook/MySQL or similar
2121
* syntax.
22+
*
23+
* @deprecated since 1.1.3, use directly {@link String} instead, e.g. {@code "ROCKSDB"}
24+
* @see io.asyncer.r2dbc.mysql.api.MySqlTransactionDefinition#consistent(String)
25+
* @see io.asyncer.r2dbc.mysql.api.MySqlTransactionDefinition#consistent(String, long)
2226
*/
27+
@Deprecated
2328
public enum ConsistentSnapshotEngine {
2429

2530
ROCKSDB,

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/InsertSyntheticRow.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616

1717
package io.asyncer.r2dbc.mysql;
1818

19+
import io.asyncer.r2dbc.mysql.api.MySqlColumnMetadata;
20+
import io.asyncer.r2dbc.mysql.api.MySqlRow;
21+
import io.asyncer.r2dbc.mysql.api.MySqlRowMetadata;
22+
import io.asyncer.r2dbc.mysql.api.MySqlStatement;
23+
import io.asyncer.r2dbc.mysql.codec.CodecContext;
1924
import io.asyncer.r2dbc.mysql.codec.Codecs;
25+
import io.asyncer.r2dbc.mysql.collation.CharCollation;
2026
import io.asyncer.r2dbc.mysql.constant.MySqlType;
2127
import io.r2dbc.spi.ColumnMetadata;
2228
import io.r2dbc.spi.Nullability;
2329
import io.r2dbc.spi.Row;
2430
import io.r2dbc.spi.RowMetadata;
2531

32+
import java.lang.reflect.ParameterizedType;
2633
import java.util.Collections;
2734
import java.util.List;
2835
import java.util.NoSuchElementException;
@@ -37,7 +44,7 @@
3744
*
3845
* @see MySqlStatement#returnGeneratedValues(String...) reading last inserted ID.
3946
*/
40-
final class InsertSyntheticRow implements Row, RowMetadata, ColumnMetadata {
47+
final class InsertSyntheticRow implements MySqlRow, MySqlRowMetadata, MySqlColumnMetadata {
4148

4249
private final Codecs codecs;
4350

@@ -96,27 +103,27 @@ public boolean contains(String name) {
96103
}
97104

98105
@Override
99-
public RowMetadata getMetadata() {
106+
public MySqlRowMetadata getMetadata() {
100107
return this;
101108
}
102109

103110
@Override
104-
public ColumnMetadata getColumnMetadata(int index) {
111+
public MySqlColumnMetadata getColumnMetadata(int index) {
105112
assertValidIndex(index);
106113

107114
return this;
108115
}
109116

110117
@Override
111-
public ColumnMetadata getColumnMetadata(String name) {
118+
public MySqlColumnMetadata getColumnMetadata(String name) {
112119
requireNonNull(name, "name must not be null");
113120
assertValidName(name);
114121

115122
return this;
116123
}
117124

118125
@Override
119-
public List<ColumnMetadata> getColumnMetadatas() {
126+
public List<MySqlColumnMetadata> getColumnMetadatas() {
120127
return Collections.singletonList(this);
121128
}
122129

@@ -125,6 +132,11 @@ public MySqlType getType() {
125132
return lastInsertId < 0 ? MySqlType.BIGINT_UNSIGNED : MySqlType.BIGINT;
126133
}
127134

135+
@Override
136+
public CharCollation getCharCollation(CodecContext context) {
137+
return context.getClientCollation();
138+
}
139+
128140
@Override
129141
public String getName() {
130142
return keyName;
@@ -140,6 +152,18 @@ public Nullability getNullability() {
140152
return Nullability.NON_NULL;
141153
}
142154

155+
@Override
156+
public <T> T get(int index, ParameterizedType type) {
157+
throw new IllegalArgumentException(String.format("Cannot decode %s with last inserted ID %s", type,
158+
lastInsertId < 0 ? Long.toUnsignedString(lastInsertId) : lastInsertId));
159+
}
160+
161+
@Override
162+
public <T> T get(String name, ParameterizedType type) {
163+
throw new IllegalArgumentException(String.format("Cannot decode %s with last inserted ID %s", type,
164+
lastInsertId < 0 ? Long.toUnsignedString(lastInsertId) : lastInsertId));
165+
}
166+
143167
private void assertValidName(String name) {
144168
if (!contains0(name)) {
145169
throw new NoSuchElementException("Column name '" + name + "' does not exist in " + this.nameSet);

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/MySqlBatchingBatch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.asyncer.r2dbc.mysql;
1818

19+
import io.asyncer.r2dbc.mysql.api.MySqlBatch;
20+
import io.asyncer.r2dbc.mysql.api.MySqlResult;
1921
import io.asyncer.r2dbc.mysql.client.Client;
2022
import io.asyncer.r2dbc.mysql.codec.Codecs;
2123
import reactor.core.publisher.Flux;
@@ -28,7 +30,7 @@
2830
* An implementation of {@link MySqlBatch} for executing a collection of statements in a batch against the
2931
* MySQL database.
3032
*/
31-
final class MySqlBatchingBatch extends MySqlBatch {
33+
final class MySqlBatchingBatch implements MySqlBatch {
3234

3335
private final Client client;
3436

@@ -63,7 +65,7 @@ public MySqlBatch add(String sql) {
6365
@Override
6466
public Flux<MySqlResult> execute() {
6567
return QueryFlow.execute(client, getSql())
66-
.map(messages -> MySqlResult.toResult(false, codecs, context, null, messages));
68+
.map(messages -> MySqlSegmentResult.toResult(false, codecs, context, null, messages));
6769
}
6870

6971
@Override

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/MySqlColumnDescriptor.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.asyncer.r2dbc.mysql;
1818

19+
import io.asyncer.r2dbc.mysql.api.MySqlColumnMetadata;
20+
import io.asyncer.r2dbc.mysql.api.MySqlNativeTypeMetadata;
1921
import io.asyncer.r2dbc.mysql.codec.CodecContext;
2022
import io.asyncer.r2dbc.mysql.collation.CharCollation;
2123
import io.asyncer.r2dbc.mysql.constant.MySqlType;
@@ -48,28 +50,28 @@ final class MySqlColumnDescriptor implements MySqlColumnMetadata {
4850

4951
private final int collationId;
5052

51-
private MySqlColumnDescriptor(int index, short typeId, String name, ColumnDefinition definition,
53+
private MySqlColumnDescriptor(int index, short typeId, String name, int definitions,
5254
long size, int decimals, int collationId) {
5355
require(index >= 0, "index must not be a negative integer");
5456
require(size >= 0, "size must not be a negative integer");
5557
require(decimals >= 0, "decimals must not be a negative integer");
5658
requireNonNull(name, "name must not be null");
57-
require(collationId > 0, "collationId must be a positive integer");
58-
requireNonNull(definition, "definition must not be null");
59+
60+
MySqlTypeMetadata typeMetadata = new MySqlTypeMetadata(typeId, definitions, collationId);
5961

6062
this.index = index;
61-
this.typeMetadata = new MySqlTypeMetadata(typeId, definition);
62-
this.type = MySqlType.of(typeId, definition);
63+
this.typeMetadata = typeMetadata;
64+
this.type = MySqlType.of(typeMetadata);
6365
this.name = name;
64-
this.nullability = definition.isNotNull() ? Nullability.NON_NULL : Nullability.NULLABLE;
66+
this.nullability = typeMetadata.isNotNull() ? Nullability.NON_NULL : Nullability.NULLABLE;
6567
this.size = size;
6668
this.decimals = decimals;
6769
this.collationId = collationId;
6870
}
6971

7072
static MySqlColumnDescriptor create(int index, DefinitionMetadataMessage message) {
71-
ColumnDefinition definition = message.getDefinition();
72-
return new MySqlColumnDescriptor(index, message.getTypeId(), message.getColumn(), definition,
73+
int definitions = message.getDefinitions();
74+
return new MySqlColumnDescriptor(index, message.getTypeId(), message.getColumn(), definitions,
7375
message.getSize(), message.getDecimals(), message.getCollationId());
7476
}
7577

@@ -88,7 +90,7 @@ public String getName() {
8890
}
8991

9092
@Override
91-
public MySqlTypeMetadata getNativeTypeMetadata() {
93+
public MySqlNativeTypeMetadata getNativeTypeMetadata() {
9294
return typeMetadata;
9395
}
9496

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

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

105-
@Override
106-
public long getNativePrecision() {
107-
return size;
108-
}
109-
110111
@Override
111112
public Integer getScale() {
112113
// 0x00 means it is an integer or a static string.

0 commit comments

Comments
 (0)