DATACASS-148: fixed

This commit is contained in:
Matthew Adams
2014-09-12 16:15:20 -05:00
parent 60f6c8fba8
commit ae607283f9
2 changed files with 24 additions and 4 deletions

View File

@@ -68,8 +68,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Default Constructor for wiring in the required components later
*/
public CassandraTemplate() {
}
public CassandraTemplate() {}
public CassandraTemplate(Session session) {
this(session, new MappingCassandraConverter());
@@ -536,7 +535,12 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
protected <T> List<T> batchInsert(List<T> entities, WriteOptions options, boolean asychronously) {
Assert.notEmpty(entities);
if (entities == null || entities.size() == 0) {
if (logger.isWarnEnabled()) {
logger.warn("no-op due to given null or empty list");
}
return entities;
}
Batch b = createInsertBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options,
cassandraConverter);

View File

@@ -15,6 +15,10 @@
*/
package org.springframework.data.cassandra.test.integration.template;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -42,7 +46,6 @@ import com.datastax.driver.core.querybuilder.Select;
* Unit Tests for CqlTemplate
*
* @author David Webb
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -163,6 +166,19 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa
}
@Test
public void insertEmptyList() {
List<Book> list = template.insert(new ArrayList<Book>());
assertNotNull(list);
assertEquals(0, list.size());
}
@Test
public void insertNullList() {
List<Book> list = template.insert((List<Book>) null);
assertNull(list);
}
@Test
public void insertBatchTest() {