From 7fed977a8a6d1606b97248ab365fb70d0f207e47 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Fri, 21 Jun 2019 18:37:48 +0300 Subject: [PATCH] Use functions for cache in ref and getTableColumns in hid class --- .../latera/bss/connectors/hid/Table.groovy | 43 ++++++++++------- .../bss/connectors/hid/hydra/Ref.groovy | 47 +++++++++++++------ .../camunda/latera/bss/utils/Oracle.groovy | 2 +- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/src/org/camunda/latera/bss/connectors/hid/Table.groovy b/src/org/camunda/latera/bss/connectors/hid/Table.groovy index 1b4802ee..b2b2cbab 100644 --- a/src/org/camunda/latera/bss/connectors/hid/Table.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/Table.groovy @@ -12,27 +12,36 @@ trait Table { private static LinkedHashMap DEFAULT_ORDER = [:] private static List DEFAULT_FIELDS = null + private void putTableColumnsCache(def tableName, def columnsList) { + if (!TABLE_COLUMNS_CACHE.containsKey(tableName)) { + TABLE_COLUMNS_CACHE[tableName] = columnsList + } + } + + private def getTableColumnsCached(def tableName) { + if (!TABLE_COLUMNS_CACHE.containsKey(tableName)) { + return TABLE_COLUMNS_CACHE[tableName] + } + return null + } + List getTableColumns(String tableName, String tableOwner = 'AIS_NET') { String tableFullName = "${tableOwner}.${tableName}" - if (TABLE_COLUMNS_CACHE.containsKey(tableFullName)) { - return TABLE_COLUMNS_CACHE[tableFullName] - } else { - List columnsList = null - - List result = queryDatabase(""" - SELECT COLUMN_NAME - FROM ALL_TAB_COLUMNS - WHERE TABLE_NAME = '${tableName}' - AND OWNER = '${tableOwner}' - """, false, true) - - columnsList = result*.getAt(0) //get only first column values - - if (columnsList) { - TABLE_COLUMNS_CACHE[tableFullName] = columnsList - } + List columnsList = getTableColumnsCached(tableFullName) + if (columnsList) { return columnsList } + + List result = queryDatabase(""" + SELECT COLUMN_NAME + FROM ALL_TAB_COLUMNS + WHERE TABLE_NAME = '${tableName}' + AND OWNER = '${tableOwner}' + """, false, true) + + columnsList = result*.getAt(0) //get only first column values + putTableColumnsCache(tableFullName, columnsList) + return columnsList } List getTableData( diff --git a/src/org/camunda/latera/bss/connectors/hid/hydra/Ref.groovy b/src/org/camunda/latera/bss/connectors/hid/hydra/Ref.groovy index c54efc48..8bae4f60 100644 --- a/src/org/camunda/latera/bss/connectors/hid/hydra/Ref.groovy +++ b/src/org/camunda/latera/bss/connectors/hid/hydra/Ref.groovy @@ -1,4 +1,5 @@ package org.camunda.latera.bss.connectors.hid.hydra + import org.camunda.latera.bss.utils.Numeric trait Ref { @@ -12,6 +13,26 @@ trait Ref { return REFS_TABLE } + private void putRefCache(def code, def refId) { + if (!REFS_CACHE.containsKey(code)) { + REFS_CACHE[code] = Numeric.toIntSafe(refId) + } + } + + private def getRefIdCached(def code) { + if (REFS_CACHE.containsKey(code)) { + return REFS_CACHE[code] + } + return null + } + + private def getRefCodeCached(def id) { + if (REFS_CACHE.containsValue(id)) { + return REFS_CACHE.find{it.value == id}?.key + } + return null + } + LinkedHashMap getRef(def refId) { LinkedHashMap where = [ n_ref_id: refId @@ -108,9 +129,7 @@ trait Ref { def result = hid.getTableData(getRefsTable(), where: where) if (result) { result.each { ref -> - if (!REFS_CACHE.containsKey(ref.vc_code)) { - REFS_CACHE[ref.vc_code] = Numeric.toIntSafe(ref.n_ref_id) - } + putRefCache(ref.vc_code, ref.n_ref_id) } } return result @@ -129,17 +148,16 @@ trait Ref { } def getRefIdByCode(def code) { - if (REFS_CACHE.containsKey(code)) { - return REFS_CACHE[code] + def id = getRefIdCached(code) + if (id) { + return id } def where = [ vc_code: code ] - def id = Numeric.toIntSafe(hid.getTableFirst(getRefsTable(), 'n_ref_id', where)) - if (id) { - REFS_CACHE[code] = id - } + id = Numeric.toIntSafe(hid.getTableFirst(getRefsTable(), 'n_ref_id', where)) + putRefCache(code, id) return id } @@ -152,17 +170,16 @@ trait Ref { String getRefCode(def id) { id = Numeric.toIntSafe(id) - if (REFS_CACHE.containsValue(id)) { - return REFS_CACHE.find{it.value == id}?.key + def code = getRefCodeCached(id) + if (code) { + return code } def where = [ n_ref_id: id ] - def code = hid.getTableFirst(getRefsTable(), 'vc_code', where) - if (code) { - REFS_CACHE[code] = id - } + code = hid.getTableFirst(getRefsTable(), 'vc_code', where) + putRefCache(code, id) return code } diff --git a/src/org/camunda/latera/bss/utils/Oracle.groovy b/src/org/camunda/latera/bss/utils/Oracle.groovy index 339aa8fb..ab4d3f25 100644 --- a/src/org/camunda/latera/bss/utils/Oracle.groovy +++ b/src/org/camunda/latera/bss/utils/Oracle.groovy @@ -41,7 +41,7 @@ class Oracle { } static Boolean decodeFlag(value) { - return value == 1 + return value.toString() == '1' } static Object nvl(nullable, replacement, args = []) {