From 83559ddc77a0217391212f2abcdcba2c3ff56937 Mon Sep 17 00:00:00 2001 From: "Agarwal, Ruchira (ra1926)" Date: Tue, 5 Nov 2019 18:16:50 +0000 Subject: minor updates to clean up code clean up code to sync with internal Issue-ID: CCSDK-1873 Signed-off-by: Agarwal, Ruchira (ra1926) Change-Id: Idcc7186d5aaa783c527de3986e7a1ecd9bfcf651 --- .../sli/adaptors/resource/sql/SqlResource.java | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'sql-resource') diff --git a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java index 767fdac79..69965d101 100755 --- a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java +++ b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java @@ -100,7 +100,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (QueryStatus.FAILURE); } - String theStmt = resolveCtxVars(key, ctx); + String theStmt = resolveCtxVars(key, ctx, resource); try { CachedRowSet results = dblibSvc.getData(theStmt, null, null); @@ -131,8 +131,9 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { if (dblibSvc == null) { return (QueryStatus.FAILURE); } + + String sqlQuery = resolveCtxVars(key, ctx, resource); - String sqlQuery = resolveCtxVars(key, ctx); try { @@ -230,7 +231,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (QueryStatus.FAILURE); } - String sqlStmt = resolveCtxVars(key, ctx); + String sqlStmt = resolveCtxVars(key, ctx, ""); LOG.debug("key = [" + key + "]; sqlStmt = [" + sqlStmt + "]"); try { @@ -247,7 +248,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { } - private String resolveCtxVars(String key, SvcLogicContext ctx) { + private String resolveCtxVars(String key, SvcLogicContext ctx, String resource) { if (key == null) { return (null); } @@ -257,16 +258,20 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { LOG.debug("Stripped outer single quotes - key is now [" + key + "]"); } - String[] keyTerms = key.split("\\s+"); + //"SQL-TRUE" allows for the key to be used as is. + if (!resource.equals("SQL-TRUE")) { + String[] keyTerms = key.split("\\s+"); - StringBuffer sqlBuffer = new StringBuffer(); + StringBuffer sqlBuffer = new StringBuffer(); - for (int i = 0; i < keyTerms.length; i++) { - sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); - sqlBuffer.append(" "); - } + for (int i = 0; i < keyTerms.length; i++) { + sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); + sqlBuffer.append(" "); + } + key = sqlBuffer.toString(); + } - return (sqlBuffer.toString()); + return (key); } private String resolveTerm(String term, SvcLogicContext ctx) { @@ -441,7 +446,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (strValue); } else { ResultSet results = null; - try (Connection conn = dblibSvc.getConnection(); + try (Connection conn = dblibSvc.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL")) { stmt.setBytes(1, colValue); -- cgit 1.2.3-korg