Skip to content

Commit

Permalink
Limit SELECT results for getEnityBy methods in hid.Hydra
Browse files Browse the repository at this point in the history
Improves performance of getTableFirst queries
  • Loading branch information
dolfinus committed Jun 29, 2019
1 parent 1cad6b6 commit 50497cd
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 147 deletions.
27 changes: 16 additions & 11 deletions src/org/camunda/latera/bss/connectors/HID.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ class HID implements Table {
this.proxy.setBasicAuth(this.user, this.password)
}

List queryDatabase(CharSequence query, Boolean asMap = false, Boolean noLimit = false) {
List queryDatabase(CharSequence query, Boolean asMap = false, Integer limit = 0, Integer page = 1) {
List result = []
Integer pageNumber = noLimit ? 0 : 1
LinkedHashMap answer = this.proxy.invokeMethod('SELECT', [query.toString(), pageNumber])
if (limit != 0 && limit != null) {
query = """SELECT * FROM (
${query}
)
WHERE ROWNUM <= 1"""
}
LinkedHashMap answer = this.proxy.invokeMethod('SELECT', [query.toString(), page])
List rows = answer.SelectResult
if (rows) {
rows.each{ row ->
Expand Down Expand Up @@ -57,16 +62,16 @@ class HID implements Table {
return result
}

List queryDatabaseList(CharSequence query, Boolean noLimit = false) {
return queryDatabase(query, false, noLimit)
List queryDatabaseList(CharSequence query, Integer limit = 0, Integer page = 1) {
return queryDatabase(query, false, limit, page)
}

List queryDatabaseMap(CharSequence query, Boolean noLimit = false) {
return queryDatabase(query, true, noLimit)
List queryDatabaseMap(CharSequence query, Integer limit = 0, Integer page = 1) {
return queryDatabase(query, true, limit, page)
}

def queryFirst(CharSequence query, Boolean asMap = false, Boolean noLimit = false) {
List result = this.queryDatabase(query, asMap)
def queryFirst(CharSequence query, Boolean asMap = false) {
List result = this.queryDatabase(query, asMap, 1)

if (result) {
return result.getAt(0)
Expand All @@ -75,11 +80,11 @@ class HID implements Table {
}
}

List queryFirstList(CharSequence query, Boolean noLimit = false) {
List queryFirstList(CharSequence query) {
return queryFirst(query, false, noLimit)
}

Map queryFirstMap(CharSequence query, Boolean noLimit = false) {
Map queryFirstMap(CharSequence query) {
return queryFirst(query, true, noLimit)
}

Expand Down
22 changes: 13 additions & 9 deletions src/org/camunda/latera/bss/connectors/hid/Table.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait Table {
private static LinkedHashMap DEFAULT_WHERE = [:]
private static LinkedHashMap DEFAULT_ORDER = [:]
private static List DEFAULT_FIELDS = null
private static Integer DEFAULT_LIMIT = 0

List getTableColumns(CharSequence tableName, CharSequence tableOwner = 'AIS_NET') {
String tableFullName = "${tableOwner}.${tableName}"
Expand All @@ -24,7 +25,7 @@ trait Table {
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = '${tableName}'
AND OWNER = '${tableOwner}'
""", false, true)
""", false, 0, 0)

columnsList = result*.getAt(0) // get only first column values
return TableColumnCache.instance.putAndGet(tableFullName, columnsList)
Expand All @@ -34,7 +35,8 @@ trait Table {
CharSequence tableName,
fields = DEFAULT_FIELDS,
Map where = DEFAULT_WHERE,
order = DEFAULT_ORDER
order = DEFAULT_ORDER,
Integer limit = DEFAULT_LIMIT
) {
String query = "SELECT"

Expand Down Expand Up @@ -97,26 +99,28 @@ trait Table {
}
}
}
return queryDatabase(query, true)
return queryDatabase(query, true, limit)
}

List getTableData(Map options, CharSequence tableName) {
LinkedHashMap params = [
fields : DEFAULT_FIELDS,
where : DEFAULT_WHERE,
order : DEFAULT_ORDER
order : DEFAULT_ORDER,
limit : DEFAULT_LIMIT
] + options
return getTableData(tableName, params.fields, params.where, params.order)
return getTableData(tableName, params.fields, params.where, params.order, params.limit)
}

List getTableData(Map input) {
LinkedHashMap params = [
tableName : '',
fields : DEFAULT_FIELDS,
where : DEFAULT_WHERE,
order : DEFAULT_ORDER
order : DEFAULT_ORDER,
limit : DEFAULT_LIMIT
] + input
return getTableData(params.tableName, params.fields, params.where, params.order)
return getTableData(params.tableName, params.fields, params.where, params.order, params.limit)
}

def getTableFirst(
Expand All @@ -126,9 +130,9 @@ trait Table {
order = DEFAULT_ORDER
) {
if (isString(fields) && fields != '*') {
return getTableData(tableName, [fields], where, order)?.getAt(0)?."${fields}"
return getTableData(tableName, [fields], where, order, 1)?.getAt(0)?."${fields}"
}
return getTableData(tableName, fields, where, order)?.getAt(0)
return getTableData(tableName, fields, where, order, 1)?.getAt(0)
}

def getTableFirst(Map options, CharSequence tableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ trait Account {
number : null,
maxOverdraft : null,
rem : null,
firmId : getFirmId()
firmId : getFirmId(),
limit : 0
], input)
LinkedHashMap where = [:]

Expand Down Expand Up @@ -79,11 +80,11 @@ trait Account {
if (params.firmId) {
where.n_firm_id = params.firmId
}
return hid.getTableData(getAccountsTable(), where: where)
return hid.getTableData(getAccountsTable(), where: where, limit: params.limit)
}

Map getAccountBy(Map input) {
return getAccountsBy(input)?.getAt(0)
return getAccountsBy(input + [limit: 1])?.getAt(0)
}

Map getAccount(def accountId) {
Expand Down
31 changes: 18 additions & 13 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Address.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ trait Address {
isMain : null,
operationDate : null,
beginDate : null,
endDate : null
endDate : null,
limit : 0
], input)

LinkedHashMap where = [:]
Expand Down Expand Up @@ -150,18 +151,19 @@ trait Address {
String oracleDate = encodeDateStr(params.operationDate)
where[oracleDate] = [BETWEEN: "D_BEGIN AND NVL(D_END, ${oracleDate})"]
}
return hid.getTableData(getObjectAddressesTable(), where: where, order: ['C_FL_MAIN DESC'])
LinkedHashMap order = [c_fl_main: 'desc']
return hid.getTableData(getObjectAddressesTable(), where: where, order: order, limit: params.limit)
}

Map getObjAddressBy(Map input) {
return getObjAddressesBy(input)?.getAt(0)
return getObjAddressesBy(input + [limit: 1])?.getAt(0)
}

Map getObjAddress(def objAddressId) {
LinkedHashMap where = [
n_obj_address_id: objAddressId
]
return hid.getTableData(getObjectAddressesTable(), where: where)
return hid.getTableFirst(getObjectAddressesTable(), where: where)
}

List getSubjAddressesBy(Map input) {
Expand All @@ -180,7 +182,8 @@ trait Address {
rem : null,
bindAddrTypeId : getDefaultAddressBindTypeId(),
stateId : getDefaultAddressStateId(),
isMain : null
isMain : null,
limit : 0
], input)

LinkedHashMap where = [:]
Expand Down Expand Up @@ -229,18 +232,19 @@ trait Address {
if (params.isMain != null) {
where.c_fl_main = encodeBool(params.isMain)
}
return hid.getTableData(getSubjectAddressesTable(), where: where, order: ['C_FL_MAIN DESC'])
LinkedHashMap order = [c_fl_main: 'desc']
return hid.getTableData(getSubjectAddressesTable(), where: where, order: order, limit: params.limit)
}

Map getSubjAddressBy(Map input) {
return getSubjAddressesBy(input)?.getAt(0)
return getSubjAddressesBy(input + [limit: 1])?.getAt(0)
}

Map getSubjAddress(def subjAddressId) {
LinkedHashMap where = [
n_subj_address_id: subjAddressId
]
return hid.getTableData(getSubjectAddressesTable(), where: where)
return hid.getTableFirst(getSubjectAddressesTable(), where: where)
}

List getEntityAddressesBy(Map input) {
Expand Down Expand Up @@ -279,7 +283,7 @@ trait Address {
}

Map getEntityAddressBy(Map input) {
return getEntityAddressesBy(input)?.getAt(0)
return getEntityAddressesBy(input + [limit: 1])?.getAt(0)
}

Map getEntityAddress(def entityOrEntityTypeId, def entityAddressId) {
Expand Down Expand Up @@ -341,11 +345,12 @@ trait Address {
if (params.rem) {
where.vc_rem = params.rem
}
return hid.getTableData(getMainAddressesTable(), where: where, order: ['N_ADDRESS_ID ASC'])
LinkedHashMap order = [n_address_id: 'desc']
return hid.getTableData(getMainAddressesTable(), where: where, order: order, limit: params.limit)
}

Map getAddressBy(Map input) {
return getAddressesBy(input)?.getAt(0)
return getAddressesBy(input + [limit: 1])?.getAt(0)
}

Map getAddress(def addressId) {
Expand Down Expand Up @@ -1046,10 +1051,10 @@ trait Address {
Number getSubnetIdByIP(CharSequence ip) {
def subnetId = null
try {
subnetId = hid.queryFirst("""
subnetId = toIntSafe(hid.queryFirst("""
SELECT SI_ADDRESSES_PKG_S.GET_SUBNET_BY_IP_ADDRESS('$ip')
FROM DUAL
""")?.getAt(0)
""")?.getAt(0))
} catch (Exception e){
logger.error_oracle(e)
}
Expand Down
11 changes: 6 additions & 5 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Bill.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ trait Bill {
discountDocId : null,
operationDate : null,
beginDate : null,
endDate : null
endDate : null,
limit : 0
], input)
LinkedHashMap where = [:]

Expand Down Expand Up @@ -193,19 +194,19 @@ trait Bill {
where[oracleDate] = [BETWEEN: "D_BEGIN AND NVL(D_END, ${oracleDate})"]
}
LinkedHashMap order = [n_line_no: 'asc']
return hid.getTableData(getBillLinesTable(), where: where, order: order)
return hid.getTableData(getBillLinesTable(), where: where, order: order, limit: params.limit)
}

List getBillLines(def docId) {
List getBillLines(def docId, Integer limit = 0) {
LinkedHashMap where = [
n_doc_id : docId,
n_move_type_id : ['not in': [getChargeCanceledTypeId()]]
]
return hid.getTableData(getBillLinesTable(), where: where)
return hid.getTableData(getBillLinesTable(), where: where, limit: limit)
}

Map getBillLineBy(Map input) {
return getBillLinesBy(input)?.getAt(0)
return getBillLinesBy(input + [limit: 1])?.getAt(0)
}

Map getBillLine(def lineId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ trait Company {
opfId : null,
groupId : null,
firmId : getFirmId(),
stateId : getSubjectStateOnId()
stateId : getSubjectStateOnId(),
limit : 0
], input)
LinkedHashMap where = [:]

Expand Down Expand Up @@ -96,11 +97,11 @@ trait Company {
if (params.stateId) {
where.n_subj_state_id = params.stateId
}
return hid.getTableData(getCompaniesTable(), where: where)
return hid.getTableData(getCompaniesTable(), where: where, limit: params.limit)
}

Map getCompanyBy(Map input) {
return getCompaniesBy(input)?.getAt(0)
return getCompaniesBy(input + [limit: 1])?.getAt(0)
}

Boolean isCompany(CharSequence entityType) {
Expand Down
16 changes: 9 additions & 7 deletions src/org/camunda/latera/bss/connectors/hid/hydra/Customer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ trait Customer {
firmId : getFirmId(),
resellerId : getResellerId(),
stateId : getSubjectStateOnId(),
tags : null
tags : null,
limit : 0
], input)
LinkedHashMap where = [:]

Expand Down Expand Up @@ -186,11 +187,11 @@ trait Customer {
if (params.tags) {
where.t_tags = params.tags
}
return hid.getTableData(getCustomersTable(), where: where)
return hid.getTableData(getCustomersTable(), where: where, limit: params.limit)
}

Map getCustomerBy(Map input) {
return getCustomersBy(input)?.getAt(0)
return getCustomersBy(input + [limit: 1])?.getAt(0)
}

Boolean isCustomer(CharSequence entityType) {
Expand Down Expand Up @@ -372,7 +373,8 @@ trait Customer {
login : null,
password : null,
passwordHash : null,
hashTypeId : null
hashTypeId : null,
limit : 0
], input)
LinkedHashMap where = [
c_active: encodeBool(true)
Expand Down Expand Up @@ -408,11 +410,11 @@ trait Customer {
if (params.hashTypeId) {
where.n_hash_type_id = hashTypeId
}
return hid.getTableData(getCustomerNetServicesTable(), where: where)
return hid.getTableData(getCustomerNetServicesTable(), where: where, limit: params.limit)
}

Map getCustomerNetServiceAccessBy(Map input) {
return getCustomerNetServicesAccessBy(input)?.getAt(0)
return getCustomerNetServicesAccessBy(input + [limit: 1])?.getAt(0)
}

Map putCustomerNetServiceAccess(Map input) {
Expand Down Expand Up @@ -522,7 +524,7 @@ trait Customer {
}

Map getCustomerAppAccessBy(Map input) {
return getCustomerAppsAccessBy(input)?.getAt(0)
return getCustomerAppsAccessBy(input + [limit: 1])?.getAt(0)
}

Map putCustomerAppAccess(Map input) {
Expand Down
Loading

0 comments on commit 50497cd

Please sign in to comment.