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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make SqlConnectOptions abstract again so that Driver#createConnectOpt…
…ions is the only generic path
aguibert committed May 29, 2020
commit ed25c7195b9545b074fd2e32c4550e0886aff548
Original file line number Diff line number Diff line change
@@ -76,14 +76,6 @@ 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;
Original file line number Diff line number Diff line change
@@ -38,8 +38,6 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
private static DB2ConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof DB2ConnectOptions) {
return (DB2ConnectOptions) options;
} else if (options.getClass().equals(SqlConnectOptions.class)) {
return new DB2ConnectOptions(options);
} else {
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
Original file line number Diff line number Diff line change
@@ -61,10 +61,6 @@ public MSSQLConnectOptions(JsonObject json) {
MSSQLConnectOptionsConverter.fromJson(json, this);
}

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

public MSSQLConnectOptions(MSSQLConnectOptions other) {
super(other);
}
Original file line number Diff line number Diff line change
@@ -38,8 +38,6 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
private static MSSQLConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof MSSQLConnectOptions) {
return (MSSQLConnectOptions) options;
} else if (SqlConnectOptions.class.equals(options.getClass())) {
return new MSSQLConnectOptions(options);
} else {
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
Original file line number Diff line number Diff line change
@@ -76,16 +76,6 @@ 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;
Original file line number Diff line number Diff line change
@@ -38,8 +38,6 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
private static MySQLConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof MySQLConnectOptions) {
return (MySQLConnectOptions) options;
} else if (options.getClass().equals(SqlConnectOptions.class)) {
return new MySQLConnectOptions(options);
} else {
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
Original file line number Diff line number Diff line change
@@ -121,15 +121,6 @@ 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;
Original file line number Diff line number Diff line change
@@ -23,8 +23,6 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO
private static PgConnectOptions wrap(SqlConnectOptions options) {
if (options instanceof PgConnectOptions) {
return (PgConnectOptions) options;
} else if (options.getClass().equals(SqlConnectOptions.class)) {
return new PgConnectOptions(options);
} else {
throw new IllegalArgumentException("Unsupported option type: " + options.getClass());
}
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
@@ -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;
@@ -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());
}
@@ -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)) {
@@ -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)) {
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
* Connect options for configuring {@link SqlConnection} or {@link Pool}.
*/
@DataObject(generateConverter = true)
public class SqlConnectOptions extends NetClientOptions {
public abstract class SqlConnectOptions extends NetClientOptions {

public static final boolean DEFAULT_CACHE_PREPARED_STATEMENTS = false;
public static final int DEFAULT_PREPARED_STATEMENT_CACHE_MAX_SIZE = 256;
@@ -41,32 +41,17 @@ public class SqlConnectOptions extends NetClientOptions {
private int preparedStatementCacheSqlLimit = DEFAULT_PREPARED_STATEMENT_CACHE_SQL_LIMIT;
private Map<String, String> properties = new HashMap<>(4);

/**
* @deprecated This constructor will be removed in the next release.
* Instead, use {@link Driver#createConnectOptions()}
*/
@Deprecated
public SqlConnectOptions() {
super();
init();
}

/**
* @deprecated This constructor will be removed in the next release.
* Instead, use {@link Driver#createConnectOptions()}
*/
@Deprecated
public SqlConnectOptions(JsonObject json) {
super(json);
init();
SqlConnectOptionsConverter.fromJson(json, this);
}

/**
* @deprecated This constructor will be removed in the next release.
* Instead, use {@link Driver#createConnectOptions()}
*/
@Deprecated
public SqlConnectOptions(SqlConnectOptions other) {
super(other);
this.host = other.host;
@@ -294,8 +279,7 @@ public JsonObject toJson() {
/**
* Initialize with the default options.
*/
protected void init() {
}
protected abstract void init();

@Override
public boolean equals(Object obj) {
Original file line number Diff line number Diff line change
@@ -133,8 +133,7 @@ default Pool createPool(SqlConnectOptions connectOptions) {
* @return true if the driver accepts the {@code connectOptions}, false otherwise
*/
default boolean acceptsOptions(SqlConnectOptions connectOptions) {
return createConnectOptions().getClass().isAssignableFrom(connectOptions.getClass()) ||
SqlConnectOptions.class.equals(connectOptions.getClass());
return createConnectOptions().getClass().isAssignableFrom(connectOptions.getClass());
}

/**
Original file line number Diff line number Diff line change
@@ -138,6 +138,9 @@ public void testRejectCreatePool03(TestContext ctx) {
}

public static class BogusOptions extends SqlConnectOptions {
@Override
protected void init() {
}
}

private Driver getDriver() {