Database Reference
In-Depth Information
MaxLOut = mshExec('display database $1.$2;', ['Sample','Basic']) //
passing in args
parseMaxLDisplayX(MaxLOut).each{ println "Sample.Basic has ${it.
number_dimensions} dimensions!" }
MaxLOut = mshExec('display application all;',[]) // multi-item
display
parseMaxLDisplayX(MaxLOut).each{ println "${it.application} has
${it.number_of_databases} database(s)!" }
Included here is a function that parses the output from maxL “display” commands
and returns a list of maps. Each map in the list contains key-value pairs drawn from the
text table embedded in maxL's output string. The parsing function is useful for either
technique of running maxL commands.
9.5.11 Using Command Line Arguments and Config File Settings
many of our scripts will benefit from the ability to accept settings from the outside
world, whether through command line arguments or by loading settings from files.
We can generalize script to do both of these things. It seems reasonable to accept com-
mand line arguments for the server, user, password, application, database, and calc
script. It also makes sense only to enable server, user, and password to come from a
file. groovy provides classes named CliBuilder and ConfigSlurper, which make these
tasks easy. This recipe shows how to use them to load settings for the script and, while
we are at it, we will let the script accept a list of multiple calc scripts to be run on the
same database.
First, we need to place the following code in a file called essConfig.groovy.
essUser='user'
essPass='pass'
environments {
prod {
essSvrName='prod_ess_server'
}
dev {
essSvrName='dev_ess_server'
}
}
This config file has a nested, tree-like structure. The section at the top contains default
values while the lower section defines values that apply to specific “environments.” This
way, we can have multiple possible configurations defined in one file. Config files can be
much more complex than this one. They can be nested more deeply and can even return
objects instead of just simple values.
The following code sets up a command line interface and accesses the config settings
from the file above to be able to run any calc script on any database.
import com.essbase.api.session.IEssbase
def cs = new ConfigSlurper('dev').parse(new File('essConfig.
groovy').toURL())
Search WWH ::




Custom Search