Groovy 与否,我是按照以下方式完成的,请提供更好的答案,我会接受!
首先,我构建以下结构:
Map packages = new LinkedHashMap()
class Package {
String name
Map functions = [:]
}
class Function {
String name
String returnType
boolean isFunction = false
Map parameters = [:]
}
class Parameter {
String name
String dataType
String inOut
}
然后我读了
sql.eachRow("""\
select PACKAGE_NAME, OBJECT_NAME, POSITION, ARGUMENT_NAME, DATA_TYPE, IN_OUT
from USER_ARGUMENTS
order by PACKAGE_NAME, OBJECT_NAME, POSITION""")
{
// create or get package
def thePackage = packages[it.PACKAGE_NAME ?: '']
if (thePackage == null) {
thePackage = new Package(name : it.PACKAGE_NAME ?: '')
packages[it.PACKAGE_NAME ?: ''] = thePackage
}
// create or get function
def theFunction = thePackage.functions[it.OBJECT_NAME ?: '']
if (theFunction == null) {
theFunction = new Function(name: it.OBJECT_NAME ?: '')
thePackage.functions[it.OBJECT_NAME ?: ''] = theFunction
}
// Position 0 is the return value
if (it.POSITION == 0) {
theFunction.isFunction = true
theFunction.returnType = it.DATA_TYPE
}
else {
// create the argument
def theParameter = new Parameter(
name: it.ARGUMENT_NAME, dataType: it.DATA_TYPE, inOut: it.IN_OUT)
theFunction.parameters[it.ARGUMENT_NAME ?: ''] = theParameter
}
}