Skip to content

Commit 82275e1

Browse files
authored
Merge pull request #618 from aguibert/driver-service-master
Driver service for generic API entry point
2 parents 64cfee7 + 32de528 commit 82275e1

File tree

20 files changed

+657
-24
lines changed

20 files changed

+657
-24
lines changed

vertx-db2-client/src/main/java/io/vertx/db2client/DB2ConnectOptions.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static DB2ConnectOptions fromUri(String connectionUri) throws IllegalArgu
5959
DEFAULT_CONNECTION_ATTRIBUTES = Collections.unmodifiableMap(defaultAttributes);
6060
}
6161

62-
private int pipeliningLimit;
62+
private int pipeliningLimit = DEFAULT_PIPELINING_LIMIT;
6363

6464
public DB2ConnectOptions() {
6565
super();
@@ -74,6 +74,14 @@ public DB2ConnectOptions(JsonObject json) {
7474
super(json);
7575
DB2ConnectOptionsConverter.fromJson(json, this);
7676
}
77+
78+
public DB2ConnectOptions(SqlConnectOptions other) {
79+
super(other);
80+
if (other instanceof DB2ConnectOptions) {
81+
DB2ConnectOptions opts = (DB2ConnectOptions) other;
82+
this.pipeliningLimit = opts.pipeliningLimit;
83+
}
84+
}
7785

7886
public DB2ConnectOptions(DB2ConnectOptions other) {
7987
super(other);
@@ -170,7 +178,6 @@ public DB2ConnectOptions addProperty(String key, String value) {
170178
protected void init() {
171179
this.setHost(DEFAULT_HOST);
172180
this.setPort(DEFAULT_PORT);
173-
this.setPipeliningLimit(DEFAULT_PIPELINING_LIMIT);
174181
this.setProperties(new HashMap<>(DEFAULT_CONNECTION_ATTRIBUTES));
175182
}
176183

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.vertx.db2client.spi;
17+
18+
import io.vertx.core.Vertx;
19+
import io.vertx.db2client.DB2ConnectOptions;
20+
import io.vertx.db2client.DB2Pool;
21+
import io.vertx.sqlclient.Pool;
22+
import io.vertx.sqlclient.PoolOptions;
23+
import io.vertx.sqlclient.SqlConnectOptions;
24+
import io.vertx.sqlclient.spi.Driver;
25+
26+
public class DB2Driver implements Driver {
27+
28+
@Override
29+
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
30+
return DB2Pool.pool(wrap(options), poolOptions);
31+
}
32+
33+
@Override
34+
public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolOptions) {
35+
return DB2Pool.pool(vertx, wrap(options), poolOptions);
36+
}
37+
38+
@Override
39+
public boolean acceptsOptions(SqlConnectOptions options) {
40+
return options instanceof DB2ConnectOptions || SqlConnectOptions.class.equals(options.getClass());
41+
}
42+
43+
private static DB2ConnectOptions wrap(SqlConnectOptions options) {
44+
if (options instanceof DB2ConnectOptions) {
45+
return (DB2ConnectOptions) options;
46+
} else {
47+
return new DB2ConnectOptions(options);
48+
}
49+
}
50+
51+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.vertx.db2client.spi.DB2Driver
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.vertx.db2client.tck;
18+
19+
import org.junit.Before;
20+
import org.junit.ClassRule;
21+
import org.junit.Rule;
22+
import org.junit.rules.TestName;
23+
import org.junit.runner.RunWith;
24+
25+
import io.vertx.db2client.junit.DB2Resource;
26+
import io.vertx.ext.unit.TestContext;
27+
import io.vertx.ext.unit.junit.VertxUnitRunner;
28+
import io.vertx.sqlclient.SqlConnectOptions;
29+
import io.vertx.sqlclient.tck.DriverTestBase;
30+
31+
@RunWith(VertxUnitRunner.class)
32+
public class DB2DriverTest extends DriverTestBase {
33+
@ClassRule
34+
public static DB2Resource rule = DB2Resource.SHARED_INSTANCE;
35+
36+
@Rule
37+
public TestName testName = new TestName();
38+
39+
@Before
40+
public void printTestName(TestContext ctx) throws Exception {
41+
System.out.println(">>> BEGIN " + getClass().getSimpleName() + "." + testName.getMethodName());
42+
}
43+
44+
@Override
45+
protected SqlConnectOptions defaultOptions() {
46+
return rule.options();
47+
}
48+
49+
}

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLConnectOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public MSSQLConnectOptions(JsonObject json) {
5858
super(json);
5959
MSSQLConnectOptionsConverter.fromJson(json, this);
6060
}
61+
62+
public MSSQLConnectOptions(SqlConnectOptions other) {
63+
super(other);
64+
}
6165

6266
public MSSQLConnectOptions(MSSQLConnectOptions other) {
6367
super(other);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.vertx.mssqlclient.spi;
17+
18+
import io.vertx.core.Vertx;
19+
import io.vertx.mssqlclient.MSSQLConnectOptions;
20+
import io.vertx.mssqlclient.MSSQLPool;
21+
import io.vertx.sqlclient.Pool;
22+
import io.vertx.sqlclient.PoolOptions;
23+
import io.vertx.sqlclient.SqlConnectOptions;
24+
import io.vertx.sqlclient.spi.Driver;
25+
26+
public class MSSQLDriver implements Driver {
27+
28+
@Override
29+
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
30+
return MSSQLPool.pool(wrap(options), poolOptions);
31+
}
32+
33+
@Override
34+
public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolOptions) {
35+
return MSSQLPool.pool(vertx, wrap(options), poolOptions);
36+
}
37+
38+
@Override
39+
public boolean acceptsOptions(SqlConnectOptions options) {
40+
return options instanceof MSSQLConnectOptions || SqlConnectOptions.class.equals(options.getClass());
41+
}
42+
43+
private static MSSQLConnectOptions wrap(SqlConnectOptions options) {
44+
if (options instanceof MSSQLConnectOptions) {
45+
return (MSSQLConnectOptions) options;
46+
} else {
47+
return new MSSQLConnectOptions(options);
48+
}
49+
}
50+
51+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.vertx.mssqlclient.spi.MSSQLDriver
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.vertx.mssqlclient.tck;
18+
19+
import io.vertx.sqlclient.SqlConnectOptions;
20+
import io.vertx.sqlclient.tck.DriverTestBase;
21+
import io.vertx.ext.unit.junit.VertxUnitRunner;
22+
import io.vertx.mssqlclient.junit.MSSQLRule;
23+
24+
import org.junit.ClassRule;
25+
import org.junit.runner.RunWith;
26+
27+
@RunWith(VertxUnitRunner.class)
28+
public class MSSQLDriverTest extends DriverTestBase {
29+
@ClassRule
30+
public static MSSQLRule rule = MSSQLRule.SHARED_INSTANCE;
31+
32+
@Override
33+
protected SqlConnectOptions defaultOptions() {
34+
return rule.options();
35+
}
36+
37+
}

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLConnectOptions.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,37 @@ public static MySQLConnectOptions fromUri(String connectionUri) throws IllegalAr
6060
}
6161

6262
private String collation;
63-
private String charset;
64-
private Boolean useAffectedRows;
65-
private SslMode sslMode;
63+
private String charset = DEFAULT_CHARSET;
64+
private Boolean useAffectedRows = DEFAULT_USE_AFFECTED_ROWS;
65+
private SslMode sslMode = DEFAULT_SSL_MODE;
6666
private String serverRsaPublicKeyPath;
6767
private Buffer serverRsaPublicKeyValue;
68-
private String characterEncoding;
68+
private String characterEncoding = DEFAULT_CHARACTER_ENCODING;
6969

7070
public MySQLConnectOptions() {
7171
super();
72-
this.charset = DEFAULT_CHARSET;
73-
this.sslMode = DEFAULT_SSL_MODE;
74-
this.useAffectedRows = DEFAULT_USE_AFFECTED_ROWS;
75-
this.characterEncoding = DEFAULT_CHARACTER_ENCODING;
7672
}
7773

7874
public MySQLConnectOptions(JsonObject json) {
7975
super(json);
80-
this.charset = DEFAULT_CHARSET;
81-
this.sslMode = DEFAULT_SSL_MODE;
82-
this.useAffectedRows = DEFAULT_USE_AFFECTED_ROWS;
83-
this.characterEncoding = DEFAULT_CHARACTER_ENCODING;
8476
MySQLConnectOptionsConverter.fromJson(json, this);
8577
}
78+
79+
public MySQLConnectOptions(SqlConnectOptions other) {
80+
super(other);
81+
if (other instanceof MySQLConnectOptions) {
82+
MySQLConnectOptions opts = (MySQLConnectOptions) other;
83+
this.collation = opts.collation;
84+
this.serverRsaPublicKeyPath = opts.serverRsaPublicKeyPath;
85+
this.serverRsaPublicKeyValue = opts.serverRsaPublicKeyValue != null ? opts.serverRsaPublicKeyValue.copy() : null;
86+
}
87+
}
8688

8789
public MySQLConnectOptions(MySQLConnectOptions other) {
8890
super(other);
8991
this.collation = other.collation;
90-
this.charset = other.charset;
91-
this.useAffectedRows = other.useAffectedRows;
92-
this.sslMode = other.sslMode;
9392
this.serverRsaPublicKeyPath = other.serverRsaPublicKeyPath;
9493
this.serverRsaPublicKeyValue = other.serverRsaPublicKeyValue != null ? other.serverRsaPublicKeyValue.copy() : null;
95-
this.characterEncoding = other.characterEncoding;
9694
}
9795

9896
/**
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2020 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.vertx.mysqlclient.spi;
17+
18+
import io.vertx.core.Vertx;
19+
import io.vertx.mysqlclient.MySQLConnectOptions;
20+
import io.vertx.mysqlclient.MySQLPool;
21+
import io.vertx.sqlclient.Pool;
22+
import io.vertx.sqlclient.PoolOptions;
23+
import io.vertx.sqlclient.SqlConnectOptions;
24+
import io.vertx.sqlclient.spi.Driver;
25+
26+
public class MySQLDriver implements Driver {
27+
28+
@Override
29+
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
30+
return MySQLPool.pool(wrap(options), poolOptions);
31+
}
32+
33+
@Override
34+
public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolOptions) {
35+
return MySQLPool.pool(vertx, wrap(options), poolOptions);
36+
}
37+
38+
@Override
39+
public boolean acceptsOptions(SqlConnectOptions options) {
40+
return options instanceof MySQLConnectOptions || SqlConnectOptions.class.equals(options.getClass());
41+
}
42+
43+
private static MySQLConnectOptions wrap(SqlConnectOptions options) {
44+
if (options instanceof MySQLConnectOptions) {
45+
return (MySQLConnectOptions) options;
46+
} else {
47+
return new MySQLConnectOptions(options);
48+
}
49+
}
50+
51+
}

0 commit comments

Comments
 (0)