Skip to content

Commit cf2ce9f

Browse files
committed
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.
1 parent caf4160 commit cf2ce9f

File tree

16 files changed

+174
-173
lines changed

16 files changed

+174
-173
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/AsyncCassandraTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.springframework.data.cql.core.WriteOptions;
3939
import org.springframework.data.cql.core.session.DefaultSessionFactory;
4040
import org.springframework.data.cql.core.session.SessionFactory;
41-
import org.springframework.data.cql.core.support.CQLExceptionTranslator;
41+
import org.springframework.data.cql.support.CqlExceptionTranslator;
4242
import org.springframework.util.Assert;
4343
import org.springframework.util.ClassUtils;
4444
import org.springframework.util.concurrent.ListenableFuture;
@@ -87,7 +87,7 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
8787

8888
private final CassandraMappingContext mappingContext;
8989

90-
private final CQLExceptionTranslator exceptionTranslator;
90+
private final CqlExceptionTranslator exceptionTranslator;
9191

9292
private final StatementFactory statementFactory;
9393

spring-data-cassandra/src/main/java/org/springframework/data/cql/config/xml/CassandraCqlClusterParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import org.springframework.beans.factory.xml.ParserContext;
3131
import org.springframework.data.cql.config.CassandraCqlClusterFactoryBean;
3232
import org.springframework.data.cql.config.KeyspaceActionSpecificationFactoryBean;
33-
import org.springframework.data.cql.config.KeyspaceAttributes;
3433
import org.springframework.data.cql.config.MultiLevelSetFlattenerFactoryBean;
3534
import org.springframework.data.cql.config.PoolingOptionsFactoryBean;
3635
import org.springframework.data.cql.config.SocketOptionsFactoryBean;
3736
import org.springframework.data.cql.core.keyspace.KeyspaceActionSpecification;
37+
import org.springframework.data.cql.core.keyspace.KeyspaceAttributes;
3838
import org.springframework.util.StringUtils;
3939
import org.springframework.util.xml.DomUtils;
4040
import org.w3c.dom.Element;

