DATACOUCH-384 - Apply converters to string based query parameters
Apply the converters registered to serialize the positional and named parameters to match the database representation Original Pull Request: #172.
This commit is contained in:
@@ -38,6 +38,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -125,7 +127,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
Pageable pageable = new PageRequest(0, 8);
|
||||
|
||||
Page<Party> page1 = repository.findAll(pageable);
|
||||
assertEquals(16, page1.getTotalElements()); //12 generated parties + 4 specifically crafted party
|
||||
assertEquals(17, page1.getTotalElements()); //12 generated parties + 5 specifically crafted party
|
||||
assertEquals(8, page1.getNumberOfElements());
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
Pageable pageable = new PageRequest(0, 8, Sort.Direction.DESC, "attendees");
|
||||
|
||||
Page<Party> page1 = repository.findAll(pageable);
|
||||
assertEquals(16, page1.getTotalElements()); //12 generated parties + 4 specifically crafted party
|
||||
assertEquals(17, page1.getTotalElements()); //12 generated parties + 5 specifically crafted party
|
||||
assertEquals(8, page1.getNumberOfElements());
|
||||
|
||||
List<Party> parties = page1.getContent();
|
||||
@@ -160,4 +162,16 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
assertTrue(partyList.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpelDateConvertion() {
|
||||
final String key = "testSpelDateConvertion";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(2018, Calendar.SEPTEMBER, 10);
|
||||
Date date = cal.getTime();
|
||||
partyRepository.save(new Party(key, "", "", date, 0, null));
|
||||
List<Party> partyList = partyRepository.getByEventDate(date);
|
||||
assertTrue(partyList.size() == 1);
|
||||
assertEquals("Key mismatch", partyList.get(0).getKey(), key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +78,7 @@ public interface PartyRepository extends CouchbaseRepository<Party, String> {
|
||||
List<Party> findByDescriptionOrName(String description, String name);
|
||||
|
||||
List<Party> removeByDescriptionOrName(String description, String name);
|
||||
|
||||
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and eventDate = $1")
|
||||
List<Party> getByEventDate(Date eventDate);
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ public class StringN1qlBasedQuery extends AbstractN1qlBasedQuery {
|
||||
private JsonValue getPositionalPlaceholderValues(ParameterAccessor accessor) {
|
||||
JsonArray posValues = JsonArray.create();
|
||||
for (Parameter parameter : getQueryMethod().getParameters().getBindableParameters()) {
|
||||
posValues.add(accessor.getBindableValue(parameter.getIndex()));
|
||||
posValues.add(getCouchbaseOperations().getConverter().convertForWriteIfNeeded(accessor.getBindableValue(parameter.getIndex())));
|
||||
}
|
||||
return posValues;
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class StringN1qlBasedQuery extends AbstractN1qlBasedQuery {
|
||||
|
||||
for (Parameter parameter : getQueryMethod().getParameters().getBindableParameters()) {
|
||||
String placeholder = parameter.getPlaceholder();
|
||||
Object value = accessor.getBindableValue(parameter.getIndex());
|
||||
Object value = getCouchbaseOperations().getConverter().convertForWriteIfNeeded(accessor.getBindableValue(parameter.getIndex()));
|
||||
|
||||
if (placeholder != null && placeholder.charAt(0) == ':') {
|
||||
placeholder = placeholder.replaceFirst(":", "");
|
||||
|
||||
Reference in New Issue
Block a user