Skip to content

Commit

Permalink
Use functions for cache in ref and getTableColumns in hid class
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Jun 21, 2019
1 parent e1d6042 commit 7fed977
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
43 changes: 26 additions & 17 deletions src/org/camunda/latera/bss/connectors/hid/Table.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
47 changes: 32 additions & 15 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Ref.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package org.camunda.latera.bss.connectors.hid.hydra

import org.camunda.latera.bss.utils.Numeric

trait Ref {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/camunda/latera/bss/utils/Oracle.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Oracle {
}

static Boolean decodeFlag(value) {
return value == 1
return value.toString() == '1'
}

static Object nvl(nullable, replacement, args = []) {
Expand Down

0 comments on commit 7fed977

Please sign in to comment.