Merge pull request #29 from petercable/varint

DATACASS-199: ColumnMapper maps varint to Integer 

Task-Url: https://jira.spring.io/browse/DATACASS-199
This commit is contained in:
David Webb
2015-01-27 10:58:28 -05:00
4 changed files with 93 additions and 1 deletions

View File

@@ -67,9 +67,12 @@ public class ColumnReader {
if (type.equals(DataType.text()) || type.equals(DataType.ascii()) || type.equals(DataType.varchar())) {
return row.getString(i);
}
if (type.equals(DataType.cint()) || type.equals(DataType.varint())) {
if (type.equals(DataType.cint())) {
return new Integer(row.getInt(i));
}
if (type.equals(DataType.varint())) {
return row.getVarint(i);
}
if (type.equals(DataType.cdouble())) {
return new Double(row.getDouble(i));
}

View File

@@ -0,0 +1,48 @@
package org.springframework.data.cassandra.test.integration.querymethods.bigintparam;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigInteger;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class BigIntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
@Configuration
@EnableCassandraRepositories(basePackageClasses = BigThingRepo.class)
public static class Config extends IntegrationTestConfig {
@Override
public String[] getEntityBasePackages() {
return new String[] { BigThing.class.getPackage().getName() };
}
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.RECREATE_DROP_UNUSED;
}
}
@Autowired
BigThingRepo repo;
@Test
public void testQueryWithReference() {
BigInteger number = new BigInteger("42");
BigThing saved = new BigThing(number);
repo.save(saved);
BigThing found = repo.findThingByBigInteger(new BigInteger("42"));
assertNotNull(found);
}
}

View File

@@ -0,0 +1,28 @@
package org.springframework.data.cassandra.test.integration.querymethods.bigintparam;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import java.math.BigInteger;
@Table
public class BigThing {
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private BigInteger number;
public BigThing() {}
public BigThing(BigInteger number) {
setNumber(number);
}
public BigInteger getNumber() {
return number;
}
public void setNumber(BigInteger number) {
this.number = number;
}
}

View File

@@ -0,0 +1,13 @@
package org.springframework.data.cassandra.test.integration.querymethods.bigintparam;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.cassandra.repository.Query;
import java.math.BigInteger;
public interface BigThingRepo extends CassandraRepository<BigThing> {
@Query("SELECT * from bigthing where number = ?0")
BigThing findThingByBigInteger(BigInteger number);
}