DATACASS-92 - IN PROGRESS

Added support for all data types except List,Set and Map.  Those are for
tomorrow.
This commit is contained in:
David T Webb
2014-02-13 00:13:37 -05:00
parent b1226eb2b5
commit b220a8ab50
4 changed files with 81 additions and 19 deletions

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.cassandra.convert;
import java.nio.ByteBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.cassandra.mapping.CassandraPersistentProperty;
@@ -33,6 +31,7 @@ import com.datastax.driver.core.Row;
*
* @author Alex Shvid
* @author Matthew T. Adams
* @author David Webb
*/
public class DefaultCassandraRowValueProvider implements CassandraRowValueProvider {
@@ -73,16 +72,44 @@ public class DefaultCassandraRowValueProvider implements CassandraRowValueProvid
log.debug(columnType.getName().name());
// TODO Might need to qualify all DataTypes as we encounter them.
if (columnType.equals(DataType.text())) {
// TODO DW Set, Map, List
if (columnType.equals(DataType.text()) || columnType.equals(DataType.ascii())
|| columnType.equals(DataType.varchar())) {
return (T) source.getString(columnName);
}
if (columnType.equals(DataType.cint())) {
if (columnType.equals(DataType.cint()) || columnType.equals(DataType.varint())) {
return (T) new Integer(source.getInt(columnName));
}
if (columnType.equals(DataType.cdouble())) {
return (T) new Double(source.getDouble(columnName));
}
if (columnType.equals(DataType.bigint()) || columnType.equals(DataType.counter())) {
return (T) new Long(source.getLong(columnName));
}
if (columnType.equals(DataType.cfloat())) {
return (T) new Float(source.getFloat(columnName));
}
if (columnType.equals(DataType.decimal())) {
return (T) source.getDecimal(columnName);
}
if (columnType.equals(DataType.cboolean())) {
return (T) new Boolean(source.getBool(columnName));
}
if (columnType.equals(DataType.timestamp())) {
return (T) source.getDate(columnName);
}
if (columnType.equals(DataType.blob())) {
return (T) source.getBytes(columnName);
}
if (columnType.equals(DataType.inet())) {
return (T) source.getInet(columnName);
}
if (columnType.equals(DataType.uuid()) || columnType.equals(DataType.timeuuid())) {
return (T) source.getUUID(columnName);
}
ByteBuffer bytes = source.getBytes(columnName);
return (T) columnType.deserialize(bytes);
return (T) source.getBytes(columnName);
}
public Row getRow() {

View File

@@ -181,6 +181,10 @@ public class DefaultCassandraPersistentEntityMetadataVerifier implements Cassand
*/
if (isTable) {
/*
* TODO Verify annotation values with CqlIndentifier
*/
/*
* Ensure only one PK
*/

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.cassandra.test.integration.simpletons;
import java.util.Date;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
@@ -33,6 +35,8 @@ public class Book {
private String title;
private String author;
private int pages;
private Date saleDate;
private boolean isInStock;
/**
* @return Returns the isbn.
@@ -41,6 +45,34 @@ public class Book {
return isbn;
}
/**
* @return Returns the saleDate.
*/
public Date getSaleDate() {
return saleDate;
}
/**
* @param saleDate The saleDate to set.
*/
public void setSaleDate(Date saleDate) {
this.saleDate = saleDate;
}
/**
* @return Returns the isInStock.
*/
public boolean isInStock() {
return isInStock;
}
/**
* @param isInStock The isInStock to set.
*/
public void setInStock(boolean isInStock) {
this.isInStock = isInStock;
}
/**
* @param isbn The isbn to set.
*/

View File

@@ -16,38 +16,30 @@
package org.springframework.data.cassandra.test.integration.template;
import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.createKeyspace;
import static org.springframework.cassandra.core.keyspace.DropTableSpecification.dropTable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.ConsistencyLevel;
import org.springframework.cassandra.core.QueryOptions;
import org.springframework.cassandra.core.RetryPolicy;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.test.integration.simpletons.Book;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.TestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
@@ -93,6 +85,8 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa
b1.setTitle("Spring Data Cassandra Guide");
b1.setAuthor("Cassandra Guru");
b1.setPages(521);
b1.setSaleDate(new Date());
b1.setInStock(true);
template.insert(b1);
@@ -249,6 +243,8 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa
b.setTitle("Spring Data Cassandra Guide");
b.setAuthor("Cassandra Guru");
b.setPages(i * 10 + 5);
b.setInStock(true);
b.setSaleDate(new Date());
books.add(b);
}
@@ -643,12 +639,15 @@ public class CassandraDataOperationsTest extends AbstractSpringDataEmbeddedCassa
Select select = QueryBuilder.select().all().from("book");
List<Book> b = template.select(select.getQueryString(), Book.class);
List<Book> bookz = template.select(select.getQueryString(), Book.class);
log.info("Book Count -> " + b.size());
log.info("Book Count -> " + bookz.size());
Assert.assertEquals(b.size(), 20);
Assert.assertEquals(bookz.size(), 20);
for (Book b : bookz) {
Assert.assertTrue(b.isInStock());
}
}
@Test