Skip to content

Commit 2c2eac8

Browse files
committed
Various API cleanups
1 parent 0b2633b commit 2c2eac8

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
lines changed

vertx-db2-client/src/main/java/io/vertx/db2client/impl/DB2SocketConnection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ public void init() {
102102
protected <R> void doSchedule(CommandBase<R> cmd, Completable<R> handler) {
103103
if (cmd instanceof TxCommand) {
104104
TxCommand<R> txCmd = (TxCommand<R>) cmd;
105-
if (txCmd.kind == TxCommand.Kind.BEGIN) {
105+
if (txCmd.kind() == TxCommand.Kind.BEGIN) {
106106
// DB2 always implicitly starts a transaction with each query, and does
107107
// not support the 'BEGIN' keyword. Instead we can no-op BEGIN commands
108-
handler.succeed(txCmd.result);
108+
handler.succeed(txCmd.result());
109109
} else {
110-
SimpleQueryCommand<Void> cmd2 = new SimpleQueryCommand<>(txCmd.kind.sql, false, false,
111-
QueryCommandBase.NULL_COLLECTOR, QueryResultHandler.NOOP_HANDLER);
112-
super.doSchedule(cmd2, (res, err) -> handler.complete(txCmd.result, err));
110+
SimpleQueryCommand<Void> cmd2 = new SimpleQueryCommand<>(txCmd.kind().sql(), false, false,
111+
SocketConnectionBase.NULL_COLLECTOR, QueryResultHandler.NOOP_HANDLER);
112+
super.doSchedule(cmd2, (res, err) -> handler.complete(txCmd.result(), err));
113113

114114
}
115115
} else {

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import io.netty.channel.ChannelPipeline;
1515
import io.netty.channel.ChannelPromise;
1616
import io.netty.handler.ssl.SslHandler;
17-
import io.vertx.core.AsyncResult;
1817
import io.vertx.core.Completable;
1918
import io.vertx.core.Future;
20-
import io.vertx.core.Handler;
2119
import io.vertx.core.internal.ContextInternal;
2220
import io.vertx.core.internal.PromiseInternal;
2321
import io.vertx.core.internal.tls.SslContextManager;
@@ -166,14 +164,14 @@ public void init() {
166164
protected <R> void doSchedule(CommandBase<R> cmd, Completable<R> handler) {
167165
if (cmd instanceof TxCommand) {
168166
TxCommand<R> tx = (TxCommand<R>) cmd;
169-
String sql = tx.kind == BEGIN ? "BEGIN TRANSACTION":tx.kind.sql;
167+
String sql = tx.kind() == BEGIN ? "BEGIN TRANSACTION" : tx.kind().sql();
170168
SimpleQueryCommand<Void> cmd2 = new SimpleQueryCommand<>(
171169
sql,
172170
false,
173171
false,
174-
QueryCommandBase.NULL_COLLECTOR,
172+
SocketConnectionBase.NULL_COLLECTOR,
175173
QueryResultHandler.NOOP_HANDLER);
176-
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result, err));
174+
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result(), err));
177175
} else {
178176
super.doSchedule(cmd, handler);
179177
}

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLSocketConnection.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import io.vertx.sqlclient.impl.SocketConnectionBase;
4444
import io.vertx.sqlclient.internal.command.CommandBase;
4545
import io.vertx.sqlclient.internal.command.ExtendedQueryCommand;
46-
import io.vertx.sqlclient.internal.command.QueryCommandBase;
4746
import io.vertx.sqlclient.internal.command.SimpleQueryCommand;
4847
import io.vertx.sqlclient.internal.command.TxCommand;
4948
import io.vertx.sqlclient.spi.DatabaseMetadata;
@@ -122,12 +121,12 @@ protected <R> void doSchedule(CommandBase<R> cmd, Completable<R> handler) {
122121
if (cmd instanceof TxCommand) {
123122
TxCommand<R> tx = (TxCommand<R>) cmd;
124123
SimpleQueryCommand<Void> cmd2 = new SimpleQueryCommand<>(
125-
tx.kind.sql,
124+
tx.kind().sql(),
126125
false,
127126
false,
128-
QueryCommandBase.NULL_COLLECTOR,
127+
SocketConnectionBase.NULL_COLLECTOR,
129128
QueryResultHandler.NOOP_HANDLER);
130-
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result, err));
129+
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result(), err));
131130
} else {
132131
super.doSchedule(cmd, handler);
133132
}

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleTransactionCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public static <U> OracleTransactionCommand<U> create(OracleConnection oracleConn
3535
@Override
3636
protected Future<R> execute() {
3737
Future<Void> result;
38-
if (op.kind == BEGIN) {
38+
if (op.kind() == BEGIN) {
3939
result = begin();
40-
} else if (op.kind == COMMIT) {
40+
} else if (op.kind() == COMMIT) {
4141
result = commit();
4242
} else {
4343
result = rollback();
4444
}
45-
return result.map(op.result);
45+
return result.map(op.result());
4646
}
4747

4848
private Future<Void> begin() {

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgSocketConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ protected <R> void doSchedule(CommandBase<R> cmd, Completable<R> handler) {
163163
if (cmd instanceof TxCommand) {
164164
TxCommand<R> tx = (TxCommand<R>) cmd;
165165
SimpleQueryCommand<Void> cmd2 = new SimpleQueryCommand<>(
166-
tx.kind.sql,
166+
tx.kind().sql(),
167167
false,
168168
false,
169-
QueryCommandBase.NULL_COLLECTOR,
169+
SocketConnectionBase.NULL_COLLECTOR,
170170
QueryResultHandler.NOOP_HANDLER);
171-
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result, err));
171+
super.doSchedule(cmd2, (res, err) -> handler.complete(tx.result(), err));
172172
} else {
173173
super.doSchedule(cmd, handler);
174174
}

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/SocketConnectionBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.vertx.core.tracing.TracingPolicy;
3030
import io.vertx.core.internal.ContextInternal;
3131
import io.vertx.core.internal.net.NetSocketInternal;
32+
import io.vertx.sqlclient.Row;
3233
import io.vertx.sqlclient.SqlConnectOptions;
3334
import io.vertx.sqlclient.impl.cache.PreparedStatementCache;
3435
import io.vertx.sqlclient.impl.codec.InvalidCachedStatementEvent;
@@ -39,13 +40,16 @@
3940

4041
import java.util.ArrayDeque;
4142
import java.util.List;
43+
import java.util.function.Function;
4244
import java.util.function.Predicate;
45+
import java.util.stream.Collector;
4346

4447
/**
4548
* @author <a href="mailto:[email protected]">Julien Viet</a>
4649
*/
4750
public abstract class SocketConnectionBase implements Connection {
4851

52+
public static final Collector<Row, Void, Void> NULL_COLLECTOR = Collector.of(() -> null, (v, row) -> {}, (v1, v2) -> null, Function.identity());
4953
private static final Completable<?> NULL_HANDLER = (res, err) -> {};
5054

5155
public static final Logger logger = LoggerFactory.getLogger(SocketConnectionBase.class);

vertx-sql-client/src/main/java/io/vertx/sqlclient/internal/command/QueryCommandBase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.vertx.sqlclient.Row;
2121
import io.vertx.sqlclient.internal.QueryResultHandler;
2222

23-
import java.util.function.Function;
2423
import java.util.stream.Collector;
2524

2625
/**
@@ -29,8 +28,6 @@
2928

3029
public abstract class QueryCommandBase<T> extends CommandBase<Boolean> {
3130

32-
public static final Collector<Row, Void, Void> NULL_COLLECTOR = Collector.of(() -> null, (v,row) -> {}, (v1, v2) -> null, Function.identity());
33-
3431
private final QueryResultHandler<T> resultHandler;
3532
private final Collector<Row, ?, T> collector;
3633
private final boolean autoCommit;

vertx-sql-client/src/main/java/io/vertx/sqlclient/internal/command/TxCommand.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,30 @@ public enum Kind {
1717

1818
BEGIN(), ROLLBACK(), COMMIT();
1919

20-
public final String sql;
20+
private final String sql;
2121

2222
Kind() {
2323
this.sql = name();
2424
}
25+
26+
public String sql() {
27+
return sql;
28+
}
2529
}
2630

27-
public final R result;
28-
public final Kind kind;
31+
private final R result;
32+
private final Kind kind;
2933

3034
public TxCommand(Kind kind, R result) {
3135
this.kind = kind;
3236
this.result = result;
3337
}
38+
39+
public R result() {
40+
return result;
41+
}
42+
43+
public Kind kind() {
44+
return kind;
45+
}
3446
}

0 commit comments

Comments
 (0)