From 69bdb38e71b76354be6465bc23cb386c99eafe80 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Wed, 28 Aug 2019 11:05:39 +0200 Subject: [PATCH] Improve perf of user recomputation in complex2s 1) Implemented filtering in ScriptedSQL search operation 2) Turned off recompilation of Groovy scripts on each DB request --- .../resources/scriptedsql-sis-persons.xml | 2 +- .../res/sis-persons/SearchScript.groovy | 67 ++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/demo/complex2s/midpoint-objects/resources/scriptedsql-sis-persons.xml b/demo/complex2s/midpoint-objects/resources/scriptedsql-sis-persons.xml index 6fe8355..d95d39e 100644 --- a/demo/complex2s/midpoint-objects/resources/scriptedsql-sis-persons.xml +++ b/demo/complex2s/midpoint-objects/resources/scriptedsql-sis-persons.xml @@ -42,7 +42,7 @@ /opt/midpoint/var/res/sis-persons/TestScript.groovy /opt/midpoint/var/res/sis-persons/SchemaScript.groovy - true + false diff --git a/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy b/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy index 9e16b51..1226bdf 100644 --- a/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy +++ b/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy @@ -21,8 +21,10 @@ * ==================== * Portions Copyrighted 2013 ConnId. */ -import groovy.sql.Sql; -import groovy.sql.DataSet; + +import groovy.sql.Sql +import groovy.sql.DataSet +import org.identityconnectors.framework.common.objects.* // Parameters: // The connector sends the following: @@ -61,7 +63,66 @@ def where = ""; switch ( objectClass ) { case "__ACCOUNT__": - sql.eachRow("select uid, surname, givenName, fullName, mail from SIS_PERSONS", {result.add([ + + sqlParams = [:] + + uidColumn = 'uid' + nameColumn = 'uid' + + log.info("Building where clause, query {0}, uidcolumn {1}, nameColumn {2}", query, uidColumn, nameColumn) + + String left = query.get("left") + if (left != null) { + if (Uid.NAME.equals(left)) { + left = uidColumn + } else if (Name.NAME.equals(left)) { + left = nameColumn + } + + String right = query.get("right") + + String operation = query.get("operation") + switch (operation) { + case "CONTAINS": + right = '%' + right + '%' + break; + case "ENDSWITH": + right = '%' + right + break; + case "STARTSWITH": + right = right + '%' + break; + } + + sqlParams.put(left, right) + right = ":" + left + + def engine = new groovy.text.SimpleTemplateEngine() + + def whereTemplates = [ + CONTAINS : ' $left ${not ? "not " : ""}like $right', + ENDSWITH : ' $left ${not ? "not " : ""}like $right', + STARTSWITH : ' $left ${not ? "not " : ""}like $right', + EQUALS : ' $left ${not ? "<>" : "="} $right', + GREATERTHAN : ' $left ${not ? "<=" : ">"} $right', + GREATERTHANOREQUAL: ' $left ${not ? "<" : ">="} $right', + LESSTHAN : ' $left ${not ? ">=" : "<"} $right', + LESSTHANOREQUAL : ' $left ${not ? ">" : "<="} $right' + ] + + def wt = whereTemplates.get(operation) + def binding = [left: left, right: right, not: query.get("not")] + def template = engine.createTemplate(wt).make(binding) + where = ' where ' + template.toString() + + log.info("Where clause: {0}, with parameters {1}", where, sqlParams) + } + + q = 'select uid, surname, givenName, fullName, mail from SIS_PERSONS' + where + + log.info('query = {0}', query) + log.info('sql = {0}', q) + sql.eachRow(sqlParams, q, {result.add([ __UID__:it.uid, __NAME__:it.uid, uid:it.uid,