Home » Java » Enterprise Java » Read-only ViewObject and Declarative SQL mode

About Eugene Fedorenko

Read-only ViewObject and Declarative SQL mode


The declarative SQL mode is considered to be one of the most valuable advantages of the entity-based view objects. In this mode the VO’s SQL is generated at runtime depending on the attributes showed in UI. For example, if some page contains a table with only two columns EmployeeId and FirstName, then the query will be generated as “select Employee_ID, First_Name from Employees”. This feature can significantly improve the performance of ADF application. But what about read-only or SQL-based view objects? JDeveloper doesn’t allow you to choose the SQL mode for SQL-based VOs. ?nly “Expert” mode can be used with no chance to have the query generated on the fly. But everything is possible.

In this post we have an example of some SQL-based view object VEmployees:

Let’s generate View Object Definition class:

We’re going to override some methods:

  public boolean isRuntimeSQLGeneration()
     return true;

  public boolean isFullSql()
      return false;

  //In our case we know exactly the clause FROM
  public String buildDefaultFrom(AttributeDef[] attrDefs,
                                 SQLBuilder builder,
                                 BaseViewCriteriaManagerImpl vcManager)
     return "Employees";

  //Setting "Selected in Query" property for each attribute except PK
  protected void createDef()
     for (AttributeDef at : getAttributeDefs()) 
      if (!at.isPrimaryKey()) 
        ((AttributeDefImpl) at).setSelected(false);   

Actually, that’s it! Let’s test it.

For the page showing the full set of attributes, we have the result:

And generated query (I use ODL analyzer):

For the page with only two attributes we have the following result:

And the query:

The sample application for this post requires JDeveloper and standard HR schema.

Reference: Read-only ViewObject and Declarative SQL mode from our JCG partner Eugene Fedorenko at the ADF Practice blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....


Leave a Reply

Your email address will not be published. Required fields are marked *


Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.