Skip to content

Commit

Permalink
Improve perf of user recomputation in complex2s
Browse files Browse the repository at this point in the history
1) Implemented filtering in ScriptedSQL search operation
2) Turned off recompilation of Groovy scripts on each DB request
  • Loading branch information
mederly committed Aug 28, 2019
1 parent f98d12f commit 69bdb38
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<icscscriptedsql:testScriptFileName>/opt/midpoint/var/res/sis-persons/TestScript.groovy</icscscriptedsql:testScriptFileName>
<icscscriptedsql:schemaScriptFileName>/opt/midpoint/var/res/sis-persons/SchemaScript.groovy</icscscriptedsql:schemaScriptFileName>

<icscscriptedsql:reloadScriptOnExecution>true</icscscriptedsql:reloadScriptOnExecution>
<icscscriptedsql:reloadScriptOnExecution>false</icscscriptedsql:reloadScriptOnExecution>
<!-- >icscscriptedsql:syncScriptFileName>/opt/midpoint/var/res/SyncScript.groovy</icscscriptedsql:syncScriptFileName -->

<icscscriptedsql:validConnectionQuery></icscscriptedsql:validConnectionQuery>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 69bdb38

Please sign in to comment.