diff --git a/java/client/src/main/java/com/youtube/vitess/client/RpcClient.java b/java/client/src/main/java/com/youtube/vitess/client/RpcClient.java index b73d45dd0f..eaf6ef6703 100644 --- a/java/client/src/main/java/com/youtube/vitess/client/RpcClient.java +++ b/java/client/src/main/java/com/youtube/vitess/client/RpcClient.java @@ -34,46 +34,46 @@ import java.util.Iterator; public interface RpcClient extends Closeable { // executeShard sends a single query to a set of shards. ExecuteShardsResponse executeShard( - Context ctx, ExecuteShardsRequest request) throws VitessRpcException; + Context ctx, ExecuteShardsRequest request) throws VitessException, VitessRpcException; // executeKeyspaceIds sends a query with keyspace ids as bind variables. ExecuteKeyspaceIdsResponse executeKeyspaceIds( - Context ctx, ExecuteKeyspaceIdsRequest request) throws VitessRpcException; + Context ctx, ExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException; // executeKeyRanges sends a query with a set of key ranges. ExecuteKeyRangesResponse executeKeyRanges( - Context ctx, ExecuteKeyRangesRequest request) throws VitessRpcException; + Context ctx, ExecuteKeyRangesRequest request) throws VitessException, VitessRpcException; // executeBatchKeyspaceIds sends a list of queries with keyspace ids as bind variables. ExecuteBatchKeyspaceIdsResponse executeBatchKeyspaceIds( - Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessRpcException; + Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessException, VitessRpcException; // executeBatchShards sends a list of queries to a set of shards. ExecuteBatchShardsResponse executeBatchShards( - Context ctx, ExecuteBatchShardsRequest request) throws VitessRpcException; + Context ctx, ExecuteBatchShardsRequest request) throws VitessException, VitessRpcException; // streamExecuteShard starts stream queries with multiple shards. Iterator streamExecuteShard( - Context ctx, StreamExecuteShardsRequest request) throws VitessRpcException; + Context ctx, StreamExecuteShardsRequest request) throws VitessException, VitessRpcException; // streamExecuteKeyspaceIds starts a list of stream queries with keyspace ids as bind variables. Iterator streamExecuteKeyspaceIds( - Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessRpcException; + Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException; // streamExecuteKeyRanges starts stream query with a set of key ranges. Iterator streamExecuteKeyRanges( - Context ctx, StreamExecuteKeyRangesRequest request) throws VitessRpcException; + Context ctx, StreamExecuteKeyRangesRequest request) throws VitessException, VitessRpcException; // begin starts a transaction. - BeginResponse begin(Context ctx, BeginRequest request) throws VitessRpcException; + BeginResponse begin(Context ctx, BeginRequest request) throws VitessException, VitessRpcException; // commit commits a transaction. - CommitResponse commit(Context ctx, CommitRequest request) throws VitessRpcException; + CommitResponse commit(Context ctx, CommitRequest request) throws VitessException, VitessRpcException; // rollback rollbacks a pending transaction. - RollbackResponse rollback(Context ctx, RollbackRequest request) throws VitessRpcException; + RollbackResponse rollback(Context ctx, RollbackRequest request) throws VitessException, VitessRpcException; // getSrvKeyspace returns a list of serving keyspaces. GetSrvKeyspaceResponse getSrvKeyspace( - Context ctx, GetSrvKeyspaceRequest request) throws VitessRpcException; + Context ctx, GetSrvKeyspaceRequest request) throws VitessException, VitessRpcException; } diff --git a/java/client/src/main/java/com/youtube/vitess/client/VTGateConn.java b/java/client/src/main/java/com/youtube/vitess/client/VTGateConn.java index 0b51656ea6..524a292ffd 100644 --- a/java/client/src/main/java/com/youtube/vitess/client/VTGateConn.java +++ b/java/client/src/main/java/com/youtube/vitess/client/VTGateConn.java @@ -27,7 +27,7 @@ import java.util.Iterator; /** * VTGateConn manages a VTGate connection. - * TODO(shengzhe): define VitessException for app-level error + * *

Usage: * * @@ -79,46 +79,46 @@ public class VTGateConn implements Closeable { } public ExecuteShardsResponse ExecuteShard(Context ctx, ExecuteShardsRequest request) - throws VitessRpcException { + throws VitessException, VitessRpcException { return this.client.executeShard(ctx, request); } public ExecuteKeyspaceIdsResponse ExecuteKeyspaceIds(Context ctx, ExecuteKeyspaceIdsRequest request) - throws VitessRpcException { + throws VitessException, VitessRpcException { return this.client.executeKeyspaceIds(ctx, request); } public ExecuteKeyRangesResponse executeKeyRanges(Context ctx, ExecuteKeyRangesRequest request) - throws VitessRpcException { + throws VitessException, VitessRpcException { return this.client.executeKeyRanges(ctx, request); } public ExecuteBatchKeyspaceIdsResponse executeBatchKeyspaceIds( - Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessRpcException { + Context ctx, ExecuteBatchKeyspaceIdsRequest request) throws VitessException, VitessRpcException { return this.client.executeBatchKeyspaceIds(ctx, request); } public ExecuteBatchShardsResponse executeBatchShards(Context ctx, ExecuteBatchShardsRequest request) - throws VitessRpcException { + throws VitessException, VitessRpcException { return this.client.executeBatchShards(ctx, request); } public Iterator streamExecuteShard( - Context ctx, StreamExecuteShardsRequest request) throws VitessRpcException { + Context ctx, StreamExecuteShardsRequest request) throws VitessException, VitessRpcException { return this.client.streamExecuteShard(ctx, request); } public Iterator streamExecuteKeyspaceIds( - Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessRpcException { + Context ctx, StreamExecuteKeyspaceIdsRequest request) throws VitessException, VitessRpcException { return this.client.streamExecuteKeyspaceIds(ctx, request); } public Iterator streamExecuteKeyRanges( - Context ctx, StreamExecuteKeyRangesRequest request) throws VitessRpcException { + Context ctx, StreamExecuteKeyRangesRequest request) throws VitessException, VitessRpcException { return this.client.streamExecuteKeyRanges(ctx, request); } - public VTGateTx begin(Context ctx, BeginRequest request) throws VitessRpcException { + public VTGateTx begin(Context ctx, BeginRequest request) throws VitessException, VitessRpcException { BeginResponse response = this.client.begin(ctx, request); if (response.hasError()) { throw new VitessRpcException(response.getError().getMessage()); @@ -127,7 +127,7 @@ public class VTGateConn implements Closeable { } public GetSrvKeyspaceResponse getSrvKeyspace(Context ctx, GetSrvKeyspaceRequest request) - throws VitessRpcException { + throws VitessException, VitessRpcException { return this.client.getSrvKeyspace(ctx, request); } diff --git a/java/client/src/main/java/com/youtube/vitess/client/VTGateTx.java b/java/client/src/main/java/com/youtube/vitess/client/VTGateTx.java index 7cb5c49a65..8c7bc42814 100644 --- a/java/client/src/main/java/com/youtube/vitess/client/VTGateTx.java +++ b/java/client/src/main/java/com/youtube/vitess/client/VTGateTx.java @@ -37,7 +37,7 @@ public class VTGateTx { } public QueryResult executeShard(Context ctx, ExecuteShardsRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("executeShard: not in transaction"); } @@ -47,7 +47,7 @@ public class VTGateTx { } public QueryResult executeKeyspaceIds(Context ctx, ExecuteKeyspaceIdsRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("executeKeyspaceIds: not in transaction"); } @@ -57,7 +57,7 @@ public class VTGateTx { } public QueryResult executeKeyRanges(Context ctx, ExecuteKeyRangesRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("executeKeyRanges: not in transaction"); } @@ -68,7 +68,7 @@ public class VTGateTx { public List executeBatchKeyspaceIds( Context ctx, ExecuteBatchKeyspaceIdsRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("executeBatchKeyspaceIds: not in transaction"); } @@ -78,7 +78,7 @@ public class VTGateTx { } public List executeBatchShards(Context ctx, ExecuteBatchShardsRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("executeBatchShards: not in transaction"); } @@ -89,7 +89,7 @@ public class VTGateTx { public CommitResponse commit(Context ctx, CommitRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("commit: not in transaction"); } @@ -100,7 +100,7 @@ public class VTGateTx { } public RollbackResponse rollback(Context ctx, RollbackRequest request) - throws VitessRpcException, VitessNotInTransactionException { + throws VitessException, VitessRpcException, VitessNotInTransactionException { if (this.session == null) { throw new VitessNotInTransactionException("rollback: not in transaction"); } diff --git a/java/client/src/main/java/com/youtube/vitess/client/VitessException.java b/java/client/src/main/java/com/youtube/vitess/client/VitessException.java new file mode 100644 index 0000000000..0349f9cfee --- /dev/null +++ b/java/client/src/main/java/com/youtube/vitess/client/VitessException.java @@ -0,0 +1,23 @@ +package com.youtube.vitess.client; + +/** + * VitessException indicates an error returned by VTGate. + */ +public class VitessException extends Exception { + + public VitessException() { + super(); + } + + public VitessException(String message) { + super(message); + } + + public VitessException(String message, Throwable cause) { + super(message, cause); + } + + public VitessException(Throwable cause) { + super(cause); + } +} diff --git a/java/client/src/main/java/com/youtube/vitess/client/VitessRpcException.java b/java/client/src/main/java/com/youtube/vitess/client/VitessRpcException.java index e862e9603d..fc3f6726ed 100644 --- a/java/client/src/main/java/com/youtube/vitess/client/VitessRpcException.java +++ b/java/client/src/main/java/com/youtube/vitess/client/VitessRpcException.java @@ -1,7 +1,7 @@ package com.youtube.vitess.client; /** - * VitessRpcException indicates a rpc error between client and VTGate. + * VitessRpcException indicates an RPC error while trying to communicate with VTGate. */ public class VitessRpcException extends Exception {