DATACASS-33 - simplifying CassandraOperations
This commit is contained in:
@@ -18,16 +18,17 @@ package org.springframework.cassandra.core;
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
|
||||
/**
|
||||
* @author David Webb
|
||||
* Interface used to give an implementation access to a {@link ResultSetFuture} after the query has completed.
|
||||
*
|
||||
* @author David Webb
|
||||
*/
|
||||
public interface AsynchronousQueryListener {
|
||||
|
||||
/**
|
||||
* Called upon Query Completion.
|
||||
*
|
||||
* @param rsf The given ResultSetFuture's get methods should return immediately.
|
||||
* @param rsf The {@link ResultSetFuture}. Since this isn't called until the asynchronous query completes, it can be
|
||||
* immediately interrogated.
|
||||
*/
|
||||
public void onQueryComplete(ResultSetFuture rsf);
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public interface CqlOperations {
|
||||
* Executes the supplied CQL Query and returns nothing.
|
||||
*
|
||||
* @param cql
|
||||
* @see #query(String)
|
||||
*/
|
||||
void execute(String cql) throws DataAccessException;
|
||||
|
||||
@@ -108,10 +109,10 @@ public interface CqlOperations {
|
||||
ResultSetFuture queryAsynchronously(String cql, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Executes the provided CQL Query with the provided Runnable implementations.
|
||||
* Executes the provided CQL Query with the provided {@link Runnable} implementation.
|
||||
*
|
||||
* @param cql The Query
|
||||
* @param listener Runnable Listener for handling the query in a separate thread
|
||||
* @param listener {@link Runnable} listener for handling the query in a separate thread
|
||||
*/
|
||||
void queryAsynchronously(String cql, Runnable listener);
|
||||
|
||||
@@ -121,7 +122,8 @@ public interface CqlOperations {
|
||||
* query is completed for optimal flexibility.
|
||||
*
|
||||
* @param cql The Query
|
||||
* @param listener Runnable Listener for handling the query in a separate thread
|
||||
* @param listener {@link AsynchronousQueryListener} Listener for handling the query's {@link ResultSetFuture} in a
|
||||
* separate thread
|
||||
*/
|
||||
void queryAsynchronously(String cql, AsynchronousQueryListener listener);
|
||||
|
||||
@@ -189,6 +191,23 @@ public interface CqlOperations {
|
||||
*/
|
||||
void queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options, Executor executor);
|
||||
|
||||
/**
|
||||
* Executes the provided CQL query and returns the {@link ResultSet}.
|
||||
*
|
||||
* @param cql The query
|
||||
* @return The {@link ResultSet}
|
||||
*/
|
||||
ResultSet query(String cql);
|
||||
|
||||
/**
|
||||
* Executes the provided CQL query with the given {@link QueryOptions} and returns the {@link ResultSet}.
|
||||
*
|
||||
* @param cql The query
|
||||
* @param options The {@link QueryOptions}; may be null.
|
||||
* @return The {@link ResultSet}
|
||||
*/
|
||||
ResultSet query(String cql, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Executes the provided CQL Query, and extracts the results with the ResultSetExtractor.
|
||||
*
|
||||
@@ -762,6 +781,14 @@ public interface CqlOperations {
|
||||
*/
|
||||
void truncate(String tableName);
|
||||
|
||||
/**
|
||||
* Counts all rows for given table
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
long count(String tableName);
|
||||
|
||||
/**
|
||||
* Convenience method to convert the given specification to CQL and execute it.
|
||||
*
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
import org.springframework.cassandra.support.CassandraAccessor;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.dao.QueryTimeoutException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -63,6 +64,7 @@ import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.querybuilder.Truncate;
|
||||
|
||||
/**
|
||||
@@ -304,6 +306,23 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
return process(doExecute(cql, options), rowMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet query(String cql) {
|
||||
return query(cql, (QueryOptions) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet query(String cql, QueryOptions options) {
|
||||
|
||||
return query(cql, new ResultSetExtractor<ResultSet>() {
|
||||
|
||||
@Override
|
||||
public ResultSet extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
return rs;
|
||||
}
|
||||
}, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> query(String cql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(cql, rowMapper, null);
|
||||
@@ -434,7 +453,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Set<Host> getHosts() {
|
||||
protected Set<Host> getHosts() {
|
||||
|
||||
/*
|
||||
* Get the cluster metadata for this session
|
||||
@@ -965,4 +984,25 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(String tableName) {
|
||||
return selectCount(QueryBuilder.select().countAll().from(tableName).getQueryString());
|
||||
}
|
||||
|
||||
protected long selectCount(String countQuery) {
|
||||
|
||||
return query(countQuery, new ResultSetExtractor<Long>() {
|
||||
|
||||
@Override
|
||||
public Long extractData(ResultSet rs) throws DriverException, DataAccessException {
|
||||
|
||||
Row row = rs.one();
|
||||
if (row == null) {
|
||||
throw new InvalidDataAccessApiUsageException(String.format("count query did not return any results"));
|
||||
}
|
||||
|
||||
return row.getLong(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,11 @@ import java.util.List;
|
||||
|
||||
public class CollectionUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] toArray(Iterable<T> i) {
|
||||
return (T[]) toList(i).toArray();
|
||||
}
|
||||
|
||||
public static <T> List<T> toList(Iterable<T> i) {
|
||||
|
||||
List<T> list = null;
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.mapping.model.SpELContext;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
@@ -67,7 +68,11 @@ public class MappingCassandraConverter extends AbstractCassandraConverter implem
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
*/
|
||||
public MappingCassandraConverter(CassandraMappingContext mappingContext) {
|
||||
|
||||
super(new DefaultConversionService());
|
||||
|
||||
Assert.notNull(mappingContext);
|
||||
|
||||
this.mappingContext = mappingContext;
|
||||
this.spELContext = new SpELContext(RowReaderPropertyAccessor.INSTANCE);
|
||||
}
|
||||
|
||||
@@ -124,24 +124,4 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityClass
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String determineTableName(Class<?> entityClass) {
|
||||
|
||||
if (entityClass == null) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"No class parameter provided, entity table name can't be determined!");
|
||||
}
|
||||
|
||||
CassandraPersistentEntity<?> entity = getCassandraMappingContext().getPersistentEntity(entityClass);
|
||||
if (entity == null) {
|
||||
throw new InvalidDataAccessApiUsageException("No Persitent Entity information found for the class "
|
||||
+ entityClass.getName());
|
||||
}
|
||||
return entity.getTableName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,32 +16,34 @@
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import org.springframework.cassandra.core.RowCallback;
|
||||
import org.springframework.data.convert.EntityReader;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
/**
|
||||
* Simple {@link RowCallback} that will transform {@link Row} into the given target type using the given
|
||||
* {@link EntityReader}.
|
||||
* 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
|
||||
*/
|
||||
public class ReadRowCallback<T> implements RowCallback<T> {
|
||||
public class CassandraConverterRowCallback<T> implements RowCallback<T> {
|
||||
|
||||
private final EntityReader<? super T, Object> reader;
|
||||
private final CassandraConverter reader;
|
||||
private final Class<T> type;
|
||||
|
||||
public ReadRowCallback(EntityReader<? super T, Object> reader, Class<T> type) {
|
||||
public CassandraConverterRowCallback(CassandraConverter reader, Class<T> type) {
|
||||
|
||||
Assert.notNull(reader);
|
||||
Assert.notNull(type);
|
||||
|
||||
this.reader = reader;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T doWith(Row row) {
|
||||
T source = reader.read(type, row);
|
||||
return source;
|
||||
return reader.read(type, row);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
|
||||
/**
|
||||
* Operations for interacting with Cassandra. These operations are used by the Repository implementation, but can also
|
||||
* be used directly when that is desired by the developer.
|
||||
@@ -45,50 +43,25 @@ public interface CassandraOperations extends CqlOperations {
|
||||
* Execute query and convert ResultSet to the list of entities
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param selectClass must not be {@literal null}, mapped entity type.
|
||||
* @param type must not be {@literal null}, mapped entity type.
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> select(String cql, Class<T> selectClass);
|
||||
<T> List<T> select(String cql, Class<T> type);
|
||||
|
||||
/**
|
||||
* Execute query and convert ResultSet to the list of entities
|
||||
*
|
||||
* @param selectQuery must not be {@literal null}.
|
||||
* @param selectClass must not be {@literal null}, mapped entity type.
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> select(Select selectQuery, Class<T> selectClass);
|
||||
|
||||
<T> T selectOneById(Class<T> selectClass, Object id);
|
||||
<T> T selectOneById(Class<T> type, Object id);
|
||||
|
||||
/**
|
||||
* Execute query and convert ResultSet to the entity
|
||||
*
|
||||
* @param query must not be {@literal null}.
|
||||
* @param selectClass must not be {@literal null}, mapped entity type.
|
||||
* @param type must not be {@literal null}, mapped entity type.
|
||||
* @return
|
||||
*/
|
||||
<T> T selectOne(String cql, Class<T> selectClass);
|
||||
<T> T selectOne(String cql, Class<T> type);
|
||||
|
||||
<T> T selectOne(Select selectQuery, Class<T> selectClass);
|
||||
boolean exists(Class<?> type, Object id);
|
||||
|
||||
Long countById(Class<?> clazz, Object id);
|
||||
|
||||
/**
|
||||
* Counts rows for given query
|
||||
*
|
||||
* @param selectQuery
|
||||
* @return
|
||||
*/
|
||||
Long count(Select selectQuery);
|
||||
|
||||
/**
|
||||
* Counts all rows for given table
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
Long count(String tableName);
|
||||
long count(Class<?> type);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
@@ -97,23 +70,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T insert(T entity);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
<T> T insert(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> T insert(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -130,15 +86,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities);
|
||||
|
||||
/**
|
||||
* Insert the given list of objects to the table by name.
|
||||
*
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -147,14 +94,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insert(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -162,13 +101,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -177,14 +109,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> T insertAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -192,13 +116,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -207,14 +124,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> insertAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -222,13 +131,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T update(T entity);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> T update(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -237,14 +139,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T update(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> T update(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -252,13 +146,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> update(List<T> entities);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -267,14 +154,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> update(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -282,13 +161,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -297,14 +169,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> T updateAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
@@ -312,13 +176,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities);
|
||||
|
||||
/**
|
||||
* Insert the given object to the table by id.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -327,14 +184,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> updateAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -342,14 +191,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void delete(T entity);
|
||||
|
||||
/**
|
||||
* Removes the given object from the given table.
|
||||
*
|
||||
* @param object
|
||||
* @param table must not be {@literal null} or empty.
|
||||
*/
|
||||
<T> void delete(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
@@ -357,13 +198,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void delete(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
*/
|
||||
<T> void delete(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -371,14 +205,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void delete(List<T> entities);
|
||||
|
||||
/**
|
||||
* Removes the given object from the given table.
|
||||
*
|
||||
* @param object
|
||||
* @param table must not be {@literal null} or empty.
|
||||
*/
|
||||
<T> void delete(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -386,13 +212,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void delete(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
*/
|
||||
<T> void delete(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -407,21 +226,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param tableName
|
||||
* @param options
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Removes the given object from the given table.
|
||||
*
|
||||
* @param object
|
||||
* @param table must not be {@literal null} or empty.
|
||||
*/
|
||||
<T> void deleteAsynchronously(T entity, String tableName);
|
||||
|
||||
/**
|
||||
* Remove the given object from the table by id.
|
||||
*
|
||||
@@ -429,14 +233,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities);
|
||||
|
||||
/**
|
||||
* Removes the given object from the given table.
|
||||
*
|
||||
* @param object
|
||||
* @param table must not be {@literal null} or empty.
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, String tableName);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
@@ -444,13 +240,6 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, QueryOptions options);
|
||||
|
||||
/**
|
||||
* @param entities
|
||||
* @param tableName
|
||||
* @param options
|
||||
*/
|
||||
<T> void deleteAsynchronously(List<T> entities, String tableName, QueryOptions options);
|
||||
|
||||
/**
|
||||
* Returns the underlying {@link CassandraConverter}.
|
||||
*
|
||||
@@ -458,9 +247,9 @@ public interface CassandraOperations extends CqlOperations {
|
||||
*/
|
||||
CassandraConverter getConverter();
|
||||
|
||||
void deleteById(Class<?> clazz, Object id);
|
||||
void deleteById(Class<?> type, Object id);
|
||||
|
||||
<T> List<T> selectByIds(Class<T> clazz, Iterable<?> ids);
|
||||
<T> List<T> selectByIds(Class<T> type, Iterable<?> ids);
|
||||
|
||||
<T> List<T> selectAll(Class<T> clazz);
|
||||
<T> List<T> selectAll(Class<T> type);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import com.datastax.driver.core.TableMetadata;
|
||||
|
||||
@@ -26,4 +27,24 @@ public interface CassandraMappingContext extends
|
||||
* @param table May not be null.
|
||||
*/
|
||||
boolean usesTable(TableMetadata table);
|
||||
|
||||
/**
|
||||
* Returns the {@link CassandraPersistentEntity} for the given type. If it doesn't exist, this method throws
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param type The Java type of the persistent entity.
|
||||
* @return The {@link CassandraPersistentEntity} describing the persistent Java type.
|
||||
* @throws IllegalArgumentException if the persistent entity is unknown
|
||||
*/
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns the {@link CassandraPersistentEntity} for the given type. If it doesn't exist, this method throws
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
* @param type The {@link TypeInformation} of the persistent entity.
|
||||
* @return The {@link CassandraPersistentEntity} describing the persistent Java type.
|
||||
* @throws IllegalArgumentException if the persistent entity is unknown
|
||||
*/
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(TypeInformation<?> type);
|
||||
}
|
||||
|
||||
@@ -148,4 +148,29 @@ public class DefaultCassandraMappingContext extends
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(Class<?> type) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = getPersistentEntity(type);
|
||||
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException(String.format("no persistence metadata found for type [%s]", type.getName()));
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CassandraPersistentEntity<?> getRequiredPersistentEntity(TypeInformation<?> type) {
|
||||
|
||||
CassandraPersistentEntity<?> entity = getPersistentEntity(type);
|
||||
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException(String.format("no persistence metadata found for type [%s]",
|
||||
type.getActualType()));
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cassandra.core.util.CollectionUtils;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
|
||||
@@ -34,7 +35,7 @@ import com.datastax.driver.core.querybuilder.Select;
|
||||
*/
|
||||
public class SimpleCassandraRepository<T, ID extends Serializable> implements CassandraRepository<T, ID> {
|
||||
|
||||
protected CassandraTemplate template;
|
||||
protected CassandraOperations template;
|
||||
protected CassandraEntityInformation<T, ID> entityInformation;
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public class SimpleCassandraRepository<T, ID extends Serializable> implements Ca
|
||||
|
||||
@Override
|
||||
public <S extends T> S save(S entity) {
|
||||
return template.insert(entity, entityInformation.getTableName());
|
||||
return template.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +71,7 @@ public class SimpleCassandraRepository<T, ID extends Serializable> implements Ca
|
||||
|
||||
@Override
|
||||
public boolean exists(ID id) {
|
||||
return template.countById(entityInformation.getJavaType(), id) >= 1; // TODO: == instead of >= ?
|
||||
return template.exists(entityInformation.getJavaType(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,6 +110,6 @@ public class SimpleCassandraRepository<T, ID extends Serializable> implements Ca
|
||||
}
|
||||
|
||||
protected List<T> findAll(Select query) {
|
||||
return template.select(query, entityInformation.getJavaType());
|
||||
return template.select(query.getQueryString(), entityInformation.getJavaType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ import com.datastax.driver.core.querybuilder.Select;
|
||||
public class CassandraDataOperationsTest {
|
||||
|
||||
@Autowired
|
||||
private CassandraOperations cassandraTemplate;
|
||||
private CassandraOperations template;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CassandraDataOperationsTest.class);
|
||||
|
||||
@@ -92,16 +92,13 @@ public class CassandraDataOperationsTest {
|
||||
@Test
|
||||
public void insertTest() {
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b1 = new Book();
|
||||
b1.setIsbn("123456-1");
|
||||
b1.setTitle("Spring Data Cassandra Guide");
|
||||
b1.setAuthor("Cassandra Guru");
|
||||
b1.setPages(521);
|
||||
|
||||
cassandraTemplate.insert(b1);
|
||||
template.insert(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
@@ -109,11 +106,8 @@ public class CassandraDataOperationsTest {
|
||||
b2.setAuthor("Cassandra Guru");
|
||||
b2.setPages(521);
|
||||
|
||||
cassandraTemplate.insert(b2, "book_alt");
|
||||
template.insert(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b3 = new Book();
|
||||
b3.setIsbn("123456-3");
|
||||
b3.setTitle("Spring Data Cassandra Guide");
|
||||
@@ -124,34 +118,27 @@ public class CassandraDataOperationsTest {
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
|
||||
cassandraTemplate.insert(b3, "book", options);
|
||||
template.insert(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b5 = new Book();
|
||||
b5.setIsbn("123456-5");
|
||||
b5.setTitle("Spring Data Cassandra Guide");
|
||||
b5.setAuthor("Cassandra Guru");
|
||||
b5.setPages(265);
|
||||
|
||||
cassandraTemplate.insert(b5, options);
|
||||
|
||||
template.insert(b5, options);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertAsynchronouslyTest() {
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
Book b1 = new Book();
|
||||
b1.setIsbn("123456-1");
|
||||
b1.setTitle("Spring Data Cassandra Guide");
|
||||
b1.setAuthor("Cassandra Guru");
|
||||
b1.setPages(521);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(b1);
|
||||
template.insertAsynchronously(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
@@ -159,7 +146,7 @@ public class CassandraDataOperationsTest {
|
||||
b2.setAuthor("Cassandra Guru");
|
||||
b2.setPages(521);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(b2, "book_alt");
|
||||
template.insertAsynchronously(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -174,7 +161,7 @@ public class CassandraDataOperationsTest {
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(b3, "book", options);
|
||||
template.insertAsynchronously(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -194,7 +181,7 @@ public class CassandraDataOperationsTest {
|
||||
b5.setAuthor("Cassandra Guru");
|
||||
b5.setPages(265);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(b5, options);
|
||||
template.insertAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -209,19 +196,19 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book_alt");
|
||||
template.insert(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book", options);
|
||||
template.insert(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, options);
|
||||
template.insert(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -236,19 +223,19 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(books);
|
||||
template.insertAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(books, "book_alt");
|
||||
template.insertAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(books, "book", options);
|
||||
template.insertAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insertAsynchronously(books, options);
|
||||
template.insertAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -290,7 +277,7 @@ public class CassandraDataOperationsTest {
|
||||
b1.setAuthor("Cassandra Guru");
|
||||
b1.setPages(521);
|
||||
|
||||
cassandraTemplate.update(b1);
|
||||
template.update(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
@@ -298,7 +285,7 @@ public class CassandraDataOperationsTest {
|
||||
b2.setAuthor("Cassandra Guru");
|
||||
b2.setPages(521);
|
||||
|
||||
cassandraTemplate.update(b2, "book_alt");
|
||||
template.update(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -309,7 +296,7 @@ public class CassandraDataOperationsTest {
|
||||
b3.setAuthor("Cassandra Guru");
|
||||
b3.setPages(265);
|
||||
|
||||
cassandraTemplate.update(b3, "book", options);
|
||||
template.update(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -320,7 +307,7 @@ public class CassandraDataOperationsTest {
|
||||
b5.setAuthor("Cassandra Guru");
|
||||
b5.setPages(265);
|
||||
|
||||
cassandraTemplate.update(b5, options);
|
||||
template.update(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -342,7 +329,7 @@ public class CassandraDataOperationsTest {
|
||||
b1.setAuthor("Cassandra Guru");
|
||||
b1.setPages(521);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(b1);
|
||||
template.updateAsynchronously(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
@@ -350,7 +337,7 @@ public class CassandraDataOperationsTest {
|
||||
b2.setAuthor("Cassandra Guru");
|
||||
b2.setPages(521);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(b2, "book_alt");
|
||||
template.updateAsynchronously(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -361,7 +348,7 @@ public class CassandraDataOperationsTest {
|
||||
b3.setAuthor("Cassandra Guru");
|
||||
b3.setPages(265);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(b3, "book", options);
|
||||
template.updateAsynchronously(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -372,7 +359,7 @@ public class CassandraDataOperationsTest {
|
||||
b5.setAuthor("Cassandra Guru");
|
||||
b5.setPages(265);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(b5, options);
|
||||
template.updateAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -387,35 +374,35 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.update(books);
|
||||
template.update(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book_alt");
|
||||
template.insert(books);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.update(books, "book_alt");
|
||||
template.update(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book", options);
|
||||
template.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.update(books, "book", options);
|
||||
template.update(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, options);
|
||||
template.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.update(books, options);
|
||||
template.update(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -430,35 +417,35 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(books);
|
||||
template.updateAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book_alt");
|
||||
template.insert(books);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(books, "book_alt");
|
||||
template.updateAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book", options);
|
||||
template.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(books, "book", options);
|
||||
template.updateAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, options);
|
||||
template.insert(books, options);
|
||||
|
||||
alterBooks(books);
|
||||
|
||||
cassandraTemplate.updateAsynchronously(books, options);
|
||||
template.updateAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -489,12 +476,12 @@ public class CassandraDataOperationsTest {
|
||||
Book b1 = new Book();
|
||||
b1.setIsbn("123456-1");
|
||||
|
||||
cassandraTemplate.delete(b1);
|
||||
template.delete(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
|
||||
cassandraTemplate.delete(b2, "book_alt");
|
||||
template.delete(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -502,7 +489,7 @@ public class CassandraDataOperationsTest {
|
||||
Book b3 = new Book();
|
||||
b3.setIsbn("123456-3");
|
||||
|
||||
cassandraTemplate.delete(b3, "book", options);
|
||||
template.delete(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -510,7 +497,7 @@ public class CassandraDataOperationsTest {
|
||||
Book b5 = new Book();
|
||||
b5.setIsbn("123456-5");
|
||||
|
||||
cassandraTemplate.delete(b5, options);
|
||||
template.delete(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -529,12 +516,12 @@ public class CassandraDataOperationsTest {
|
||||
Book b1 = new Book();
|
||||
b1.setIsbn("123456-1");
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(b1);
|
||||
template.deleteAsynchronously(b1);
|
||||
|
||||
Book b2 = new Book();
|
||||
b2.setIsbn("123456-2");
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(b2, "book_alt");
|
||||
template.deleteAsynchronously(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -542,7 +529,7 @@ public class CassandraDataOperationsTest {
|
||||
Book b3 = new Book();
|
||||
b3.setIsbn("123456-3");
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(b3, "book", options);
|
||||
template.deleteAsynchronously(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -550,7 +537,7 @@ public class CassandraDataOperationsTest {
|
||||
Book b5 = new Book();
|
||||
b5.setIsbn("123456-5");
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(b5, options);
|
||||
template.deleteAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -565,27 +552,27 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
cassandraTemplate.delete(books);
|
||||
template.delete(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book_alt");
|
||||
template.insert(books);
|
||||
|
||||
cassandraTemplate.delete(books, "book_alt");
|
||||
template.delete(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book", options);
|
||||
template.insert(books, options);
|
||||
|
||||
cassandraTemplate.delete(books, "book", options);
|
||||
template.delete(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, options);
|
||||
template.insert(books, options);
|
||||
|
||||
cassandraTemplate.delete(books, options);
|
||||
template.delete(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -600,27 +587,27 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(books);
|
||||
template.deleteAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book_alt");
|
||||
template.insert(books);
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(books, "book_alt");
|
||||
template.deleteAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, "book", options);
|
||||
template.insert(books, options);
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(books, "book", options);
|
||||
template.deleteAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books, options);
|
||||
template.insert(books, options);
|
||||
|
||||
cassandraTemplate.deleteAsynchronously(books, options);
|
||||
template.deleteAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
@@ -636,12 +623,12 @@ public class CassandraDataOperationsTest {
|
||||
b1.setAuthor("Cassandra Guru");
|
||||
b1.setPages(521);
|
||||
|
||||
cassandraTemplate.insert(b1);
|
||||
template.insert(b1);
|
||||
|
||||
Select select = QueryBuilder.select().all().from("book");
|
||||
select.where(QueryBuilder.eq("isbn", "123456-1"));
|
||||
|
||||
Book b = cassandraTemplate.selectOne(select, Book.class);
|
||||
Book b = template.selectOne(select.getQueryString(), Book.class);
|
||||
|
||||
log.info("SingleSelect Book Title -> " + b.getTitle());
|
||||
log.info("SingleSelect Book Author -> " + b.getAuthor());
|
||||
@@ -656,11 +643,11 @@ public class CassandraDataOperationsTest {
|
||||
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
template.insert(books);
|
||||
|
||||
Select select = QueryBuilder.select().all().from("book");
|
||||
|
||||
List<Book> b = cassandraTemplate.select(select, Book.class);
|
||||
List<Book> b = template.select(select.getQueryString(), Book.class);
|
||||
|
||||
log.info("Book Count -> " + b.size());
|
||||
|
||||
@@ -671,23 +658,16 @@ public class CassandraDataOperationsTest {
|
||||
@Test
|
||||
public void selectCountTest() {
|
||||
|
||||
List<Book> books = getBookList(20);
|
||||
int count = 20;
|
||||
List<Book> books = getBookList(count);
|
||||
|
||||
cassandraTemplate.insert(books);
|
||||
|
||||
Select select = QueryBuilder.select().countAll().from("book");
|
||||
|
||||
Long count = cassandraTemplate.count(select);
|
||||
|
||||
log.info("Book Count -> " + count);
|
||||
|
||||
Assert.assertEquals(count, new Long(20));
|
||||
template.insert(books);
|
||||
|
||||
Assert.assertEquals(count, template.count(Book.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearCassandra() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user