Wednesday 7 January 2015

create ViewObject in runtime

Usually, during ADF development, you create view objects at the design time. Using java call it is possible to create them also in runtime. The code will describe itself, so don't waste time and:

ViewObject vo = getDBTransaction().getRootApplicationModule().createViewObjectFromQueryStmt("tempDynamicVo", "select 1 from dual");
System.out.println("fitst selected attribute from the first row is: "+ vo.first().getAttribute(0));


And that's it. The VO is there and can be accessed in different part of the code as those designed in common way.

ViewObject vo = findViewObject("tempDynamicVo");
System.out.println("fitst selected attribute from the first row is: "+ vo.first().getAttribute(0));


Because it's dynamic, it doesn't obscure the Data Control and other developer won't use it in their part of the design.

The view object name must be unique. Depends on your use case it may be consider as a best practice to clean it after data consumption. Just call:

vo.remove();

The use cases? There are, the simpliest one is an execution of stored function in the database:

select my_stored_funct(:myBindVar) from dual


Runtime VO approach sounds more BC4J than plain PreparedStatement calls. At least you've got an alternative way to implement it :)