Database Reference
In-Depth Information
This produces:
Basic
Xchgrate
Interntl
At this point, Java developers who have worked with the JAPI may begin snapping their
pencils in surprise. Interacting with Essbase, in particular looping over JAPI collections,
is not supposed to be this easy, but groovy makes it so. First off, getApplication returns
an object of type IEssolapApplication, which does not even have a cubes property, it has
a getCubes method. Further, getCubes returns an IEssIterator, which does not have an all
property, either; similarly, it has a getAll method. yet, we seem to be using these prop-
erties. groovy has automatically added them to the objects based on finding the native
methods and seeing that they match a certain pattern. using these properties makes our
code very expressive and powerful, but also very readable. now, of course we did not have
to use the cubes and all properties. Calls to the native methods would have been fine.
Another item to note is how we use the return value of the all property, or the getAll
method that it aliases. The return value is documented as a plain Java array, which has
no built-in iteration methods. groovy, however, automatically adds its powerful itera-
tors to every array it finds, allowing us to proceed directly from the all property to an
each method, and our looping construct is built in a single line. This is much clearer and
easier than what the JAPI natively allows. This can be seen by comparing what we have
written above to the sample Java code that is provided with the API.
Groovy makes working with existing Java classes easier by inspecting them and adding enhancements. Any method with
the form getSomething() or setSomething(value) can be called as if they are properties of the class by removing the 'get'
or 'set' from the beginning and changing the initial capital letter of what remains to lower case. Java collection classes
also automatically receive Groovy's powerful iteration methods, such as each, any, and find.
9.3.4 Step Four: Retrieving Dimensions
now that we are getting Sample and a list of its databases from Essbase, let's go one step
farther and get the dimensions from the databases. All we have to do is expand the body
of the closure that we are running against every cube. now it will list not only the name
of the cube, but also the names of its dimensions.
import com.essbase.api.session.IEssbase
essHome = IEssbase.Home.create(IEssbase.JAPI_VERSION)
essSvr = essHome.signOn('user', 'pass', false, null,
'http://aps_server:13080/aps/JAPI', 'ess_server')
essSvr.getApplication('Sample').cubes.all.each { essCube ->
println essCube.name + ':'
essCube.dimensions.all.each { println it.name }
essCube.clearActive()
}
essSvr.disconnect()
essHome.signOff()
This produces (edited for brevity):
Basic:
Year
Search WWH ::




Custom Search