Thursday, June 10, 2010

Groovy String Operations in Oracle ADF 11g

Groovy Script support by Oracle ADF 11g gives us good flexibility to operate attribute values and implement business logic. Often you need to parse String type attribute values - it can be easily done using Groovy script directly in ADF BC.

Download sample application - This sample implements validation rule for Salary attribute:

Validation logic is pretty basic, it compares old and new values, if attribute value was changed - it fails:

Now is interesting part - validation execution rule. Here I'm calling substring() method for String type Salary attribute directly in Groovy script. If JobId of current employee starts with IT, only then validation rule is triggered:

I can use toUpperCase() method as well. Using Groovy, LastName attribute is converted to upper case:

On runtime, String type attributes are successfully parsed, validation rule is invoked and it prints LastName in upper case:

Special thanks for researching this, going to my colleague - Inno from Soweto :)


Hasim said...

Hey dude,

Looks you are enjoying FIFA.

Nice Post as always.


Andrej Baranovskij said...

Yes - football fever :)


Unknown said...

I have a query in the field of Business Components
how to assign a default value, the result of a sql query, an attribute of an entity (EO).

entity: Comprobantesgasto.
attributes: cgid, noejercicio, noentrada,........

the default noejercicio attribute is the result of a query, eg select max (Ej.ejercicio) from Ejercicio Ej WHERE Ej.Activo = 'S', where the Ejercicio table contains information relating to Ejercicio = years May be more than one year active at any given time.

P. D. excuse my English
thank you very much. Greetings

Andrej Baranovskij said...

Hi Luciano,

You can try to put SQL statement into Expression field of VO attribute.


Unknown said...

Excuse my ignorance, Andrejus.

In the View Object (CgcompronabegastoView), I have to edit the attribute Ejercicio, and in the area of "Query Column" complete the Expression of this with my Sql Query. I have to edit a property more?,
probe this in the attribute, and does not store my sql query in the area "Query Column" in the view Object (VO).

Then, also edit the attribute of the Entity, enable the check box: "Derived from SQL Expression" and update the "Expression" in the area "SQL Expression" in the SQL Query. This allows you to store the SQL query in the View object, the first idea previously described above.

This configuration in the entity, results in the value of attribute "Ejercicio" is the same as the result of my SQL query (Select max(Ejercicio) .....), running the AppModules. I'm not property or to modify and test values in the Entity / View, with this idea to solve this.

I think your observation of work on the View, to obtain the solution is correct, does not probe with Groovy and such functions. Ej: #RowSetAttr.max(GroovyExpr), also could be a solution.

For this particular case of Assignment of default values to an "Attribute Of An Entity", as the result of an SQL query, I did not find much information, only referenced in Chapter 6: Specifying a Business Domain, How Do You Implement Attribute defaulting and Calculation? - Oracle Jdeveloper 11 - HandBook.

I ask if you remember such information or referred to such Assignment of default values. from already thank you very much

Andrej Baranovskij said...

You should use your SQL statement on expression field of VO attribute. Thats the way to go.

There is no point to use Groovy for SQL select to get default value.


Unknown said...

Andrejus hello, I still have the problems as
Do not save the SQL in the area of "Query Column" in the "Expression" of the VO.
It is the right place to write my SQL query?
my SQL query, the I write with a particular format or PL-SQL?
from already thank you very much.