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:
Trisha Anand 2021-09-30 21:18:52 +05:30 committed by GitHub
parent d8dec82565
commit 9dafd3207f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 4 deletions

View File

@ -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;
}

View File

@ -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();
}