Groovy, a useful dynamic language for the JVM based on Java but adding powerful features you would often see in others scripting languages like Phyton and Ruby. Groovy is part of the ADF Framework, particullary inside the Business Components world. This post will resume some of the most useful line of code when working with ADF BC and a little bit of Groovy.
Remember that before implementing a functionality in you BC, ask yourselve if that could be done using groovy. Below, some common questions developers ask when impleneting a functionality:
– How to call java methods using groovy? It well depends where is your java method declared.
– How to call java method declared in application module from an Entity Object?
You could even access a different application module by calling something like
– How to call java method declared in application module from a View Object?
– How to call java method declared in ViewObjectimpl class?
– How to get max, min, avg, sum or count of an attribute in a ViewObject? Using Aggregate Functions; Groovy will become really handly when you need to calculate some additional information based on an attribute of your ViewObject. You can SUM, COUNT, AVG and get MAX, MIN of one particular attribute. It can be used in the current ViewObject or in its default, a ViewObject accessor using the following syntax to retireve the sum:
<ViewAccessorName>.SUM(“AttributeName”) (for view accessors)
– How to get next DB sequence number using groovy? Just for Entity Level Attribute.
new oracle.jbo.server.SequenceImpl(“YOUR_SEQ”, object.getDBTransaction()).getSequenceNumber()
– How to get a ViewAccessor row by key and get an attribute of it?
oracle.jbo.Key key = new oracle.jbo.Key(“yourKey”); return yourViewAccessor.findByKey(key,1).getAttribute(“yourAttribute”)
– How to use logger in groovy?
Yes! That is also possible. https://blogs.oracle.com/jdevotnharvest/entry/using_adf_logger_with_groovy
– How to get current logged in userName?
– How to get current date?
– How to get current stamp time?
– At entity level custom validation, how to access the EntityObject methods and properties?
using source keyword. E.g source.yourPublicMethodInEntityImpl()
– How to raise an error in Entity Validation?
– Other keywords in Entity Validation Level?
– How to get the ADF Context?
– How to get user session?
Finally, please refer to the following document which will explain at glance all details about groovy in ADF 11g.