DATACASS-330 - Polishing.

Move Reactive Session support to session package. Reorder fields according their visibility.
This commit is contained in:
Mark Paluch
2017-01-18 18:15:14 +01:00
committed by John Blum
parent 22e6e9ae9f
commit 4df8fd1fce
31 changed files with 117 additions and 79 deletions

View File

@@ -80,8 +80,8 @@ import com.google.common.util.concurrent.Futures;
public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations {
/**
* Constructs a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link Session} has to be set before using the
* instance.
* Constructs a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before
* using the instance.
*
* @see #setSessionFactory(SessionFactory)
*/

View File

@@ -80,8 +80,8 @@ import com.datastax.driver.core.exceptions.DriverException;
public class CqlTemplate extends CassandraAccessor implements CqlOperations {
/**
* Constructs a new, uninitialized {@link CqlTemplate}. Note: The {@link Session} has to be set before using the
* instance.
* Constructs a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using
* the instance.
*
* @see #setSessionFactory(SessionFactory)
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -18,6 +18,7 @@ package org.springframework.cassandra.core;
import java.util.Map;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;

View File

@@ -22,6 +22,10 @@ import java.util.Map;
import java.util.function.Function;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
import org.springframework.cassandra.support.ReactiveCassandraAccessor;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.DataAccessUtils;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.cassandra.core;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.dao.DataAccessException;
import com.datastax.driver.core.PreparedStatement;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -15,11 +15,13 @@
*/
package org.springframework.cassandra.core;
import reactor.core.publisher.Mono;
import org.springframework.cassandra.core.session.ReactiveSession;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.exceptions.DriverException;
import reactor.core.publisher.Mono;
/**
* One of the two central callback interfaces used by the {@link ReactiveCqlTemplate} class. This interface creates a
* {@link PreparedStatement} given a {@link ReactiveSession}, provided by the {@link ReactiveCqlTemplate} class.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.cassandra.core;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.dao.DataAccessException;
import com.datastax.driver.core.exceptions.DriverException;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -15,14 +15,15 @@
*/
package org.springframework.cassandra.core;
import reactor.core.publisher.Mono;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import com.datastax.driver.core.exceptions.DriverException;
import reactor.core.publisher.Mono;
/**
* Adapter implementation of the {@link ReactiveResultSetExtractor} interface that delegates to a {@link RowMapper}
* which is supposed to create an object for each row. Each object is emitted through the {@link Publisher} of this

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.cassandra.core;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.dao.DataAccessException;
import com.datastax.driver.core.Statement;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.cassandra.core;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.dao.DataAccessException;
import com.datastax.driver.core.Statement;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 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.
@@ -13,7 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.core;
package org.springframework.cassandra.core.session;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 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.
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.core;
package org.springframework.cassandra.core.session;
import org.springframework.cassandra.core.ReactiveRowMapperResultSetExtractor;
/**
* Default implementation of {@link ReactiveSessionFactory}.

View File

@@ -45,6 +45,9 @@ public class DefaultSessionFactory implements SessionFactory {
this.session = session;
}
/* (non-Javadoc)
* @see org.springframework.cassandra.core.session.SessionFactory#getSession()
*/
@Override
public Session getSession() {
return session;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 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.
@@ -13,24 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.core;
package org.springframework.cassandra.core.session;
import reactor.core.publisher.Flux;
import java.util.List;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ExecutionInfo;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Statement;
import reactor.core.publisher.Flux;
/**
* The reactive result of a query.
* <p>
* The retrieval of the rows of a {@link ReactiveResultSet} is generally paged (a first page of result is fetched and
* the next one is only fetched once all the results of the first one has been consumed). The size of the pages can be
* configured either globally through {@link QueryOptions#setFetchSize} or per-statement with
* {@link Statement#setFetchSize}.
* configured either globally through {@link com.datastax.driver.core.QueryOptions#setFetchSize} or per-statement with
* {@link com.datastax.driver.core.Statement#setFetchSize}.
* <p>
* Please note however that this {@link ReactiveResultSet} paging is not available with the version 1 of the native
* protocol (i.e. with Cassandra 1.2 or if version 1 has been explicitly requested through

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 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.
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.core;
package org.springframework.cassandra.core.session;
import reactor.core.publisher.Mono;
import java.io.Closeable;
import java.util.Map;
@@ -27,8 +29,6 @@ import com.datastax.driver.core.exceptions.QueryExecutionException;
import com.datastax.driver.core.exceptions.QueryValidationException;
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
import reactor.core.publisher.Mono;
/**
* A session holds connections to a Cassandra cluster, allowing it to be queried. {@link ReactiveSession} executes
* queries and prepares statements in a reactive style returning results wrapped in {@link Mono} and

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2017 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.
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.core;
package org.springframework.cassandra.core.session;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
/**
* Strategy interface to produce {@link ReactiveSession} instances.

View File

@@ -1,5 +1,5 @@
/**
* Provides utility classes for simple {@link com.datastax.driver.core.Session} access and various simple DataSource
* Provides utility classes for simple {@link com.datastax.driver.core.Session} access and various session
* implementations.
*
* @author Mark Paluch

View File

@@ -64,22 +64,23 @@ public class CassandraAccessor implements InitializingBean {
*/
private final static Statement DEFAULTS = QueryBuilder.select().from("DEFAULT");
/** Logger available to subclasses */
protected final Logger logger = LoggerFactory.getLogger(getClass());
protected CassandraExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
/**
* If this variable is set to a non-negative value, it will be used for setting the {@code fetchSize} property on
* statements used for query processing.
*/
private int fetchSize = -1;
protected CassandraExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
/**
* If this variable is set to a value, it will be used for setting the {@code consistencyLevel} property on statements
* used for query processing.
*/
private com.datastax.driver.core.ConsistencyLevel consistencyLevel;
protected final Logger logger = LoggerFactory.getLogger(getClass());
/**
* If this variable is set to a value, it will be used for setting the {@code retryPolicy} property on statements used
* for query processing.
@@ -438,8 +439,8 @@ public class CassandraAccessor implements InitializingBean {
this.rowCallbackHandler = rowCallbackHandler;
}
/**
* @inheritDoc
/* (non-Javadoc)
* @see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet)
*/
@Override
public Object extractData(ResultSet resultSet) {

View File

@@ -18,7 +18,8 @@ package org.springframework.cassandra.support;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cassandra.core.ReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
import org.springframework.cassandra.core.support.CQLExceptionTranslator;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
@@ -27,15 +28,14 @@ import com.datastax.driver.core.exceptions.DriverException;
/**
* Base class for {@link org.springframework.cassandra.core.ReactiveCqlTemplate} and other CQL-accessing DAO helpers,
* defining common properties such as {@link org.springframework.cassandra.core.ReactiveSessionFactory} and exception
* translator.
* defining common properties such as {@link ReactiveSessionFactory} and exception translator.
* <p>
* Not intended to be used directly.
*
* @author Mark Paluch
* @since 2.0
* @see InitializingBean
* @see org.springframework.cassandra.core.ReactiveSession
* @see ReactiveSession
* @see org.springframework.cassandra.core.ReactiveCqlTemplate
*/
public abstract class ReactiveCassandraAccessor implements InitializingBean {

View File

@@ -22,6 +22,8 @@ import reactor.core.scheduler.Schedulers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.KeyspaceMetadata;

View File

@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

View File

@@ -24,6 +24,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import com.datastax.driver.core.querybuilder.QueryBuilder;

View File

@@ -31,6 +31,10 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;

View File

@@ -15,19 +15,19 @@
*/
package org.springframework.data.cassandra.config.java;
import org.springframework.cassandra.core.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.DefaultReactiveSessionFactory;
import reactor.core.scheduler.Schedulers;
import org.springframework.cassandra.core.ReactiveCqlOperations;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
import org.springframework.cassandra.core.ReactiveSession;
import org.springframework.cassandra.core.ReactiveSessionFactory;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.data.cassandra.core.CassandraAdminTemplate;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import reactor.core.scheduler.Schedulers;
/**
* Extension to {@link AbstractCassandraConfiguration} providing Spring Data Cassandra configuration for Spring Data's
* Reactive Cassandra support using JavaConfig.

View File

@@ -40,7 +40,7 @@ import com.datastax.driver.core.Statement;
public interface AsyncCassandraOperations {
/**
* Expose the underlying {@link AsyncCqlOperationsOperations} to allow asynchronous CQL operations.
* Expose the underlying {@link AsyncCqlOperations} to allow asynchronous CQL operations.
*
* @return the underlying {@link AsyncCqlOperations}.
* @see AsyncCqlOperations

View File

@@ -69,7 +69,9 @@ import com.datastax.driver.core.querybuilder.Update;
public class CassandraTemplate implements CassandraOperations {
private final CassandraConverter converter;
private final CassandraMappingContext mappingContext;
private final CqlOperations cqlOperations;
/**

View File

@@ -15,6 +15,30 @@
*/
package org.springframework.data.cassandra.core;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.CqlProvider;
import org.springframework.cassandra.core.QueryOptions;
import org.springframework.cassandra.core.ReactiveCqlOperations;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
import org.springframework.cassandra.core.ReactiveSessionCallback;
import org.springframework.cassandra.core.WriteOptions;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.cassandra.core.session.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
@@ -26,30 +50,6 @@ import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.querybuilder.Truncate;
import com.datastax.driver.core.querybuilder.Update;
import org.reactivestreams.Publisher;
import org.springframework.cassandra.core.CqlProvider;
import org.springframework.cassandra.core.DefaultReactiveSessionFactory;
import org.springframework.cassandra.core.QueryOptions;
import org.springframework.cassandra.core.ReactiveCqlOperations;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
import org.springframework.cassandra.core.ReactiveResultSet;
import org.springframework.cassandra.core.ReactiveSession;
import org.springframework.cassandra.core.ReactiveSessionCallback;
import org.springframework.cassandra.core.ReactiveSessionFactory;
import org.springframework.cassandra.core.WriteOptions;
import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* Primary implementation of {@link ReactiveCassandraOperations}. It simplifies the use of Reactive Cassandra usage and
* helps to avoid common errors. It executes core Cassandra workflow. This class executes CQL queries or updates,
@@ -68,7 +68,9 @@ import reactor.core.publisher.Mono;
public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
private final CassandraConverter converter;
private final CassandraMappingContext mappingContext;
private final ReactiveCqlOperations cqlOperations;
/**

View File

@@ -22,8 +22,8 @@ import reactor.core.scheduler.Schedulers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.core.DefaultBridgedReactiveSession;
import org.springframework.cassandra.core.ReactiveCqlTemplate;
import org.springframework.cassandra.core.session.DefaultBridgedReactiveSession;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.domain.Person;

View File

@@ -33,8 +33,8 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.core.ReactiveResultSet;
import org.springframework.cassandra.core.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveResultSet;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
import org.springframework.data.cassandra.domain.Person;

View File

@@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.ReactiveSession;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter;

View File

@@ -26,8 +26,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cassandra.core.ReactiveCqlOperations;
import org.springframework.cassandra.core.ReactiveSession;
import org.springframework.cassandra.core.ReactiveSessionCallback;
import org.springframework.cassandra.core.session.ReactiveSession;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;