DATACASS-123 - @Query annotation does not support integers as parameters
This commit is contained in:
@@ -33,7 +33,7 @@ public class CassandraQueryMethod extends QueryMethod {
|
||||
public static final List<Class<?>> ALLOWED_PARAMETER_TYPES = Collections.unmodifiableList(Arrays
|
||||
.asList(new Class<?>[] { String.class, CharSequence.class, char.class, Character.class, char[].class, long.class,
|
||||
Long.class, boolean.class, Boolean.class, BigDecimal.class, BigInteger.class, double.class, Double.class,
|
||||
float.class, Float.class, InetAddress.class, Date.class, UUID.class, }));
|
||||
float.class, Float.class, InetAddress.class, Date.class, UUID.class, int.class, Integer.class }));
|
||||
|
||||
public static final List<Class<?>> STRING_LIKE_PARAMETER_TYPES = Collections.unmodifiableList(Arrays
|
||||
.asList(new Class<?>[] { CharSequence.class, char.class, Character.class, char[].class }));
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.intparam;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
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;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class IntParamIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@EnableCassandraRepositories(basePackageClasses = ThingRepo.class)
|
||||
public static class Config extends IntegrationTestConfig {
|
||||
@Override
|
||||
public String[] getEntityBasePackages() {
|
||||
return new String[] { Thing.class.getPackage().getName() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE_DROP_UNUSED;
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ThingRepo repo;
|
||||
|
||||
@Test
|
||||
public void testQueryWithIntPrimitiveAndReference() {
|
||||
int number = 42;
|
||||
Thing saved = new Thing(42);
|
||||
repo.save(saved);
|
||||
|
||||
Thing found = repo.findThingByIntPrimitive(number);
|
||||
assertNotNull(found);
|
||||
|
||||
found = repo.findThingByIntReference(new Integer(number));
|
||||
assertNotNull(found);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.intparam;
|
||||
|
||||
import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class Thing {
|
||||
|
||||
@PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
|
||||
private int number;
|
||||
|
||||
public Thing() {
|
||||
}
|
||||
|
||||
public Thing(int number) {
|
||||
setNumber(number);
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.data.cassandra.test.integration.querymethods.intparam;
|
||||
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
import org.springframework.data.cassandra.repository.Query;
|
||||
|
||||
public interface ThingRepo extends CassandraRepository<Thing> {
|
||||
|
||||
@Query("SELECT * from thing where number = ?0")
|
||||
Thing findThingByIntPrimitive(int number);
|
||||
|
||||
@Query("SELECT * from thing where number = ?0")
|
||||
Thing findThingByIntReference(Integer number);
|
||||
}
|
||||
Reference in New Issue
Block a user