Skip to main content

Groovy expression for assigning DB Sequence value to a String type attribute

You can use Groovy expression to default value for  Key attribute from a database sequence while you create new instance of an entity object. If you have access to my book Oracle ADF Real World Developer’s Guide, see page 76 for details or see the following blog from Timo Hahn  http://tompeez.wordpress.com/2011/09/02/using-groovy-expression-to-set-a-primary-key-with-a-sequence-number/

This post is just meant for sharing a simple tip that I learned today(Thanks to Steve Muench) for assigning database sequence value to a String type attribute. In case if you need to assign the sequence value to an attribute of type String in an entity object(yes, there are such use cases as well), you can add "as String" to the end of the Groovy expression and set it as default value for the entity attribute.

Example:
(new oracle.jbo.server.SequenceImpl("DEPARTMENTS_SEQ", adf.object.getDBTransaction())).getSequenceNumber() as String

Comments

Popular posts from this blog

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…