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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 2 additions & 1 deletion
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);

0 commit comments

Comments
 (0)