Skip to content

Commit f961984

Browse files
committed
Redis Cluster: wrapSql - add suppressed exception from JedisException as cause in the new SQLException
1 parent 0e3377f commit f961984

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

driver/src/main/java/jdbc/client/impl/RedisClientBase.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final RedisResult execute(String sql) throws SQLException {
2424
Object data = execute(query);
2525
return RedisResultHelper.parseResult(query, data);
2626
} catch (JedisException e) {
27-
throw new SQLException(e);
27+
throw sqlWrap(e);
2828
}
2929
}
3030

@@ -51,7 +51,7 @@ public final void setDatabase(String db) throws SQLException {
5151
try {
5252
setDatabase(parseSqlDbIndex(db));
5353
} catch (JedisException e) {
54-
throw new SQLException(e);
54+
throw sqlWrap(e);
5555
}
5656
}
5757

@@ -63,13 +63,24 @@ public final void close() throws SQLException {
6363
try {
6464
doClose();
6565
} catch (JedisException e) {
66-
throw new SQLException(e);
66+
throw sqlWrap(e);
6767
}
6868
}
6969

7070
protected abstract void doClose();
7171

7272

73+
protected static SQLException sqlWrap(@NotNull JedisException e) {
74+
if (e.getCause() == null) {
75+
Throwable[] suppressed = e.getSuppressed();
76+
if (suppressed != null && suppressed.length == 1) {
77+
return new SQLException(e.getMessage(), suppressed[0]);
78+
}
79+
}
80+
return new SQLException(e);
81+
}
82+
83+
7384
protected static class SingleConnectionPoolConfig extends ConnectionPoolConfig {
7485
public SingleConnectionPoolConfig() {
7586
super();

driver/src/main/java/jdbc/client/impl/cluster/RedisJedisClusterClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public RedisJedisClusterClient(@NotNull RedisJedisClusterURI uri) throws SQLExce
3030
try {
3131
jedisCluster = new JedisCluster(uri.getNodes(), uri, uri.getMaxAttempts(), new SingleConnectionPoolConfig());
3232
} catch (JedisException e) {
33-
throw new SQLException(e);
33+
throw sqlWrap(e);
3434
}
3535
}
3636

driver/src/main/java/jdbc/client/impl/standalone/RedisJedisClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public RedisJedisClient(@NotNull RedisJedisURI uri) throws SQLException {
2020
jedis = new Jedis(uri.getHostAndPort(), uri);
2121
jedis.connect();
2222
} catch (JedisException e) {
23-
throw new SQLException(e);
23+
throw sqlWrap(e);
2424
}
2525
}
2626

2727
public RedisJedisClient(@NotNull Connection connection) throws SQLException {
2828
try {
2929
jedis = new Jedis(connection);
3030
} catch (JedisException e) {
31-
throw new SQLException(e);
31+
throw sqlWrap(e);
3232
}
3333
}
3434

0 commit comments

Comments
 (0)