spring-data-cassandra/src/main/java/org/springframework/data/cql/core/AsyncCqlTemplate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.dao.support.DataAccessUtils;
2525
import org.springframework.dao.support.PersistenceExceptionTranslator;
2626
import org.springframework.data.cql.core.session.SessionFactory;
27-
import org.springframework.data.cql.support.CassandraAccessor;
2827
import org.springframework.util.Assert;
2928
import org.springframework.util.concurrent.ListenableFuture;
3029
import org.springframework.util.concurrent.SettableListenableFuture;
@@ -77,7 +76,7 @@
7776
* @see RowMapper
7877
* @see org.springframework.dao.support.PersistenceExceptionTranslator
7978
*/
80-
public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations {
79+
public class AsyncCqlTemplate extends CqlTemplateSupport implements AsyncCqlOperations {
8180

8281
/**
8382
* Create a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before using

spring-data-cassandra/src/main/java/org/springframework/data/cql/core/CqlTemplate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.dao.DataAccessException;
2525
import org.springframework.dao.support.DataAccessUtils;
2626
import org.springframework.data.cql.core.session.SessionFactory;
27-
import org.springframework.data.cql.support.CassandraAccessor;
2827
import org.springframework.util.Assert;
2928

3029
import com.datastax.driver.core.BoundStatement;
@@ -77,7 +76,7 @@
7776
* @see RowMapper
7877
* @see org.springframework.dao.support.PersistenceExceptionTranslator
7978
*/
80-
public class CqlTemplate extends CassandraAccessor implements CqlOperations {
79+
public class CqlTemplate extends CqlTemplateSupport implements CqlOperations {
8180

8281
/**
8382
* Create a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using the
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.cql.core;
17+
18+
import java.util.Map;
19+
import java.util.Optional;
20+
import java.util.stream.StreamSupport;
21+
22+
import org.springframework.data.cql.support.CassandraAccessor;
23+
24+
import com.datastax.driver.core.ResultSet;
25+
26+
/**
27+
* Support class for CQL template implementation providing utility methods and overridable hook methods.
28+
*
29+
* @author Mark Paluch
30+
* @since 2.0
31+
*/
32+
public abstract class CqlTemplateSupport extends CassandraAccessor {
33+
34+
/**
35+
* Create a new arg-based PreparedStatementSetter using the args passed in. By default, we'll create an
36+
* {@link ArgumentPreparedStatementBinder}. This method allows for the creation to be overridden by subclasses.
37+
*
38+
* @param args object array with arguments
39+
* @return the new {@link PreparedStatementBinder} to use
40+
*/
41+
protected PreparedStatementBinder newPreparedStatementBinder(Object[] args) {
42+
return new ArgumentPreparedStatementBinder(args);
43+
}
44+
45+
/**
46+
* Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given
47+
* {@link RowCallbackHandler}.
48+
*
49+
* @param rowCallbackHandler {@link RowCallbackHandler} to adapt as a {@link ResultSetExtractor}.
50+
* @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowCallbackHandler}.
51+
* @see org.springframework.data.cql.core.AsyncCqlTemplate.RowCallbackHandlerResultSetExtractor
52+
* @see org.springframework.data.cql.core.ResultSetExtractor
53+
* @see org.springframework.data.cql.core.RowCallbackHandler
54+
*/
55+
protected RowCallbackHandlerResultSetExtractor newResultSetExtractor(RowCallbackHandler rowCallbackHandler) {
56+
return new RowCallbackHandlerResultSetExtractor(rowCallbackHandler);
57+
}
58+
59+
/**
60+
* Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given
61+
* {@link RowMapper}.
62+
*
63+
* @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}.
64+
* @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}.
65+
* @see org.springframework.data.cql.core.ResultSetExtractor
66+
* @see org.springframework.data.cql.core.RowMapper
67+
* @see org.springframework.data.cql.core.RowMapperResultSetExtractor
68+
*/
69+
protected <T> RowMapperResultSetExtractor<T> newResultSetExtractor(RowMapper<T> rowMapper) {
70+
return new RowMapperResultSetExtractor<>(rowMapper);
71+
}
72+
73+
/**
74+
* Constructs a new instance of the {@link ResultSetExtractor} initialized with and adapting the given
75+
* {@link RowMapper}.
76+
*
77+
* @param rowMapper {@link RowMapper} to adapt as a {@link ResultSetExtractor}.
78+
* @param rowsExpected number of expected rows in the {@link ResultSet}.
79+
* @return a {@link ResultSetExtractor} implementation adapting an instance of the {@link RowMapper}.
80+
* @see org.springframework.data.cql.core.ResultSetExtractor
81+
* @see org.springframework.data.cql.core.RowMapper
82+
* @see org.springframework.data.cql.core.RowMapperResultSetExtractor
83+
*/
84+
protected <T> RowMapperResultSetExtractor<T> newResultSetExtractor(RowMapper<T> rowMapper, int rowsExpected) {
85+
return new RowMapperResultSetExtractor<>(rowMapper, rowsExpected);
86+
}
87+
88+
/**
89+
* Create a new RowMapper for reading columns as key-value pairs.
90+
*
91+
* @return the RowMapper to use
92+
* @see ColumnMapRowMapper
93+
*/
94+
protected RowMapper<Map<String, Object>> newColumnMapRowMapper() {
95+
return new ColumnMapRowMapper();
96+
}
97+
98+
/**
99+
* Create a new RowMapper for reading result objects from a single column.
100+
*
101+
* @param requiredType the type that each result object is expected to match
102+
* @return the RowMapper to use
103+
* @see SingleColumnRowMapper
104+
*/
105+
protected <T> RowMapper<T> newSingleColumnRowMapper(Class<T> requiredType) {
106+
return SingleColumnRowMapper.newInstance(requiredType);
107+
}
108+
109+
/**
110+
* Determine CQL from potential provider object.
111+
*
112+
* @param cqlProvider object that's potentially a {@link CqlProvider}
113+
* @return the CQL string, or {@code null}
114+
* @see CqlProvider
115+
*/
116+
protected static String toCql(Object cqlProvider) {
117+
return Optional.ofNullable(cqlProvider) //
118+
.filter(o -> o instanceof CqlProvider) //
119+
.map(o -> (CqlProvider) o) //
120+
.map(CqlProvider::getCql) //
121+
.orElse(null);
122+
}
123+
124+
/**
125+
* Adapter to enable use of a {@link RowCallbackHandler} inside a {@link ResultSetExtractor}.
126+
*/
127+
protected static class RowCallbackHandlerResultSetExtractor implements ResultSetExtractor<Object> {
128+
129+
private final RowCallbackHandler rowCallbackHandler;
130+
131+
protected RowCallbackHandlerResultSetExtractor(RowCallbackHandler rowCallbackHandler) {
132+
this.rowCallbackHandler = rowCallbackHandler;
133+
}
134+
135+
/* (non-Javadoc)
136+
*
137+
@see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet)
138+
*/
139+
@Override
140+
public Object extractData(ResultSet resultSet) {
141+
142+
StreamSupport.stream(resultSet.spliterator(), false).forEach(rowCallbackHandler::processRow);
143+
144+
return null;
145+
}
146+
}
147+
148+
}

spring-data-cassandra/src/main/java/org/springframework/data/cql/core/generator/CreateKeyspaceCqlGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import java.util.Map;
2121

22-
import org.springframework.data.cql.config.KeyspaceAttributes;
2322
import org.springframework.data.cql.core.keyspace.CreateKeyspaceSpecification;
23+
import org.springframework.data.cql.core.keyspace.KeyspaceAttributes;
2424
import org.springframework.data.cql.core.keyspace.KeyspaceOption;
2525
import org.springframework.data.cql.core.keyspace.Option;
2626

spring-data-cassandra/src/main/java/org/springframework/data/cql/core/keyspace/CreateKeyspaceSpecification.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.cql.core.keyspace;
1717

18-
import org.springframework.data.cql.config.DataCenterReplication;
1918
import org.springframework.data.cql.core.KeyspaceIdentifier;
2019
import org.springframework.data.cql.core.keyspace.KeyspaceOption.ReplicationStrategy;
2120
import org.springframework.data.cql.core.util.MapBuilder;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
2-
* Copyright 2013-2017 the original author or authors.
2+
* Copyright 2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.cql.config;
16+
package org.springframework.data.cql.core.keyspace;
1717

1818
/**
1919
* Simple data structure to be used when setting the replication factor for a given data center.
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
/*
2-
* Copyright 2013-2017 the original author or authors.
2+
* Copyright 2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.cql.config;
16+
package org.springframework.data.cql.core.keyspace;
1717

1818
import java.util.HashMap;
1919
import java.util.Map;
2020

21-
import org.springframework.data.cql.core.keyspace.DefaultOption;
22-
import org.springframework.data.cql.core.keyspace.KeyspaceOption;
2321
import org.springframework.data.cql.core.keyspace.KeyspaceOption.ReplicationStrategy;
24-
import org.springframework.data.cql.core.keyspace.Option;
2522
import org.springframework.data.cql.core.util.MapBuilder;
2623

2724
/**

spring-data-cassandra/src/main/java/org/springframework/data/cql/core/support/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)