From e0bdc35d8428a574c6decc6075b8d8ef98f05d5f Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Fri, 19 Jul 2019 13:03:02 -0700 Subject: Add value of the arguments Also apply the valueof to non svc context arguments. The original code would always treat null arguments as null strings. This replaces that functionality in the prepared statements. Change-Id: I88ab22c87b86a8f5ff41946757c40a399c37a6c3 Signed-off-by: Patrick Brady Issue-ID: OJSI-25 --- .../handler/dbservices/DbLibServiceQueries.java | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DbLibServiceQueries.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DbLibServiceQueries.java index ad4242ae0..d02eb55ec 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DbLibServiceQueries.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DbLibServiceQueries.java @@ -70,10 +70,23 @@ public class DbLibServiceQueries { public QueryStatus query(String query, SvcLogicContext ctx) { ArrayList arguments = new ArrayList<>(); query = CtxParameterizedResolver.resolveCtxVars(query, ctx, arguments); - return query(query, ctx, arguments); + return performQuery(query, ctx, null, arguments); + } + + public QueryStatus query(String query, String prefix, SvcLogicContext ctx) { + ArrayList arguments = new ArrayList<>(); + query = CtxParameterizedResolver.resolveCtxVars(query, ctx, arguments); + return performQuery(query, ctx, prefix, arguments); } public QueryStatus query(String query, SvcLogicContext ctx, ArrayList arguments) { + return performQuery(query, ctx, null, valueOfArrayList(arguments)); + } + public QueryStatus query(String query, SvcLogicContext ctx, String prefix, ArrayList arguments) { + return performQuery(query, ctx, prefix, valueOfArrayList(arguments)); + } + + private QueryStatus performQuery(String query, SvcLogicContext ctx, String prefix, ArrayList arguments) { CachedRowSet result = null; try { @@ -82,7 +95,7 @@ public class DbLibServiceQueries { log.debug("No data found"); return QueryStatus.NOT_FOUND; } else { - CtxParameterizedResolver.saveCachedRowSetToCtx(result, ctx, null, dbLibService); + CtxParameterizedResolver.saveCachedRowSetToCtx(result, ctx, prefix, dbLibService); } } catch (SQLException e) { log.error("Exception in query()",e); @@ -94,10 +107,14 @@ public class DbLibServiceQueries { public QueryStatus save(String query, SvcLogicContext ctx) { ArrayList arguments = new ArrayList<>(); query = CtxParameterizedResolver.resolveCtxVars(query, ctx, arguments); - return save(query,ctx,arguments); + return performSave(query, arguments); } public QueryStatus save(String query, SvcLogicContext ctx, ArrayList arguments) { + return performSave(query, valueOfArrayList(arguments)); + } + + private QueryStatus performSave(String query, ArrayList arguments) { boolean success = false; try { success = dbLibService.writeData(query, arguments, null); @@ -150,5 +167,16 @@ public class DbLibServiceQueries { } return dbLibService; } + + //By using String.valueOf on the array list items, we can store any null values as + //Strings with the value "null". This mirrors the way queries worked prior to the + //prepared statements. + private ArrayList valueOfArrayList(ArrayList original) { + ArrayList valueOfList = new ArrayList<>(); + for(String s : original) { + valueOfList.add(String.valueOf(s)); + } + return valueOfList; + } } -- cgit 1.2.3-korg