Skip to content

Commit fc8ba1a

Browse files
mp911dechristophstrobl
authored andcommitted
Polishing.
Consistently use InvalidDataAccessApiUsageException to signal that an operation is not allowed/supported in the current mode of operation. Replace converter objects with conversion within the actual method to remove indirections. Original Pull Request: #2287
1 parent ca49139 commit fc8ba1a

30 files changed

+100
-113
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -653,17 +653,17 @@ public boolean isPipelined() {
653653

654654
@Override
655655
public void openPipeline() {
656-
throw new UnsupportedOperationException("Pipeline is currently not supported for JedisClusterConnection.");
656+
throw new InvalidDataAccessApiUsageException("Pipeline is not supported for JedisClusterConnection.");
657657
}
658658

659659
@Override
660660
public List<Object> closePipeline() throws RedisPipelineException {
661-
throw new UnsupportedOperationException("Pipeline is currently not supported for JedisClusterConnection.");
661+
throw new InvalidDataAccessApiUsageException("Pipeline is not supported for JedisClusterConnection.");
662662
}
663663

664664
@Override
665665
public RedisSentinelConnection getSentinelConnection() {
666-
throw new UnsupportedOperationException("Sentinel is currently not supported for JedisClusterConnection.");
666+
throw new InvalidDataAccessApiUsageException("Sentinel is not supported for JedisClusterConnection.");
667667
}
668668

669669
@Override

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public Boolean persist(byte[] key) {
335335

336336
@Override
337337
public Boolean move(byte[] key, int dbIndex) {
338-
throw new UnsupportedOperationException("Cluster mode does not allow moving keys.");
338+
throw new InvalidDataAccessApiUsageException("Cluster mode does not allow moving keys.");
339339
}
340340

341341
@Override

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public void unwatch() {
553553
@Override
554554
public void watch(byte[]... keys) {
555555
if (isQueueing()) {
556-
throw new UnsupportedOperationException();
556+
throw new InvalidDataAccessApiUsageException("WATCH is not supported when a transaction is active");
557557
}
558558
doWithJedis(it -> {
559559

@@ -591,7 +591,7 @@ public void pSubscribe(MessageListener listener, byte[]... patterns) {
591591
}
592592

593593
if (isQueueing() || isPipelined()) {
594-
throw new UnsupportedOperationException();
594+
throw new InvalidDataAccessApiUsageException("Cannot subscribe in pipeline / transaction mode");
595595
}
596596

597597
doWithJedis(it -> {
@@ -612,7 +612,7 @@ public void subscribe(MessageListener listener, byte[]... channels) {
612612
}
613613

614614
if (isQueueing() || isPipelined()) {
615-
throw new UnsupportedOperationException();
615+
throw new InvalidDataAccessApiUsageException("Cannot subscribe in pipeline / transaction mode");
616616
}
617617

618618
doWithJedis(it -> {

src/main/java/org/springframework/data/redis/connection/jedis/JedisInvoker.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import org.springframework.aop.framework.ProxyFactory;
3636
import org.springframework.core.convert.converter.Converter;
37+
import org.springframework.dao.InvalidDataAccessApiUsageException;
3738
import org.springframework.data.redis.connection.convert.Converters;
3839
import org.springframework.lang.Nullable;
3940
import org.springframework.util.Assert;
@@ -82,7 +83,7 @@ <R> R just(ConnectionFunction0<R> function) {
8283
Assert.notNull(function, "ConnectionFunction must not be null!");
8384

8485
return synchronizer.invoke(function::apply, it -> {
85-
throw new UnsupportedOperationException("Operation not supported by Jedis in pipelining/transaction mode");
86+
throw new InvalidDataAccessApiUsageException("Operation not supported by Jedis in pipelining/transaction mode");
8687
}, Converters.identityConverter(), () -> null);
8788
}
8889

@@ -231,7 +232,7 @@ <R> SingleInvocationSpec<R> from(ConnectionFunction0<R> function) {
231232
Assert.notNull(function, "ConnectionFunction must not be null!");
232233

233234
return from(function, connection -> {
234-
throw new UnsupportedOperationException("Operation not supported in pipelining/transaction mode");
235+
throw new InvalidDataAccessApiUsageException("Operation not supported in pipelining/transaction mode");
235236
});
236237
}
237238

@@ -379,7 +380,7 @@ <R extends Collection<E>, E> ManyInvocationSpec<E> fromMany(ConnectionFunction0<
379380
Assert.notNull(function, "ConnectionFunction must not be null!");
380381

381382
return fromMany(function, connection -> {
382-
throw new UnsupportedOperationException("Operation not supported in pipelining/transaction mode");
383+
throw new InvalidDataAccessApiUsageException("Operation not supported in pipelining/transaction mode");
383384
});
384385
}
385386

src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptingCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.List;
2121

22+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2223
import org.springframework.data.redis.connection.RedisScriptingCommands;
2324
import org.springframework.data.redis.connection.ReturnType;
2425
import org.springframework.util.Assert;
@@ -101,7 +102,7 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
101102

102103
private void assertDirectMode() {
103104
if (connection.isQueueing() || connection.isPipelined()) {
104-
throw new UnsupportedOperationException("Scripting commands not supported in pipelining/transaction mode");
105+
throw new InvalidDataAccessApiUsageException("Scripting commands not supported in pipelining/transaction mode");
105106
}
106107
}
107108

src/main/java/org/springframework/data/redis/connection/jedis/JedisStringCommands.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
283283
Assert.notNull(destination, "Destination key must not be null!");
284284

285285
if (op == BitOperation.NOT && keys.length > 1) {
286-
throw new UnsupportedOperationException("Bitop NOT should only be performed against one key");
286+
throw new IllegalArgumentException("Bitop NOT should only be performed against one key");
287287
}
288288

289289
return connection.invoke().just(Jedis::bitop, PipelineBinaryCommands::bitop, JedisConverters.toBitOp(op),

src/main/java/org/springframework/data/redis/connection/lettuce/ClusterConnectionProvider.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Optional;
2727
import java.util.concurrent.CompletableFuture;
2828

29+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2930
import org.springframework.lang.Nullable;
3031
import org.springframework.util.Assert;
3132

@@ -110,7 +111,7 @@ class ClusterConnectionProvider implements LettuceConnectionProvider, RedisClien
110111
}
111112

112113
return LettuceFutureUtils
113-
.failed(new UnsupportedOperationException("Connection type " + connectionType + " not supported!"));
114+
.failed(new InvalidDataAccessApiUsageException("Connection type " + connectionType + " not supported!"));
114115
}
115116

116117
@Override

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Set;
2525
import java.util.concurrent.ThreadLocalRandom;
2626

27+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2728
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
2829
import org.springframework.data.redis.connection.RedisClusterNode;
2930
import org.springframework.data.redis.connection.SortParameters;
@@ -134,7 +135,7 @@ public Boolean renameNX(byte[] sourceKey, byte[] targetKey) {
134135

135136
@Override
136137
public Boolean move(byte[] key, int dbIndex) {
137-
throw new UnsupportedOperationException("MOVE not supported in CLUSTER mode!");
138+
throw new InvalidDataAccessApiUsageException("MOVE not supported in CLUSTER mode!");
138139
}
139140

140141
@Nullable

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public void multi() {
547547
public void select(int dbIndex) {
548548

549549
if (asyncSharedConn != null) {
550-
throw new UnsupportedOperationException("Selecting a new database not supported due to shared connection. "
550+
throw new InvalidDataAccessApiUsageException("Selecting a new database not supported due to shared connection. "
551551
+ "Use separate ConnectionFactorys to work with multiple databases");
552552
}
553553

@@ -578,7 +578,7 @@ public void unwatch() {
578578
@Override
579579
public void watch(byte[]... keys) {
580580
if (isQueueing()) {
581-
throw new UnsupportedOperationException();
581+
throw new InvalidDataAccessApiUsageException("WATCH is not supported when a transaction is active");
582582
}
583583
try {
584584
if (isPipelined()) {
@@ -620,7 +620,8 @@ public void pSubscribe(MessageListener listener, byte[]... patterns) {
620620
checkSubscription();
621621

622622
if (isQueueing() || isPipelined()) {
623-
throw new UnsupportedOperationException("Transaction/Pipelining is not supported for Pub/Sub subscriptions!");
623+
throw new InvalidDataAccessApiUsageException(
624+
"Transaction/Pipelining is not supported for Pub/Sub subscriptions!");
624625
}
625626

626627
try {
@@ -637,7 +638,8 @@ public void subscribe(MessageListener listener, byte[]... channels) {
637638
checkSubscription();
638639

639640
if (isQueueing() || isPipelined()) {
640-
throw new UnsupportedOperationException("Transaction/Pipelining is not supported for Pub/Sub subscriptions!");
641+
throw new InvalidDataAccessApiUsageException(
642+
"Transaction/Pipelining is not supported for Pub/Sub subscriptions!");
641643
}
642644

643645
try {

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceHashCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map.Entry;
2626
import java.util.Set;
2727

28+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2829
import org.springframework.data.redis.connection.RedisHashCommands;
2930
import org.springframework.data.redis.connection.convert.Converters;
3031
import org.springframework.data.redis.core.Cursor;
@@ -223,7 +224,7 @@ public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, long cursorId, ScanOption
223224
protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId, ScanOptions options) {
224225

225226
if (connection.isQueueing() || connection.isPipelined()) {
226-
throw new UnsupportedOperationException("'HSCAN' cannot be called in pipeline / transaction mode.");
227+
throw new InvalidDataAccessApiUsageException("'HSCAN' cannot be called in pipeline / transaction mode.");
227228
}
228229

229230
io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId);

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceKeyCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.concurrent.TimeUnit;
3030

31+
import org.springframework.dao.InvalidDataAccessApiUsageException;
3132
import org.springframework.data.redis.connection.DataType;
3233
import org.springframework.data.redis.connection.RedisKeyCommands;
3334
import org.springframework.data.redis.connection.SortParameters;
@@ -149,7 +150,7 @@ private Cursor<byte[]> doScan(ScanOptions options) {
149150
protected LettuceScanIteration<byte[]> doScan(ScanCursor cursor, ScanOptions options) {
150151

151152
if (connection.isQueueing() || connection.isPipelined()) {
152-
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
153+
throw new InvalidDataAccessApiUsageException("'SCAN' cannot be called in pipeline / transaction mode.");
153154
}
154155

155156
ScanArgs scanArgs = LettuceConverters.toScanArgs(options);

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommands.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525

2626
import org.reactivestreams.Publisher;
27+
28+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2729
import org.springframework.data.redis.RedisSystemException;
2830
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
2931
import org.springframework.data.redis.connection.ReactiveClusterKeyCommands;
@@ -122,6 +124,6 @@ public Flux<BooleanResponse<RenameCommand>> renameNX(Publisher<RenameCommand> co
122124

123125
@Override
124126
public Flux<BooleanResponse<MoveCommand>> move(Publisher<MoveCommand> commands) {
125-
throw new UnsupportedOperationException("MOVE not supported in CLUSTER mode!");
127+
throw new InvalidDataAccessApiUsageException("MOVE not supported in CLUSTER mode!");
126128
}
127129
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceScriptingCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222

2323
import org.springframework.core.convert.converter.Converter;
24+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2425
import org.springframework.data.redis.connection.RedisScriptingCommands;
2526
import org.springframework.data.redis.connection.ReturnType;
2627
import org.springframework.util.Assert;
@@ -46,7 +47,7 @@ public void scriptFlush() {
4647
public void scriptKill() {
4748

4849
if (connection.isQueueing()) {
49-
throw new UnsupportedOperationException("Script kill not permitted in a transaction");
50+
throw new InvalidDataAccessApiUsageException("Script kill not permitted in a transaction");
5051
}
5152

5253
connection.invoke().just(RedisScriptingAsyncCommands::scriptKill);

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.CompletableFuture;
2727
import java.util.concurrent.TimeUnit;
2828

29+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2930
import org.springframework.data.redis.connection.RedisNode;
3031
import org.springframework.data.redis.connection.RedisServerCommands;
3132
import org.springframework.data.redis.core.types.RedisClientInfo;
@@ -192,11 +193,6 @@ public String getClientName() {
192193

193194
@Override
194195
public List<RedisClientInfo> getClientList() {
195-
196-
if (connection.isPipelined()) {
197-
throw new UnsupportedOperationException("Cannot be called in pipeline mode.");
198-
}
199-
200196
return connection.invoke().from(RedisServerAsyncCommands::clientList)
201197
.get(LettuceConverters.stringToRedisClientListConverter());
202198
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSetCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2728
import org.springframework.data.redis.connection.RedisSetCommands;
2829
import org.springframework.data.redis.core.Cursor;
2930
import org.springframework.data.redis.core.KeyBoundCursor;
@@ -220,7 +221,7 @@ public Cursor<byte[]> sScan(byte[] key, long cursorId, ScanOptions options) {
220221
protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions options) {
221222

222223
if (connection.isQueueing() || connection.isPipelined()) {
223-
throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode.");
224+
throw new InvalidDataAccessApiUsageException("'SSCAN' cannot be called in pipeline / transaction mode.");
224225
}
225226

226227
io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId);

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceStringCommands.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.springframework.dao.InvalidDataAccessApiUsageException;
2425
import org.springframework.data.domain.Range;
2526
import org.springframework.data.redis.connection.BitFieldSubCommands;
2627
import org.springframework.data.redis.connection.RedisStringCommands;
@@ -275,7 +276,7 @@ public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
275276
Assert.notNull(destination, "Destination key must not be null!");
276277

277278
if (op == BitOperation.NOT && keys.length > 1) {
278-
throw new UnsupportedOperationException("Bitop NOT should only be performed against one key");
279+
throw new IllegalArgumentException("Bitop NOT should only be performed against one key");
279280
}
280281

281282
return connection.invoke().just(it -> {
@@ -289,7 +290,7 @@ public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
289290
return it.bitopXor(destination, keys);
290291
case NOT:
291292
if (keys.length != 1) {
292-
throw new UnsupportedOperationException("Bitop NOT should only be performed against one key");
293+
throw new IllegalArgumentException("Bitop NOT should only be performed against one key");
293294
}
294295
return it.bitopNot(destination, keys[0]);
295296
default:

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Set;
2828
import java.util.concurrent.TimeUnit;
2929

30+
import org.springframework.dao.InvalidDataAccessApiUsageException;
3031
import org.springframework.data.redis.connection.RedisZSetCommands;
3132
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs.Flag;
3233
import org.springframework.data.redis.connection.convert.Converters;
@@ -546,7 +547,7 @@ public Cursor<Tuple> zScan(byte[] key, long cursorId, ScanOptions options) {
546547
protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions options) {
547548

548549
if (connection.isQueueing() || connection.isPipelined()) {
549-
throw new UnsupportedOperationException("'ZSCAN' cannot be called in pipeline / transaction mode.");
550+
throw new InvalidDataAccessApiUsageException("'ZSCAN' cannot be called in pipeline / transaction mode.");
550551
}
551552

552553
io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId);

src/main/java/org/springframework/data/redis/connection/lettuce/StaticMasterReplicaConnectionProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.CompletableFuture;
3030
import java.util.concurrent.CompletionStage;
3131

32+
import org.springframework.dao.InvalidDataAccessApiUsageException;
3233
import org.springframework.lang.Nullable;
3334

3435
/**

0 commit comments

Comments
 (0)