fix: [Filter Library]Prepared Statements doesn't set value if the data type is not supported in H2. Defaulting to String for unsupported types. (#8015)
* Prepared Statements doesn't set value if the data type is not supported in H2. Defaulting to String for unsupported types. * Incorporated review comment
This commit is contained in:
parent
d8dec82565
commit
9dafd3207f
|
|
@ -322,6 +322,7 @@ public class FilterDataService {
|
|||
private void executeDbQuery(String query) {
|
||||
|
||||
Connection conn = checkAndGetConnection();
|
||||
log.debug("{} : Executing Query on H2 : {}", Thread.currentThread().getName(), query);
|
||||
|
||||
try {
|
||||
conn.createStatement().execute(query);
|
||||
|
|
@ -537,11 +538,9 @@ public class FilterDataService {
|
|||
preparedStatement.setBoolean(index, Boolean.parseBoolean(value));
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
preparedStatement.setString(index, value);
|
||||
break;
|
||||
}
|
||||
case STRING:
|
||||
default:
|
||||
preparedStatement.setString(index, value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -380,6 +380,53 @@ public class FilterDataServiceTest {
|
|||
assertEquals(filteredData.size(), 2);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValuesOfUnsupportedDataType() {
|
||||
String data = "[\n" +
|
||||
" {\n" +
|
||||
" \"id\": 2381224,\n" +
|
||||
" \"email id\": \"michael.lawson@reqres.in\",\n" +
|
||||
" \"userName\": \"Michael Lawson\",\n" +
|
||||
" \"productName\": \"Chicken Sandwich\",\n" +
|
||||
" \"orderAmount\": 4.99,\n" +
|
||||
" \"date\": \"2021-09-01\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"id\": \"\",\n" +
|
||||
" \"email id\": \"\",\n" +
|
||||
" \"userName\": \"Lindsay Ferguson\",\n" +
|
||||
" \"productName\": \"Tuna Salad\",\n" +
|
||||
" \"orderAmount\": 9.99,\n" +
|
||||
" \"date\": \"2021-09-01\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"id\": \"\",\n" +
|
||||
" \"email id\": \"\",\n" +
|
||||
" \"userName\": \"Tobias Funke\",\n" +
|
||||
" \"productName\": \"Beef steak\",\n" +
|
||||
" \"orderAmount\": 19.99,\n" +
|
||||
" \"date\": \"2021-09-01\"\n" +
|
||||
" }\n" +
|
||||
"]";
|
||||
|
||||
try {
|
||||
ArrayNode items = (ArrayNode) objectMapper.readTree(data);
|
||||
|
||||
List<Condition> conditionList = new ArrayList<>();
|
||||
|
||||
Condition condition = new Condition("orderAmount", "LT", "15");
|
||||
conditionList.add(condition);
|
||||
|
||||
ArrayNode filteredData = filterDataService.filterData(items, conditionList);
|
||||
|
||||
assertEquals(filteredData.size(), 2);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user