Prepare for removal of ListenableFuture.
Suppress warnings for using deprecated-for-removal code. Closes #1530
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.FailureCallback;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
import org.springframework.util.concurrent.SuccessCallback;
|
||||
|
||||
/**
|
||||
* Adapter class to {@link ListenableFuture} {@link ExecutionException} by applying a
|
||||
* {@link PersistenceExceptionTranslator}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
|
||||
private final ListenableFuture<T> adaptee;
|
||||
|
||||
private final ListenableFuture<T> future;
|
||||
|
||||
/**
|
||||
* Create a new {@link ExceptionTranslatingListenableFutureAdapter} given a {@link ListenableFuture} and a
|
||||
* {@link PersistenceExceptionTranslator}.
|
||||
*
|
||||
* @param adaptee must not be {@literal null}.
|
||||
* @param persistenceExceptionTranslator must not be {@literal null}.
|
||||
*/
|
||||
ExceptionTranslatingListenableFutureAdapter(ListenableFuture<T> adaptee,
|
||||
PersistenceExceptionTranslator persistenceExceptionTranslator) {
|
||||
|
||||
Assert.notNull(adaptee, "ListenableFuture must not be null");
|
||||
Assert.notNull(persistenceExceptionTranslator, "PersistenceExceptionTranslator must not be null");
|
||||
|
||||
this.adaptee = adaptee;
|
||||
this.future = adaptListenableFuture(adaptee, persistenceExceptionTranslator);
|
||||
}
|
||||
|
||||
private static <T> ListenableFuture<T> adaptListenableFuture(ListenableFuture<T> listenableFuture,
|
||||
PersistenceExceptionTranslator exceptionTranslator) {
|
||||
|
||||
SettableListenableFuture<T> settableFuture = new SettableListenableFuture<>();
|
||||
|
||||
listenableFuture.addCallback(new ListenableFutureCallback<T>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(@Nullable T result) {
|
||||
settableFuture.set(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
if (ex instanceof RuntimeException) {
|
||||
DataAccessException dataAccessException = exceptionTranslator
|
||||
.translateExceptionIfPossible((RuntimeException) ex);
|
||||
|
||||
if (dataAccessException != null) {
|
||||
settableFuture.setException(dataAccessException);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
settableFuture.setException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
return settableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
||||
future.addCallback(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) {
|
||||
future.addCallback(successCallback, failureCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return adaptee.cancel(mayInterruptIfRunning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return adaptee.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return future.isDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() throws InterruptedException, ExecutionException {
|
||||
return future.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return future.get(timeout, unit);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
* {@link org.springframework.data.cassandra.core.cql.AsyncCqlOperations}.
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public interface AsyncCqlOperations {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -89,6 +89,7 @@ import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
* {@link org.springframework.data.cassandra.core.cql.AsyncCqlTemplate}.
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations {
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.datastax.oss.driver.api.core.cql.PreparedStatement;
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@FunctionalInterface
|
||||
@SuppressWarnings("removal")
|
||||
public interface AsyncPreparedStatementCreator {
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@FunctionalInterface
|
||||
@SuppressWarnings("removal")
|
||||
public interface AsyncResultSetExtractor<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.datastax.oss.driver.api.core.cql.Row;
|
||||
* @since 4.0
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncResultStream<T> {
|
||||
|
||||
private final AsyncResultSet resultSet;
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
|
||||
* @deprecated since 4.0, use the {@link java.util.concurrent.CompletableFuture}-based variant.
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public class AsyncRowMapperResultSetExtractor<T> implements AsyncResultSetExtractor<List<T>> {
|
||||
|
||||
private final RowMapper<T> rowMapper;
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.datastax.oss.driver.api.core.DriverException;
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@FunctionalInterface
|
||||
@SuppressWarnings("removal")
|
||||
public interface AsyncSessionCallback<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.util.concurrent.SuccessCallback;
|
||||
* @since 4.0
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
|
||||
private final ListenableFuture<T> adaptee;
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
* {@link org.springframework.data.cassandra.core.AsyncCassandraTemplate}.
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public interface AsyncCassandraOperations {
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,7 @@ import com.datastax.oss.driver.api.querybuilder.update.Update;
|
||||
* {@link org.springframework.data.cassandra.core.AsyncCassandraTemplate}.
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public class AsyncCassandraTemplate
|
||||
implements AsyncCassandraOperations, ApplicationEventPublisherAware, ApplicationContextAware {
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import com.datastax.oss.driver.api.querybuilder.update.Update;
|
||||
* @since 4.0
|
||||
*/
|
||||
@Deprecated(since = "4.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
class EntityOperations {
|
||||
|
||||
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncCqlTemplateIntegrationTests extends AbstractKeyspaceCreatingIntegrationTests {
|
||||
|
||||
private static final AtomicBoolean initialized = new AtomicBoolean();
|
||||
|
||||
@@ -64,6 +64,7 @@ import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncCqlTemplateUnitTests {
|
||||
|
||||
@Mock CqlSession session;
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.datastax.oss.driver.api.core.cql.Row;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncResultStreamUnitTests {
|
||||
|
||||
private AsyncResultSet first = mock(AsyncResultSet.class);
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingIntegrationTests {
|
||||
|
||||
private AsyncCassandraTemplate template;
|
||||
|
||||
@@ -70,6 +70,7 @@ import com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecReg
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@SuppressWarnings("removal")
|
||||
class AsyncCassandraTemplateUnitTests {
|
||||
|
||||
@Mock CqlSession session;
|
||||
|
||||
Reference in New Issue
Block a user