Skip to content

Commit c0393cf

Browse files
committed
Polishing.
Add test, remove duplications. [resolves #303][#273][#276][#289] Signed-off-by: Mark Paluch <[email protected]>
1 parent 46ddc56 commit c0393cf

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/main/java/io/r2dbc/mssql/MssqlConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public Mono<MssqlConnection> create() {
113113
return initializeClient(this.configuration, true)
114114
.flatMap(it -> {
115115

116-
ConnectionOptions connectionOptions = this.configuration.toConnectionOptions(this.codecs);
116+
ConnectionOptions connectionOptions = getConnectionOptions();
117117
Mono<MssqlConnection> connectionMono =
118118
new SimpleMssqlStatement(it, connectionOptions, this.METADATA_QUERY).execute()
119119
.flatMap(result -> result.map((row, rowMetadata) -> toConnectionMetadata(it.getDatabaseVersion().orElse("unknown"), row))).map(metadata -> {

src/test/java/io/r2dbc/mssql/MssqlConnectionFactoryUnitTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@
2020
import io.r2dbc.mssql.message.tds.Encode;
2121
import io.r2dbc.mssql.message.tds.Redirect;
2222
import io.r2dbc.mssql.message.tds.ServerCharset;
23-
import io.r2dbc.mssql.message.token.Column;
24-
import io.r2dbc.mssql.message.token.ColumnMetadataToken;
25-
import io.r2dbc.mssql.message.token.DoneToken;
26-
import io.r2dbc.mssql.message.token.ErrorToken;
27-
import io.r2dbc.mssql.message.token.Prelogin;
28-
import io.r2dbc.mssql.message.token.RowToken;
29-
import io.r2dbc.mssql.message.token.RowTokenFactory;
30-
import io.r2dbc.mssql.message.token.SqlBatch;
23+
import io.r2dbc.mssql.message.token.*;
3124
import io.r2dbc.mssql.message.type.LengthStrategy;
3225
import io.r2dbc.mssql.message.type.SqlServerType;
3326
import io.r2dbc.mssql.message.type.TypeInformation;
@@ -171,6 +164,19 @@ void shouldFailOnMultipleRedirects() {
171164
assertThat(redirect.isClosed()).isTrue();
172165
}
173166

167+
@Test
168+
void shouldCreateNewPreparedStatement() {
169+
170+
MssqlConnectionFactory connectionFactory = new MssqlConnectionFactory(config -> Mono.empty(), this.configuration);
171+
ConnectionOptions options = connectionFactory.getConnectionOptions();
172+
ConnectionOptions other = connectionFactory.getConnectionOptions();
173+
174+
options.getPreparedStatementCache().putHandle(1, "foo", new Binding());
175+
176+
assertThat(options.getPreparedStatementCache().getHandle("foo", new Binding())).isEqualTo(1);
177+
assertThat(other.getPreparedStatementCache().getHandle("foo", new Binding())).isEqualTo(0);
178+
}
179+
174180
private static Column createColumn(int index, String name, SqlServerType serverType, int length, LengthStrategy lengthStrategy, @Nullable Charset charset) {
175181

176182
TypeInformation.Builder builder = TypeInformation.builder().withServerType(serverType).withMaxLength(length).withLengthStrategy(lengthStrategy);

0 commit comments

Comments
 (0)