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

Generic path to create specific SqlConnectOptions #644

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,11 @@ public DB2ConnectOptions(JsonObject json) {
DB2ConnectOptionsConverter.fromJson(json, this);
}

public DB2ConnectOptions(SqlConnectOptions other) {
super(other);
if (other instanceof DB2ConnectOptions) {
DB2ConnectOptions opts = (DB2ConnectOptions) other;
this.pipeliningLimit = opts.pipeliningLimit;
}
}

public DB2ConnectOptions(DB2ConnectOptions other) {
super(other);
this.pipeliningLimit = other.pipeliningLimit;
}

@Override
public DB2ConnectOptions setHost(String host) {
return (DB2ConnectOptions) super.setHost(host);
Expand Down Expand Up @@ -210,6 +202,6 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(pipeliningLimit);
return Objects.hash(super.hashCode(), pipeliningLimit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public String getSqlState() {
*/
@Override
public String getMessage() {
return super.getMessage();
return super.getMessage() + "; errorCode=" + errorCode + "; sqlState=" + sqlState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.vertx.sqlclient.spi.Driver;

public class DB2Driver implements Driver {

@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
return DB2Pool.pool(wrap(options), poolOptions);
Expand All @@ -35,17 +35,22 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
return DB2Pool.pool(vertx, wrap(options), poolOptions);
}

@Override
public boolean acceptsOptions(SqlConnectOptions options) {
return options instanceof DB2ConnectOptions || SqlConnectOptions.class.equals(options.getClass());
}

private static DB2ConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof DB2ConnectOptions) {
return (DB2ConnectOptions) options;
return (DB2ConnectOptions) options;
} else {
return new DB2ConnectOptions(options);
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
}

@Override
public SqlConnectOptions createConnectOptions() {
return new DB2ConnectOptions();
}

@Override
public String name() {
return "DB2";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ protected SqlConnectOptions defaultOptions() {
return rule.options();
}

@Override
protected String getDriverName() {
return "DB2";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

package io.vertx.mssqlclient;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
Expand All @@ -26,11 +31,6 @@
import io.vertx.core.net.TrustOptions;
import io.vertx.sqlclient.SqlConnectOptions;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
* Connect options for configuring {@link MSSQLConnection}.
*/
Expand Down Expand Up @@ -61,14 +61,10 @@ public MSSQLConnectOptions(JsonObject json) {
MSSQLConnectOptionsConverter.fromJson(json, this);
}

public MSSQLConnectOptions(SqlConnectOptions other) {
super(other);
}

public MSSQLConnectOptions(MSSQLConnectOptions other) {
super(other);
}

@Override
public MSSQLConnectOptions setHost(String host) {
return (MSSQLConnectOptions) super.setHost(host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.vertx.sqlclient.spi.Driver;

public class MSSQLDriver implements Driver {

@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
return MSSQLPool.pool(wrap(options), poolOptions);
Expand All @@ -35,17 +35,22 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
return MSSQLPool.pool(vertx, wrap(options), poolOptions);
}

@Override
public boolean acceptsOptions(SqlConnectOptions options) {
return options instanceof MSSQLConnectOptions || SqlConnectOptions.class.equals(options.getClass());
}

private static MSSQLConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof MSSQLConnectOptions) {
return (MSSQLConnectOptions) options;
} else {
return new MSSQLConnectOptions(options);
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
}

@Override
public SqlConnectOptions createConnectOptions() {
return new MSSQLConnectOptions();
}

@Override
public String name() {
return "SQLSERVER";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ public class MSSQLDriverTest extends DriverTestBase {
protected SqlConnectOptions defaultOptions() {
return rule.options();
}


@Override
protected String getDriverName() {
return "SQLSERVER";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,13 @@ public MySQLConnectOptions(JsonObject json) {
MySQLConnectOptionsConverter.fromJson(json, this);
}

public MySQLConnectOptions(SqlConnectOptions other) {
super(other);
if (other instanceof MySQLConnectOptions) {
MySQLConnectOptions opts = (MySQLConnectOptions) other;
this.collation = opts.collation;
this.serverRsaPublicKeyPath = opts.serverRsaPublicKeyPath;
this.serverRsaPublicKeyValue = opts.serverRsaPublicKeyValue != null ? opts.serverRsaPublicKeyValue.copy() : null;
}
}

public MySQLConnectOptions(MySQLConnectOptions other) {
super(other);
this.collation = other.collation;
this.serverRsaPublicKeyPath = other.serverRsaPublicKeyPath;
this.serverRsaPublicKeyValue = other.serverRsaPublicKeyValue != null ? other.serverRsaPublicKeyValue.copy() : null;
}

/**
* Get the collation for the connection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.vertx.sqlclient.spi.Driver;

public class MySQLDriver implements Driver {

@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
return MySQLPool.pool(wrap(options), poolOptions);
Expand All @@ -35,17 +35,22 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
return MySQLPool.pool(vertx, wrap(options), poolOptions);
}

@Override
public boolean acceptsOptions(SqlConnectOptions options) {
return options instanceof MySQLConnectOptions || SqlConnectOptions.class.equals(options.getClass());
}

private static MySQLConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof MySQLConnectOptions) {
return (MySQLConnectOptions) options;
return (MySQLConnectOptions) options;
} else {
return new MySQLConnectOptions(options);
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
}

@Override
public SqlConnectOptions createConnectOptions() {
return new MySQLConnectOptions();
}

@Override
public String name() {
return "MYSQL";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ protected SqlConnectOptions defaultOptions() {
return rule.options();
}

@Override
protected String getDriverName() {
return "MYSQL";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,12 @@ public PgConnectOptions(JsonObject json) {
PgConnectOptionsConverter.fromJson(json, this);
}

public PgConnectOptions(SqlConnectOptions other) {
super(other);
if (other instanceof PgConnectOptions) {
PgConnectOptions opts = (PgConnectOptions) other;
pipeliningLimit = opts.pipeliningLimit;
sslMode = opts.sslMode;
}
}

public PgConnectOptions(PgConnectOptions other) {
super(other);
pipeliningLimit = other.pipeliningLimit;
sslMode = other.sslMode;
}

@Override
public PgConnectOptions setHost(String host) {
return (PgConnectOptions) super.setHost(host);
Expand Down
21 changes: 13 additions & 8 deletions vertx-pg-client/src/main/java/io/vertx/pgclient/spi/PgDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.vertx.sqlclient.spi.Driver;

public class PgDriver implements Driver {

@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
return PgPool.pool(wrap(options), poolOptions);
Expand All @@ -20,17 +20,22 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
return PgPool.pool(vertx, wrap(options), poolOptions);
}

@Override
public boolean acceptsOptions(SqlConnectOptions options) {
return options instanceof PgConnectOptions || SqlConnectOptions.class.equals(options.getClass());
}

private static PgConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof PgConnectOptions) {
return (PgConnectOptions) options;
return (PgConnectOptions) options;
} else {
return new PgConnectOptions(options);
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
}

@Override
public SqlConnectOptions createConnectOptions() {
return new PgConnectOptions();
}

@Override
public String name() {
return "POSTGRESQL";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ protected SqlConnectOptions defaultOptions() {
return rule.options();
}

@Override
protected String getDriverName() {
return "POSTGRESQL";
}

}
4 changes: 4 additions & 0 deletions vertx-sql-client/src/main/java/io/vertx/sqlclient/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand All @@ -46,6 +47,7 @@ public interface Pool extends SqlClient {
* @return the connection pool
* @throws ServiceConfigurationError if no compatible drivers are found, or if multiple compatible drivers are found
*/
@GenIgnore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove these @GenIgnore annotations ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build was failing saying these were not supported, I can go back and check again, but the whole generation step is an enigma to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you push the branch to the upstream repo so that we could try to build that and see what happens?

static Pool pool(SqlConnectOptions connectOptions) {
return pool(connectOptions, new PoolOptions());
}
Expand All @@ -58,6 +60,7 @@ static Pool pool(SqlConnectOptions connectOptions) {
* @return the connection pool
* @throws ServiceConfigurationError if no compatible drivers are found, or if multiple compatible drivers are found
*/
@GenIgnore
static Pool pool(SqlConnectOptions connectOptions, PoolOptions poolOptions) {
List<Driver> candidates = new ArrayList<>(1);
for (Driver d : ServiceLoader.load(Driver.class)) {
Expand All @@ -83,6 +86,7 @@ static Pool pool(SqlConnectOptions connectOptions, PoolOptions poolOptions) {
* @return the connection pool
* @throws ServiceConfigurationError if no compatible drivers are found, or if multiple compatible drivers are found
*/
@GenIgnore
static Pool pool(Vertx vertx, SqlConnectOptions connectOptions, PoolOptions poolOptions) {
List<Driver> candidates = new ArrayList<>(1);
for (Driver d : ServiceLoader.load(Driver.class)) {
Expand Down
Loading