From cf2ce9f0cdae1773a3af71df27ba506542898fed Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 2 Jun 2017 11:16:19 +0200 Subject: [PATCH] DATACASS-446 - Resolve package cycles. * Resolve cycle between o.s.d.c.cql.core and o.s.d.c.cql.support via CassandraAccessor. * Resolve cycle between o.s.d.c.cql.core.support and o.s.d.c.cql.support via CQLExceptionTranslator. * Resolve cycle between o.s.d.c.cql.config and o.s.d.c.cql.core.keyspace via KeyspaceAttributes/DataCenterReplication. --- .../core/AsyncCassandraTemplate.java | 4 +- .../config/xml/CassandraCqlClusterParser.java | 2 +- .../data/cql/core/AsyncCqlTemplate.java | 3 +- .../data/cql/core/CqlTemplate.java | 3 +- .../data/cql/core/CqlTemplateSupport.java | 148 ++++++++++++++++++ .../generator/CreateKeyspaceCqlGenerator.java | 2 +- .../keyspace/CreateKeyspaceSpecification.java | 1 - .../keyspace}/DataCenterReplication.java | 6 +- .../keyspace}/KeyspaceAttributes.java | 9 +- .../data/cql/core/support/package-info.java | 4 - .../data/cql/support/CassandraAccessor.java | 145 +---------------- .../support/CassandraExceptionTranslator.java | 3 +- .../CqlExceptionTranslator.java} | 6 +- .../support/ReactiveCassandraAccessor.java | 7 +- ...aceCreatingJavaConfigIntegrationTests.java | 2 +- .../CreateKeyspaceCqlGeneratorUnitTests.java | 2 +- 16 files changed, 174 insertions(+), 173 deletions(-) create mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplateSupport.java rename spring-data-cassandra/src/main/java/org/springframework/data/cql/{config => core/keyspace}/DataCenterReplication.java (92%) rename spring-data-cassandra/src/main/java/org/springframework/data/cql/{config => core/keyspace}/KeyspaceAttributes.java (91%) delete mode 100644 spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/package-info.java rename spring-data-cassandra/src/main/java/org/springframework/data/cql/{core/support/CQLExceptionTranslator.java => support/CqlExceptionTranslator.java} (92%) diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java index 9b1f118e6..ed88e6b58 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java @@ -38,7 +38,7 @@ import org.springframework.data.cql.core.QueryOptions; import org.springframework.data.cql.core.WriteOptions; import org.springframework.data.cql.core.session.DefaultSessionFactory; import org.springframework.data.cql.core.session.SessionFactory; -import org.springframework.data.cql.core.support.CQLExceptionTranslator; +import org.springframework.data.cql.support.CqlExceptionTranslator; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.concurrent.ListenableFuture; @@ -87,7 +87,7 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations { private final CassandraMappingContext mappingContext; - private final CQLExceptionTranslator exceptionTranslator; + private final CqlExceptionTranslator exceptionTranslator; private final StatementFactory statementFactory; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/xml/CassandraCqlClusterParser.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/xml/CassandraCqlClusterParser.java index e69f41ba6..44cb36ccb 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/xml/CassandraCqlClusterParser.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/xml/CassandraCqlClusterParser.java @@ -30,11 +30,11 @@ import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.data.cql.config.CassandraCqlClusterFactoryBean; import org.springframework.data.cql.config.KeyspaceActionSpecificationFactoryBean; -import org.springframework.data.cql.config.KeyspaceAttributes; import org.springframework.data.cql.config.MultiLevelSetFlattenerFactoryBean; import org.springframework.data.cql.config.PoolingOptionsFactoryBean; import org.springframework.data.cql.config.SocketOptionsFactoryBean; import org.springframework.data.cql.core.keyspace.KeyspaceActionSpecification; +import org.springframework.data.cql.core.keyspace.KeyspaceAttributes; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/AsyncCqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/AsyncCqlTemplate.java index d82b1310a..639520045 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/AsyncCqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/AsyncCqlTemplate.java @@ -24,7 +24,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.data.cql.core.session.SessionFactory; -import org.springframework.data.cql.support.CassandraAccessor; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.SettableListenableFuture; @@ -77,7 +76,7 @@ import com.google.common.util.concurrent.Futures; * @see RowMapper * @see org.springframework.dao.support.PersistenceExceptionTranslator */ -public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations { +public class AsyncCqlTemplate extends CqlTemplateSupport implements AsyncCqlOperations { /** * Create a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before using diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplate.java index eda819632..5ca538609 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplate.java @@ -24,7 +24,6 @@ import java.util.function.Function; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; import org.springframework.data.cql.core.session.SessionFactory; -import org.springframework.data.cql.support.CassandraAccessor; import org.springframework.util.Assert; import com.datastax.driver.core.BoundStatement; @@ -77,7 +76,7 @@ import com.datastax.driver.core.exceptions.DriverException; * @see RowMapper * @see org.springframework.dao.support.PersistenceExceptionTranslator */ -public class CqlTemplate extends CassandraAccessor implements CqlOperations { +public class CqlTemplate extends CqlTemplateSupport implements CqlOperations { /** * Create a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using the diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplateSupport.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplateSupport.java new file mode 100644 index 000000000..071703a4d --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplateSupport.java @@ -0,0 +1,148 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://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.cql.core; + +import java.util.Map; +import java.util.Optional; +import java.util.stream.StreamSupport; + +import org.springframework.data.cql.support.CassandraAccessor; + +import com.datastax.driver.core.ResultSet; + +/** + * Support class for CQL template implementation providing utility methods and overridable hook methods. + * + * @author Mark Paluch + * @since 2.0 + */ +public abstract class CqlTemplateSupport extends CassandraAccessor { + + /** + * Create a new arg-based PreparedStatementSetter using the args passed in. By default, we'll create an + * {@link ArgumentPreparedStatementBinder}. This method allows for the creation to be overridden by subclasses. + * + * @param args object array with arguments + * @return the new {@link PreparedStatementBinder} to use + */ + protected PreparedStatementBinder newPreparedStatementBinder(Object[] args) { + return new ArgumentPreparedStatementBinder(args); + } + + /** + * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given + * {@link RowCallbackHandler}. + * + * @param rowCallbackHandler {@link RowCallbackHandler} to adapt as a {@link ResultSetExtractor}. + * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowCallbackHandler}. + * @see org.springframework.data.cql.core.AsyncCqlTemplate.RowCallbackHandlerResultSetExtractor + * @see org.springframework.data.cql.core.ResultSetExtractor + * @see org.springframework.data.cql.core.RowCallbackHandler + */ + protected RowCallbackHandlerResultSetExtractor newResultSetExtractor(RowCallbackHandler rowCallbackHandler) { + return new RowCallbackHandlerResultSetExtractor(rowCallbackHandler); + } + + /** + * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given + * {@link RowMapper}. + * + * @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}. + * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}. + * @see org.springframework.data.cql.core.ResultSetExtractor + * @see org.springframework.data.cql.core.RowMapper + * @see org.springframework.data.cql.core.RowMapperResultSetExtractor + */ + protected RowMapperResultSetExtractor newResultSetExtractor(RowMapper rowMapper) { + return new RowMapperResultSetExtractor<>(rowMapper); + } + + /** + * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given + * {@link RowMapper}. + * + * @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}. + * @param rowsExpected number of expected rows in the {@link ResultSet}. + * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}. + * @see org.springframework.data.cql.core.ResultSetExtractor + * @see org.springframework.data.cql.core.RowMapper + * @see org.springframework.data.cql.core.RowMapperResultSetExtractor + */ + protected RowMapperResultSetExtractor newResultSetExtractor(RowMapper rowMapper, int rowsExpected) { + return new RowMapperResultSetExtractor<>(rowMapper, rowsExpected); + } + + /** + * Create a new RowMapper for reading columns as key-value pairs. + * + * @return the RowMapper to use + * @see ColumnMapRowMapper + */ + protected RowMapper> newColumnMapRowMapper() { + return new ColumnMapRowMapper(); + } + + /** + * Create a new RowMapper for reading result objects from a single column. + * + * @param requiredType the type that each result object is expected to match + * @return the RowMapper to use + * @see SingleColumnRowMapper + */ + protected RowMapper newSingleColumnRowMapper(Class requiredType) { + return SingleColumnRowMapper.newInstance(requiredType); + } + + /** + * Determine CQL from potential provider object. + * + * @param cqlProvider object that's potentially a {@link CqlProvider} + * @return the CQL string, or {@code null} + * @see CqlProvider + */ + protected static String toCql(Object cqlProvider) { + return Optional.ofNullable(cqlProvider) // + .filter(o -> o instanceof CqlProvider) // + .map(o -> (CqlProvider) o) // + .map(CqlProvider::getCql) // + .orElse(null); + } + + /** + * Adapter to enable use of a {@link RowCallbackHandler} inside a {@link ResultSetExtractor}. + */ + protected static class RowCallbackHandlerResultSetExtractor implements ResultSetExtractor { + + private final RowCallbackHandler rowCallbackHandler; + + protected RowCallbackHandlerResultSetExtractor(RowCallbackHandler rowCallbackHandler) { + this.rowCallbackHandler = rowCallbackHandler; + } + + /* (non-Javadoc) + * + @see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet) + */ + @Override + public Object extractData(ResultSet resultSet) { + + StreamSupport.stream(resultSet.spliterator(), false).forEach(rowCallbackHandler::processRow); + + return null; + } + } + +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGenerator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGenerator.java index bdca1a2a6..29e8b3f9c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGenerator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGenerator.java @@ -19,8 +19,8 @@ import static org.springframework.data.cql.core.CqlStringUtils.*; import java.util.Map; -import org.springframework.data.cql.config.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.CreateKeyspaceSpecification; +import org.springframework.data.cql.core.keyspace.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.KeyspaceOption; import org.springframework.data.cql.core.keyspace.Option; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/CreateKeyspaceSpecification.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/CreateKeyspaceSpecification.java index 62578bcc4..70f04a75e 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/CreateKeyspaceSpecification.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/CreateKeyspaceSpecification.java @@ -15,7 +15,6 @@ */ package org.springframework.data.cql.core.keyspace; -import org.springframework.data.cql.config.DataCenterReplication; import org.springframework.data.cql.core.KeyspaceIdentifier; import org.springframework.data.cql.core.keyspace.KeyspaceOption.ReplicationStrategy; import org.springframework.data.cql.core.util.MapBuilder; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/DataCenterReplication.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/DataCenterReplication.java similarity index 92% rename from spring-data-cassandra/src/main/java/org/springframework/data/cql/config/DataCenterReplication.java rename to spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/DataCenterReplication.java index 524a297b9..ba6bbd167 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/DataCenterReplication.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/DataCenterReplication.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2017 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://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, @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cql.config; +package org.springframework.data.cql.core.keyspace; /** * Simple data structure to be used when setting the replication factor for a given data center. diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/KeyspaceAttributes.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/KeyspaceAttributes.java similarity index 91% rename from spring-data-cassandra/src/main/java/org/springframework/data/cql/config/KeyspaceAttributes.java rename to spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/KeyspaceAttributes.java index ddbdd4373..4a3c8235f 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/config/KeyspaceAttributes.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/KeyspaceAttributes.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2017 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://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, @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cql.config; +package org.springframework.data.cql.core.keyspace; import java.util.HashMap; import java.util.Map; -import org.springframework.data.cql.core.keyspace.DefaultOption; -import org.springframework.data.cql.core.keyspace.KeyspaceOption; import org.springframework.data.cql.core.keyspace.KeyspaceOption.ReplicationStrategy; -import org.springframework.data.cql.core.keyspace.Option; import org.springframework.data.cql.core.util.MapBuilder; /** diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/package-info.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/package-info.java deleted file mode 100644 index 195078141..000000000 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * CQL support classes. - */ -package org.springframework.data.cql.core.support; diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraAccessor.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraAccessor.java index 7472188e8..c9761051a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraAccessor.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraAccessor.java @@ -15,31 +15,16 @@ */ package org.springframework.data.cql.support; -import java.util.Map; -import java.util.Optional; -import java.util.stream.StreamSupport; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; -import org.springframework.data.cql.core.ArgumentPreparedStatementBinder; -import org.springframework.data.cql.core.ColumnMapRowMapper; -import org.springframework.data.cql.core.CqlProvider; -import org.springframework.data.cql.core.PreparedStatementBinder; -import org.springframework.data.cql.core.ResultSetExtractor; -import org.springframework.data.cql.core.RowCallbackHandler; -import org.springframework.data.cql.core.RowMapper; -import org.springframework.data.cql.core.RowMapperResultSetExtractor; -import org.springframework.data.cql.core.SingleColumnRowMapper; import org.springframework.data.cql.core.session.DefaultSessionFactory; import org.springframework.data.cql.core.session.SessionFactory; -import org.springframework.data.cql.core.support.CQLExceptionTranslator; import org.springframework.util.Assert; import com.datastax.driver.core.ConsistencyLevel; import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; import com.datastax.driver.core.Statement; import com.datastax.driver.core.exceptions.DriverException; @@ -69,7 +54,7 @@ public class CassandraAccessor implements InitializingBean { /** Logger available to subclasses */ protected final Logger logger = LoggerFactory.getLogger(getClass()); - protected CQLExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator(); + protected CqlExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator(); /** * If this variable is set to a non-negative value, it will be used for setting the {@code fetchSize} property on @@ -123,9 +108,9 @@ public class CassandraAccessor implements InitializingBean { * Exception Hierarchy. * * @param exceptionTranslator exception translator to set; must not be {@literal null}. - * @see CQLExceptionTranslator + * @see CqlExceptionTranslator */ - public void setExceptionTranslator(CQLExceptionTranslator exceptionTranslator) { + public void setExceptionTranslator(CqlExceptionTranslator exceptionTranslator) { Assert.notNull(exceptionTranslator, "CQLExceptionTranslator must not be null"); this.exceptionTranslator = exceptionTranslator; @@ -136,9 +121,9 @@ public class CassandraAccessor implements InitializingBean { * Exception Hierarchy. * * @return the Cassandra exception translator. - * @see CQLExceptionTranslator + * @see CqlExceptionTranslator */ - public CQLExceptionTranslator getExceptionTranslator() { + public CqlExceptionTranslator getExceptionTranslator() { Assert.state(this.exceptionTranslator != null, "CQLExceptionTranslator was not properly initialized"); @@ -295,102 +280,6 @@ public class CassandraAccessor implements InitializingBean { return statement; } - /** - * Create a new arg-based PreparedStatementSetter using the args passed in. By default, we'll create an - * {@link ArgumentPreparedStatementBinder}. This method allows for the creation to be overridden by subclasses. - * - * @param args object array with arguments - * @return the new {@link PreparedStatementBinder} to use - */ - protected PreparedStatementBinder newPreparedStatementBinder(Object[] args) { - return new ArgumentPreparedStatementBinder(args); - } - - /** - * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given - * {@link RowCallbackHandler}. - * - * @param rowCallbackHandler {@link RowCallbackHandler} to adapt as a {@link ResultSetExtractor}. - * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowCallbackHandler}. - * @see org.springframework.data.cql.core.AsyncCqlTemplate.RowCallbackHandlerResultSetExtractor - * @see org.springframework.data.cql.core.ResultSetExtractor - * @see org.springframework.data.cql.core.RowCallbackHandler - */ - protected RowCallbackHandlerResultSetExtractor newResultSetExtractor(RowCallbackHandler rowCallbackHandler) { - return new RowCallbackHandlerResultSetExtractor(rowCallbackHandler); - } - - /** - * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given - * {@link RowMapper}. - * - * @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}. - * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}. - * @see org.springframework.data.cql.core.ResultSetExtractor - * @see org.springframework.data.cql.core.RowMapper - * @see org.springframework.data.cql.core.RowMapperResultSetExtractor - */ - protected RowMapperResultSetExtractor newResultSetExtractor(RowMapper rowMapper) { - return new RowMapperResultSetExtractor<>(rowMapper); - } - - /** - * Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given - * {@link RowMapper}. - * - * @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}. - * @param rowsExpected number of expected rows in the {@link ResultSet}. - * @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}. - * @see org.springframework.data.cql.core.ResultSetExtractor - * @see org.springframework.data.cql.core.RowMapper - * @see org.springframework.data.cql.core.RowMapperResultSetExtractor - */ - protected RowMapperResultSetExtractor newResultSetExtractor(RowMapper rowMapper, int rowsExpected) { - return new RowMapperResultSetExtractor<>(rowMapper, rowsExpected); - } - - /** - * Create a new RowMapper for reading columns as key-value pairs. - * - * @return the RowMapper to use - * @see ColumnMapRowMapper - */ - protected RowMapper> newColumnMapRowMapper() { - return new ColumnMapRowMapper(); - } - - /** - * Create a new RowMapper for reading result objects from a single column. - * - * @param requiredType the type that each result object is expected to match - * @return the RowMapper to use - * @see SingleColumnRowMapper - */ - protected RowMapper newSingleColumnRowMapper(Class requiredType) { - return SingleColumnRowMapper.newInstance(requiredType); - } - - /** - * Determine CQL from potential provider object. - * - * @param cqlProvider object that's potentially a {@link CqlProvider} - * @return the CQL string, or {@code null} - * @see CqlProvider - */ - protected static String toCql(Object cqlProvider) { - return Optional.ofNullable(cqlProvider) // - .filter(o -> o instanceof CqlProvider) // - .map(o -> (CqlProvider) o) // - .map(CqlProvider::getCql) // - .orElse(null); - } - - protected void logDebug(String logMessage, Object... array) { - if (logger.isDebugEnabled()) { - logger.debug(logMessage, array); - } - } - /** * Translate the given {@link DriverException} into a generic {@link DataAccessException}. *

@@ -436,28 +325,4 @@ public class CassandraAccessor implements InitializingBean { return getExceptionTranslator().translate(task, cql, ex); } - - /** - * Adapter to enable use of a {@link RowCallbackHandler} inside a {@link ResultSetExtractor}. - */ - protected static class RowCallbackHandlerResultSetExtractor implements ResultSetExtractor { - - private final RowCallbackHandler rowCallbackHandler; - - protected RowCallbackHandlerResultSetExtractor(RowCallbackHandler rowCallbackHandler) { - this.rowCallbackHandler = rowCallbackHandler; - } - - /* (non-Javadoc) - * - @see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet) - */ - @Override - public Object extractData(ResultSet resultSet) { - - StreamSupport.stream(resultSet.spliterator(), false).forEach(rowCallbackHandler::processRow); - - return null; - } - } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraExceptionTranslator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraExceptionTranslator.java index 694be1376..33ed4e8b8 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraExceptionTranslator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CassandraExceptionTranslator.java @@ -26,7 +26,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.dao.support.PersistenceExceptionTranslator; -import org.springframework.data.cql.core.support.CQLExceptionTranslator; import org.springframework.data.cql.support.exception.*; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -47,7 +46,7 @@ import com.datastax.driver.core.exceptions.*; * @author Mark Paluch */ @SuppressWarnings("unchecked") -public class CassandraExceptionTranslator implements CQLExceptionTranslator { +public class CassandraExceptionTranslator implements CqlExceptionTranslator { private static final Set CONNECTION_FAILURE_TYPES = new HashSet<>( Arrays.asList("NoHostAvailableException", "ConnectionException", "OperationTimedOutException", diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/CQLExceptionTranslator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CqlExceptionTranslator.java similarity index 92% rename from spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/CQLExceptionTranslator.java rename to spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CqlExceptionTranslator.java index cf96981cc..624bcd94e 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/CQLExceptionTranslator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/CqlExceptionTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 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,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.cql.core.support; +package org.springframework.data.cql.support; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; @@ -29,7 +29,7 @@ import com.datastax.driver.core.exceptions.DriverException; * @see 2.0 */ @FunctionalInterface -public interface CQLExceptionTranslator extends PersistenceExceptionTranslator { +public interface CqlExceptionTranslator extends PersistenceExceptionTranslator { /** * Translate the given {@link DriverException} into a generic {@link DataAccessException}. diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/ReactiveCassandraAccessor.java b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/ReactiveCassandraAccessor.java index 698b76016..a6efa2ba6 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/ReactiveCassandraAccessor.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cql/support/ReactiveCassandraAccessor.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.data.cql.core.session.ReactiveSession; import org.springframework.data.cql.core.session.ReactiveSessionFactory; -import org.springframework.data.cql.core.support.CQLExceptionTranslator; import org.springframework.util.Assert; import com.datastax.driver.core.exceptions.DriverException; @@ -43,7 +42,7 @@ public abstract class ReactiveCassandraAccessor implements InitializingBean { /** Logger available to subclasses */ protected final Logger logger = LoggerFactory.getLogger(getClass()); - private CQLExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator(); + private CqlExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator(); private ReactiveSessionFactory sessionFactory; @@ -76,7 +75,7 @@ public abstract class ReactiveCassandraAccessor implements InitializingBean { * @see CassandraExceptionTranslator * @see DataAccessException */ - public void setExceptionTranslator(CQLExceptionTranslator exceptionTranslator) { + public void setExceptionTranslator(CqlExceptionTranslator exceptionTranslator) { Assert.notNull(exceptionTranslator, "CQLExceptionTranslator must not be null"); @@ -89,7 +88,7 @@ public abstract class ReactiveCassandraAccessor implements InitializingBean { * @return the Cassandra exception translator. * @see CassandraExceptionTranslator */ - public CQLExceptionTranslator getExceptionTranslator() { + public CqlExceptionTranslator getExceptionTranslator() { return this.exceptionTranslator; } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cql/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cql/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java index cf5595f2b..d0466fb7f 100755 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cql/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cql/config/java/KeyspaceCreatingJavaConfigIntegrationTests.java @@ -25,8 +25,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.cql.AbstractKeyspaceCreatingIntegrationTest; -import org.springframework.data.cql.config.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.CreateKeyspaceSpecification; +import org.springframework.data.cql.core.keyspace.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.KeyspaceOption; import org.springframework.data.cql.support.AbstractTestJavaConfig; import org.springframework.data.cql.support.KeyspaceTestUtils; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGeneratorUnitTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGeneratorUnitTests.java index 8a5496877..a50c59283 100755 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGeneratorUnitTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGeneratorUnitTests.java @@ -21,9 +21,9 @@ import java.util.HashMap; import java.util.Map; import org.junit.Test; -import org.springframework.data.cql.config.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.CreateKeyspaceSpecification; import org.springframework.data.cql.core.keyspace.DefaultOption; +import org.springframework.data.cql.core.keyspace.KeyspaceAttributes; import org.springframework.data.cql.core.keyspace.KeyspaceOption; import org.springframework.data.cql.core.keyspace.Option; import org.springframework.data.cql.support.RandomKeySpaceName;