DATACASS-439 - Remove deprecated types and members.

Removal of deprecated and obsolete types and members. Listeners became obsolete by providing AsynCqlTemplate/AsyncCassandraTemplate as async operations return futures that allow synchronization. Other types are not used anymore.
This commit is contained in:
Mark Paluch
2017-04-26 13:45:08 +02:00
parent b5763bc696
commit 69e4ddd3cc
17 changed files with 3 additions and 797 deletions

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2013-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.cassandra.config;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.FactoryBean;
/**
* Given List of Lists where all child Lists contain the same class, then a single level List of <T> is generated.
*
* @author David Webb
* @param <T>
*/
public class MultiLevelListFlattenerFactoryBean<T> implements FactoryBean<List<T>> {
private List<List<T>> multiLevelList;
@Override
public List<T> getObject() throws Exception {
return multiLevelList.stream().flatMap(Collection::stream).collect(Collectors.toList());
}
@Override
public Class<?> getObjectType() {
return List.class;
}
@Override
public boolean isSingleton() {
return true;
}
/**
* @return Returns the multiLevelList.
*/
public List<List<T>> getMultiLevelList() {
return multiLevelList;
}
/**
* @param multiLevelList The multiLevelList to set.
*/
public void setMultiLevelList(List<List<T>> multiLevelList) {
this.multiLevelList = multiLevelList;
}
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
/**
* Interface allowing a caller to cancel an asynchronous query.
*
* @author Matthew T. Adams
*/
public interface Cancellable {
/**
* Cancels the query operation that this cancellable came from.
*/
void cancel();
}

View File

@@ -1,39 +0,0 @@
/*
* 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.cassandra.core;
import java.util.List;
import com.datastax.driver.core.ResultSet;
/**
* Listener used to receive asynchronous results expected as a {@code List<T>}.
*
* @author Matthew T. Adams
* @param <T>
*/
public interface QueryForListListener<T> {
/**
* Called upon query completion.
*/
void onQueryComplete(List<T> results);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -1,25 +0,0 @@
/*
* 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.cassandra.core;
import java.util.Map;
/**
* Listener used to receive asynchronous results expected as a {@code List<T>}.
*
* @author Matthew T. Adams
*/
public interface QueryForListOfMapListener extends QueryForListListener<Map<String, Object>> {}

View File

@@ -1,39 +0,0 @@
/*
* 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.cassandra.core;
import java.util.Map;
import com.datastax.driver.core.ResultSet;
/**
* Listener used to receive asynchronous results expected as a {@code List<Map<String,Object>>}.
*
* @author Matthew T. Adams
* @param <T>
*/
public interface QueryForMapListener {
/**
* Called upon query completion.
*/
void onQueryComplete(Map<String, Object> results);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -1,42 +0,0 @@
/*
* 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.
* 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.cassandra.core;
import com.datastax.driver.core.ResultSet;
/**
* Listener used to receive asynchronous results expected as an object of type {@code T} or an {@link Exception}.
*
* @author Matthew T. Adams
* @author Mark Paluch
* @param <T>
*/
public interface QueryForObjectListener<T> {
/**
* Called upon query completion.
*
* @param result the result, can be {@literal null} for empty single-record results.
*/
void onQueryComplete(T result);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*
* @param ex the exception that triggered the failure, never {@link null}.
*/
void onException(Exception ex);
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
import org.springframework.dao.DataAccessException;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.exceptions.DriverException;
/**
* @param <T>
* @deprecated as of 2.0, not used anymore.
*/
public interface ResultSetFutureExtractor<T> {
T extractData(ResultSetFuture rs) throws DriverException, DataAccessException;
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
import com.datastax.driver.core.Row;
/**
* Simple internal callback to allow operations on a {@link Row}.
*
* @author Alex Shvid
* @deprecated as of 2.0. Superseded by {@link RowCallbackHandler}.
*/
public interface RowCallback<T> {
/**
* Implementations must implement this method to process each row of data in the
* {@link com.datastax.driver.core.ResultSet}. This method is only supposed to extract values of the current row.
*
* @param object
* @return
*/
T doWith(Row object);
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
/**
* @author David Webb
* @deprecated as of 2.0. This class is not used anymore.
*/
@Deprecated
public interface RowIterator {
Object[] next();
boolean hasNext();
}

View File

@@ -22,9 +22,7 @@ import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.util.StringUtils;
/**
* Utilities to lookup {@link BeanDefinition bean definitions} for a {@link ListableBeanFactory} and to conditionally
@@ -32,89 +30,8 @@ import org.springframework.util.StringUtils;
*
* @author Matthew Adams
* @author Mark Paluch
* @deprecated Will be removed with the next major release.
*/
@Deprecated
public class BeanDefinitionUtils {
/**
* Returns a {@link BeanDefinitionBuilder} iff no {@link BeanDefinition} of the required type is found in the given
* {@link ListableBeanFactory}, otherwise returns {@code null}, indicating that at least one existed.
*
* @param factory The {@link ListableBeanFactory} in which to look for the {@link BeanDefinition}, including
* ancestors.
* @param requiredType The {@link BeanDefinition}'s required type.
* @param instantiableType The instantiable type for the {@link BeanDefinitionBuilder}.
* @param constructorArgs Any {@link BeanDefinitionBuilderArgument}s required by the instantiableType's constructor.
* @return A {@link BeanDefinitionBuilder} iff no {@link BeanDefinition} of the required type is found, otherwise
* {@code null}.
* @see BeanDefinitionUtils#createBeanDefinitionBuilderIfNoBeanDefinitionOfTypeExists(ListableBeanFactory, Class,
* Class, BeanDefinitionBuilderArgument...)
* @see BeanDefinitionBuilderArgument#ref(Object)
* @see BeanDefinitionBuilderArgument#val(Object)
*/
public static BeanDefinitionBuilder createBeanDefinitionBuilderIfNoBeanDefinitionOfTypeExists(
ListableBeanFactory factory, Class<?> requiredType, Class<?> instantiableType,
BeanDefinitionBuilderArgument... constructorArgs) {
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, requiredType, true, false);
if (names.length > 0) {
return null;
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(instantiableType);
if (constructorArgs == null) {
return builder;
}
for (BeanDefinitionBuilderArgument arg : constructorArgs) {
if (arg.reference) {
builder.addConstructorArgReference(arg.value.toString());
} else {
builder.addConstructorArgValue(arg.value);
}
}
return builder;
}
/**
* Returns the single {@link BeanDefinitionHolder} with the given type, or null of none were found and
* {@code required} was <code>false</code>, otherwise throws {@link IllegalArgumentException}.
*
* @param registry The {@link BeanDefinitionRegistry}, often the very same instance as the {@code factor} parameter.
* @param factory The {@link ListableBeanFactory}, often the very same instance as the {@code registry} parameter.
* @param type The required {@link BeanDefinition}'s type.
* @param includeNonSingletons Whether to include beans with scope other than {@code singleton}
* @param allowEagerInit Whether to allow eager initialization of beans.
* @param required Whether to allow the return of null if none were found.
* @return The {@link BeanDefinitionHolder} or null if none found, depending on the value of {@code required}.
* @throws IllegalArgumentException If multiple were found.
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
*/
public static BeanDefinitionHolder getSingleBeanDefinitionOfType(BeanDefinitionRegistry registry,
ListableBeanFactory factory, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit,
boolean required) {
BeanDefinitionHolder[] definitions = getBeanDefinitionsOfType(registry, factory, type, includeNonSingletons,
allowEagerInit);
if (definitions.length == 1) {
return definitions[0];
}
if (definitions.length == 0 && !required) {
return null;
}
String[] names = new String[definitions.length];
for (int i = 0; i < names.length; i++) {
names[i] = definitions[i].getBeanName();
}
throw new IllegalStateException(String.format("expected one bean definition of type [%s], but found %d: %s",
type.getName(), definitions.length, StringUtils.arrayToCommaDelimitedString(names)));
}
class BeanDefinitionUtils {
/**
* Returns all {@link BeanDefinitionHolder}s with the given type.
@@ -128,8 +45,8 @@ public class BeanDefinitionUtils {
* @return The {@link BeanDefinitionHolder}s -- never returns null.
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
*/
public static BeanDefinitionHolder[] getBeanDefinitionsOfType(BeanDefinitionRegistry registry,
ListableBeanFactory factory, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
static BeanDefinitionHolder[] getBeanDefinitionsOfType(BeanDefinitionRegistry registry, ListableBeanFactory factory,
Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(factory, type, includeNonSingletons,
allowEagerInit);

View File

@@ -203,17 +203,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
property -> MappingCassandraConverter.this.readProperty(entity, property, valueProvider, propertyAccessor));
}
/**
* @deprecated Use
* {@link #readProperty(CassandraPersistentEntity, CassandraPersistentProperty, CassandraValueProvider, PersistentPropertyAccessor)}
*/
@Deprecated
protected void readPropertyFromRow(CassandraPersistentEntity<?> entity, CassandraPersistentProperty property,
CassandraRowValueProvider valueProvider, PersistentPropertyAccessor propertyAccessor) {
readProperty(entity, property, valueProvider, propertyAccessor);
}
protected void readProperty(CassandraPersistentEntity<?> entity, CassandraPersistentProperty property,
CassandraValueProvider valueProvider, PersistentPropertyAccessor propertyAccessor) {

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2013-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.cassandra.core;
import org.springframework.cassandra.core.RowCallback;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.util.Assert;
import com.datastax.driver.core.Row;
/**
* Simple {@link RowCallback} that will transform a {@link Row} into the given target type using the given
* {@link CassandraConverter}.
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author Mark Paluch
*/
public class CassandraConverterRowCallback<T> implements RowCallback<T> {
private final CassandraConverter reader;
private final Class<T> type;
/**
* Create a new {@link CassandraConverterRowCallback} instance given {@link CassandraConverter} and a target
* {@link Class type}.
*
* @param reader must not be {@literal null}.
* @param type must not be {@literal null}.
*/
public CassandraConverterRowCallback(CassandraConverter reader, Class<T> type) {
Assert.notNull(reader, "CassandraConverter must not be null");
Assert.notNull(type, "Target class must not be null");
this.reader = reader;
this.type = type;
}
/* (non-Javadoc)
* @see org.springframework.cassandra.core.RowCallback#doWith(com.datastax.driver.core.Row)
*/
@Override
public T doWith(Row row) {
return reader.read(type, row);
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
import java.nio.ByteBuffer;
import com.datastax.driver.core.DataType;
/**
* Simple Cassandra value of the ByteBuffer with DataType
*
* @author Alex Shvid
* @deprecated as of 2.0, not used anymore.
*/
@Deprecated
public class CassandraValue {
private final ByteBuffer value;
private final DataType type;
public CassandraValue(ByteBuffer value, DataType type) {
this.value = value;
this.type = type;
}
public ByteBuffer getValue() {
return value;
}
public DataType getType() {
return type;
}
}

View File

@@ -1,23 +0,0 @@
package org.springframework.data.cassandra.core;
import java.util.Collection;
import com.datastax.driver.core.ResultSet;
/**
* Listener for asynchronous repository insert or update methods.
*
* @author Matthew T. Adams
* @author Mark Paluch
* @deprecated as of 2.0, not used anymore.
*/
@Deprecated
public interface DeletionListener<T> {
void onDeletionComplete(Collection<T> entities);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright 2013-2014 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.cassandra.core;
import java.util.Collection;
import com.datastax.driver.core.ResultSet;
/**
* Listener for asynchronous repository insert or update methods.
*
* @author Matthew T. Adams
* @deprecated as of 2.0, not used anymore.
*/
@Deprecated
public interface WriteListener<T> {
/**
* Called upon completion of the asynchronous insert or update.
*
* @param entities The entities inserted or updated.
*/
void onWriteComplete(Collection<T> entities);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -17,20 +17,11 @@ package org.springframework.data.cassandra.repository.query;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.CollectionExecution;
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.ResultProcessingConverter;
@@ -47,9 +38,6 @@ import org.springframework.data.repository.query.ReturnedType;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
/**
* Base class for {@link RepositoryQuery} implementations for Cassandra.
*
@@ -142,101 +130,6 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
}
}
/**
* @param resultSet
* @param declaredReturnType
* @param returnedUnwrappedObjectType
* @return
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
public Object getCollectionOfEntity(ResultSet resultSet, Class<?> declaredReturnType,
Class<?> returnedUnwrappedObjectType) {
Collection<Object> results;
if (ClassUtils.isAssignable(SortedSet.class, declaredReturnType)) {
results = new TreeSet<>();
} else if (ClassUtils.isAssignable(Set.class, declaredReturnType)) {
results = new HashSet<>();
} else { // List.class, Collection.class, or array
results = new ArrayList<>();
}
CassandraConverter converter = template.getConverter();
for (Row row : resultSet) {
results.add(converter.read(returnedUnwrappedObjectType, row));
}
return results;
}
/**
* @param resultSet
* @param type
* @return
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
public Object getSingleEntity(ResultSet resultSet, Class<?> type) {
Object result = (resultSet.isExhausted() ? null : template.getConverter().read(type, resultSet.one()));
warnIfMoreResults(resultSet);
return result;
}
private void warnIfMoreResults(ResultSet resultSet) {
if (log.isWarnEnabled() && !resultSet.isExhausted()) {
int count = 0;
while (resultSet.one() != null) {
count++;
}
log.warn("ignoring extra {} row{}", count, count == 1 ? "" : "s");
}
}
@Deprecated
protected void warnIfMoreResults(Iterator<Row> iterator) {
if (log.isWarnEnabled() && iterator.hasNext()) {
int count = 0;
while (iterator.hasNext()) {
count++;
iterator.next();
}
log.warn("ignoring extra {} row{}", count, count == 1 ? "" : "s");
}
}
/**
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
public void setConversionService(ConversionService conversionService) {
throw new UnsupportedOperationException("setConversionService(ConversionService) is not supported anymore. "
+ "Please use CassandraMappingContext instead");
}
/**
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} handles type
* conversion.
*/
@Deprecated
public ConversionService getConversionService() {
return template.getConverter().getConversionService();
}
/**
* Creates a string query using the given {@link ParameterAccessor}
*

View File

@@ -1,88 +0,0 @@
/*
* Copyright 2013-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.cassandra.util;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cassandra.core.cql.CqlStringUtils;
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.mapping.CassandraPersistentProperty;
import org.springframework.data.mapping.PropertyHandler;
import com.datastax.driver.core.ColumnMetadata;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.TableMetadata;
/**
* Utilities to convert Cassandra Annotated objects to Queries and CQL.
*
* @author Alex Shvid
* @author David Webb
* @author Matthew T. Adams
* @deprecated need to find a better place for this
*/
@Deprecated
public abstract class CqlUtils {
/**
* Alter the table to reflect the entity annotations
*
* @param tableName
* @param entity
* @param table
* @return
*/
public static List<String> alterTable(final String tableName, final CassandraPersistentEntity<?> entity,
final TableMetadata table) {
final List<String> result = new ArrayList<>();
entity.doWithProperties((PropertyHandler<CassandraPersistentProperty>) prop -> {
String columnName = prop.getColumnName().toCql();
DataType columnDataType = prop.getDataType();
ColumnMetadata columnMetadata = table.getColumn(columnName.toLowerCase());
if (columnMetadata != null && columnDataType.equals(columnMetadata.getType())) {
return;
}
final StringBuilder str = new StringBuilder();
str.append("ALTER TABLE ");
str.append(tableName);
if (columnMetadata == null) {
str.append(" ADD ");
} else {
str.append(" ALTER ");
}
str.append(columnName);
str.append(' ');
if (columnMetadata != null) {
str.append("TYPE ");
}
str.append(CqlStringUtils.toCql(columnDataType));
str.append(';');
result.add(str.toString());
});
return result;
}
}