-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for create database if not exist
- Support `InitDbMessage`. - Support `changeDatabase` in `MySqlConnection`. - Add integration tests for that.
- Loading branch information
1 parent
46e9e69
commit 24f603c
Showing
15 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/asyncer/r2dbc/mysql/message/client/InitDbMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.asyncer.r2dbc.mysql.message.client; | ||
|
||
import io.asyncer.r2dbc.mysql.ConnectionContext; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
public final class InitDbMessage extends ScalarClientMessage { | ||
|
||
private static final byte FLAG = 0x02; | ||
|
||
private final String database; | ||
|
||
public InitDbMessage(String database) { this.database = database; } | ||
|
||
@Override | ||
protected void writeTo(ByteBuf buf, ConnectionContext context) { | ||
// RestOfPacketString, no need terminal or length | ||
buf.writeByte(FLAG).writeCharSequence(database, context.getClientCollation().getCharset()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/io/asyncer/r2dbc/mysql/InitDbIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.asyncer.r2dbc.mysql; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Integration tests for {@code createDatabaseIfNotExist}. | ||
*/ | ||
class InitDbIntegrationTest extends IntegrationTestSupport { | ||
|
||
private static final String DATABASE = "test-" + ThreadLocalRandom.current().nextInt(10000); | ||
|
||
InitDbIntegrationTest() { | ||
super(configuration( | ||
DATABASE, true, false, | ||
null, null | ||
)); | ||
} | ||
|
||
@Test | ||
void shouldCreateDatabase() { | ||
complete(conn -> conn.createStatement("SHOW DATABASES") | ||
.execute() | ||
.flatMap(it -> it.map((row, rowMetadata) -> row.get(0, String.class))) | ||
.collect(Collectors.toSet()) | ||
.doOnNext(it -> assertThat(it).contains(DATABASE)) | ||
.thenMany(conn.createStatement("DROP DATABASE `" + DATABASE + "`") | ||
.execute() | ||
.flatMap(MySqlResult::getRowsUpdated))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters