DATACASS-466 - Polish.
Resolves gh-110.
This commit is contained in:
@@ -293,8 +293,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return select(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return select(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -308,8 +308,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(entityConsumer, "Entity Consumer must not be empty");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return select(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityConsumer, entityClass);
|
||||
return select(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityConsumer, entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -321,8 +321,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return selectOne(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return selectOne(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -336,8 +336,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(update, "Update must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return getAsyncCqlOperations().execute(
|
||||
getStatementFactory().update(query, update, getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
return getAsyncCqlOperations().execute(getStatementFactory().update(query, update,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -349,8 +349,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return getAsyncCqlOperations()
|
||||
.execute(getStatementFactory().delete(query, getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
return getAsyncCqlOperations().execute(getStatementFactory().delete(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -431,8 +431,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
|
||||
Insert insert = QueryUtils.createInsertQuery(getTableName(entity).toCql(), entity, options, getConverter());
|
||||
|
||||
return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(insert)),
|
||||
WriteResult::of);
|
||||
return new MappingListenableFutureAdapter<>(
|
||||
getAsyncCqlOperations().execute(new AsyncStatementCallback(insert)), WriteResult::of);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -455,8 +455,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
|
||||
Update update = QueryUtils.createUpdateQuery(getTableName(entity).toCql(), entity, options, getConverter());
|
||||
|
||||
return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(update)),
|
||||
WriteResult::of);
|
||||
return new MappingListenableFutureAdapter<>(
|
||||
getAsyncCqlOperations().execute(new AsyncStatementCallback(update)), WriteResult::of);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -479,8 +479,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
|
||||
Delete delete = QueryUtils.createDeleteQuery(getTableName(entity).toCql(), entity, options, getConverter());
|
||||
|
||||
return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(delete)),
|
||||
WriteResult::of);
|
||||
return new MappingListenableFutureAdapter<>(
|
||||
getAsyncCqlOperations().execute(new AsyncStatementCallback(delete)), WriteResult::of);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -511,8 +511,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
Truncate truncate = QueryBuilder
|
||||
.truncate(getMappingContext().getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
Truncate truncate = QueryBuilder.truncate(
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
|
||||
return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(truncate), aBoolean -> null);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -25,6 +22,9 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
|
||||
@@ -78,10 +78,10 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
|
||||
private final CassandraConverter converter;
|
||||
|
||||
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
|
||||
|
||||
private final CqlOperations cqlOperations;
|
||||
|
||||
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
|
||||
|
||||
private final StatementFactory statementFactory;
|
||||
|
||||
/**
|
||||
@@ -286,8 +286,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return select(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return select(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -299,8 +299,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return stream(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return stream(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -325,8 +325,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(update, "Update must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return getCqlOperations().execute(
|
||||
getStatementFactory().update(query, update, getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
return getCqlOperations().execute(getStatementFactory().update(query, update,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -338,8 +338,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return getCqlOperations()
|
||||
.execute(getStatementFactory().delete(query, getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
return getCqlOperations().execute(getStatementFactory().delete(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -410,10 +410,9 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
CassandraPersistentProperty idProperty = entity.getRequiredIdProperty();
|
||||
|
||||
if (idProperty.isCompositePrimaryKey()) {
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Entity class [%s] uses a composite primary key class [%s] which this method can't support",
|
||||
entityClass.getName(), idProperty.getType().getName()));
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Entity class [%s] uses a composite primary key class [%s] which this method can't support",
|
||||
entityClass.getName(), idProperty.getType().getName()));
|
||||
}
|
||||
|
||||
Select select = QueryBuilder.select().all().from(entity.getTableName().toCql());
|
||||
@@ -441,7 +440,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null");
|
||||
|
||||
Insert insert = QueryUtils.createInsertQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
Insert insert = QueryUtils.createInsertQuery(
|
||||
getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
|
||||
return getCqlOperations().execute(new StatementCallback(insert));
|
||||
}
|
||||
@@ -464,7 +464,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null");
|
||||
|
||||
Update update = QueryUtils.createUpdateQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
Update update = QueryUtils.createUpdateQuery(
|
||||
getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
|
||||
return getCqlOperations().execute(new StatementCallback(update));
|
||||
}
|
||||
@@ -487,7 +488,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null");
|
||||
|
||||
Delete delete = QueryUtils.createDeleteQuery(getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
Delete delete = QueryUtils.createDeleteQuery(
|
||||
getTableName(entity.getClass()).toCql(), entity, options, converter);
|
||||
|
||||
return getCqlOperations().execute(new StatementCallback(delete));
|
||||
}
|
||||
@@ -520,8 +522,8 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
Truncate truncate = QueryBuilder
|
||||
.truncate(getMappingContext().getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
Truncate truncate = QueryBuilder.truncate(
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
|
||||
getCqlOperations().execute(truncate);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@ import com.datastax.driver.core.Row;
|
||||
*/
|
||||
public class WriteResult {
|
||||
|
||||
private final List<ExecutionInfo> executionInfo;
|
||||
private final boolean wasApplied;
|
||||
|
||||
private final List<ExecutionInfo> executionInfo;
|
||||
private final List<Row> rows;
|
||||
|
||||
WriteResult(List<ExecutionInfo> executionInfo, boolean wasApplied, List<Row> rows) {
|
||||
@@ -54,7 +55,7 @@ public class WriteResult {
|
||||
|
||||
List<Row> rows = new ArrayList<>(limit);
|
||||
|
||||
for (int i = 0; i < limit; i++) {
|
||||
for (int count = 0; count < limit; count++) {
|
||||
rows.add(resultSet.one());
|
||||
}
|
||||
|
||||
|
||||
@@ -443,17 +443,15 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeSelectWhereFromObject(final Object object, final Select.Where where,
|
||||
CassandraPersistentEntity<?> entity) {
|
||||
protected void writeSelectWhereFromObject(Object object, Select.Where where, CassandraPersistentEntity<?> entity) {
|
||||
getWhereClauses(object, entity).forEach(where::and);
|
||||
}
|
||||
|
||||
protected void writeDeleteWhereFromObject(final Object object, final Delete.Where where,
|
||||
CassandraPersistentEntity<?> entity) {
|
||||
protected void writeDeleteWhereFromObject(Object object, Delete.Where where, CassandraPersistentEntity<?> entity) {
|
||||
getWhereClauses(object, entity).forEach(where::and);
|
||||
}
|
||||
|
||||
protected void writeUDTValueWhereFromObject(final ConvertingPropertyAccessor accessor, final UDTValue udtValue,
|
||||
protected void writeUDTValueWhereFromObject(ConvertingPropertyAccessor accessor, UDTValue udtValue,
|
||||
CassandraPersistentEntity<?> entity) {
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
@@ -481,6 +479,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
Assert.notNull(source, "Id source must not be null");
|
||||
|
||||
Object id = extractId(source, entity);
|
||||
|
||||
Assert.notNull(id, String.format("No Id value found in object %s", source));
|
||||
|
||||
CassandraPersistentProperty idProperty = entity.getIdProperty();
|
||||
@@ -511,8 +510,9 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
String.format("Cannot use [%s] as composite Id for [%s]", id, entity.getName()));
|
||||
}
|
||||
|
||||
CassandraPersistentEntity<?> compositePrimaryKey = mappingContext
|
||||
.getRequiredPersistentEntity(compositeIdProperty);
|
||||
CassandraPersistentEntity<?> compositePrimaryKey =
|
||||
mappingContext.getRequiredPersistentEntity(compositeIdProperty);
|
||||
|
||||
return getWhereClauses(getConvertingAccessor(id, compositePrimaryKey), compositePrimaryKey);
|
||||
}
|
||||
|
||||
@@ -548,7 +548,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
Collection<Clause> clauses = new ArrayList<>();
|
||||
|
||||
for (CassandraPersistentProperty property : entity) {
|
||||
|
||||
TypeCodec<Object> codec = getCodec(property);
|
||||
Object value = accessor.getProperty(property, codec.getJavaType().getRawType());
|
||||
clauses.add(QueryBuilder.eq(property.getColumnName().toCql(), value));
|
||||
@@ -573,6 +572,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
|
||||
Object writeValue = getWriteValue(entry.getValue(), persistentProperty.getTypeInformation());
|
||||
|
||||
clauses.add(QueryBuilder.eq(persistentProperty.getColumnName().toCql(), writeValue));
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
Assert.notNull(object, "Object instance must not be null");
|
||||
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
|
||||
|
||||
final ConvertingPropertyAccessor accessor = getConvertingAccessor(object, entity);
|
||||
ConvertingPropertyAccessor propertyAccessor = getConvertingAccessor(object, entity);
|
||||
|
||||
Assert.isTrue(entity.getType().isAssignableFrom(object.getClass()),
|
||||
String.format("Given instance of type [%s] is not of compatible expected type [%s]",
|
||||
@@ -600,8 +600,8 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
|
||||
if (idProperty != null) {
|
||||
// TODO: NullId
|
||||
return accessor.getProperty(idProperty, idProperty.isCompositePrimaryKey() ? (Class<Object>) idProperty.getType()
|
||||
: (Class<Object>) getTargetType(idProperty));
|
||||
return propertyAccessor.getProperty(idProperty, idProperty.isCompositePrimaryKey()
|
||||
? (Class<Object>) idProperty.getType() : (Class<Object>) getTargetType(idProperty));
|
||||
}
|
||||
|
||||
// if the class doesn't have an id property, then it's using MapId
|
||||
@@ -613,7 +613,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
continue;
|
||||
}
|
||||
|
||||
id.with(property.getName(), getWriteValue(property, accessor));
|
||||
id.with(property.getName(), getWriteValue(property, propertyAccessor));
|
||||
}
|
||||
|
||||
return id;
|
||||
|
||||
@@ -100,8 +100,10 @@ public class SimpleCassandraRepository<T, ID> implements CassandraRepository<T,
|
||||
private <S extends T> Insert createFullInsert(S entity) {
|
||||
|
||||
CassandraConverter converter = operations.getConverter();
|
||||
CassandraPersistentEntity<?> persistentEntity = converter.getMappingContext()
|
||||
.getRequiredPersistentEntity(entity.getClass());
|
||||
|
||||
CassandraPersistentEntity<?> persistentEntity =
|
||||
converter.getMappingContext().getRequiredPersistentEntity(entity.getClass());
|
||||
|
||||
Map<String, Object> toInsert = new LinkedHashMap<>();
|
||||
|
||||
converter.write(entity, toInsert, persistentEntity);
|
||||
@@ -139,8 +141,8 @@ public class SimpleCassandraRepository<T, ID> implements CassandraRepository<T,
|
||||
List<S> result = new ArrayList<>();
|
||||
|
||||
for (S entity : entities) {
|
||||
result.add(entity);
|
||||
operations.insert(entity);
|
||||
result.add(entity);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -217,6 +217,7 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
|
||||
UpdateOptions lwtOptions = UpdateOptions.builder().withIfExists().build();
|
||||
|
||||
User user = new User("heisenberg", "Walter", "White");
|
||||
|
||||
template.insert(user);
|
||||
|
||||
user.setFirstname("Walter Hartwell");
|
||||
|
||||
Reference in New Issue
Block a user