From 76db66a0df36dd0f9db7a3eae17ffe5e2a843e84 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 9 Mar 2016 18:34:53 +0100 Subject: [PATCH] auto-remove null parameters from the map --- src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java | 12 +++++------- src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java | 9 +++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java index 0e28293..d79027c 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java @@ -50,14 +50,12 @@ public final class Queries { public static String getQuery(String tableName, Map params, int nbRow) { StringJoiner join = new StringJoiner(" AND "); for (Map.Entry param : params.entrySet()) { - if (param.getValue() != null) { - Class paramClass = param.getValue().getClass(); + Class paramClass = param.getValue().getClass(); - if (paramClass == String.class && !"".equals(param.getValue())) { - join.add(param.getKey() + " LIKE '%" + param.getValue() + "%'"); - } else if (paramClass == Float.class || paramClass == Integer.class) { - join.add(param.getKey() + " = " + param.getValue().toString()); - } + if (paramClass == String.class && !"".equals(param.getValue())) { + join.add(param.getKey() + " LIKE '%" + param.getValue() + "%'"); + } else { + join.add(param.getKey() + " = " + param.getValue().toString()); } } String where = "".equals(join.toString()) ? "" : " WHERE " + join.toString(); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java index 0913d1c..28eaf6f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java @@ -131,8 +131,13 @@ public class RequestView extends JPanel implements ActionListener { } public void updateParam(String paramName, Object value) { - logger.info("uploading " + paramName + ": " + value); - paramValues.put(paramName, value); + if (value == null) { + paramValues.remove(paramName); + logger.info("removed " + paramName); + } else { + paramValues.put(paramName, value); + logger.info("uploaded " + paramName + ": " + value); + } updateQueryArea(); } -- libgit2 0.21.2