sábado, 15 de fevereiro de 2014

Accessing ViewObjectImpl sample methods trough Groovy

Hi!

Here are two ViewObjectImpl sample methods, one using direct Where Clause modification and another one using ViewCriteriaRow API:

Class br.com.home.view.JobsVOImpl.getJobWithMinimumSalary()

    private static ADFLogger LOGGER =
               ADFLogger.createADFLogger(JobsVOImpl.class);
    private String minimumSalaryWhereClause = "MIN_SALARY IN (SELECT MIN(MIN_SALARY)\n" +
                                              "                 FROM HR.JOBS)\n" +
                                              "       AND ROWNUM = 1";
    private String minimumSalaryWhereClauseVC = "SELECT MIN(MIN_SALARY)\n" +
                                                "  FROM HR.JOBS\n";

    public String getJobWithMinimumSalary() {
        setWhereClause(minimumSalaryWhereClause);
        LOGGER.warning("WHERE clause -> " + this.getWhereClause());
        executeQuery();

        String jobId = "SH_CLERK";
        if (first() != null) {
           jobId = (String)first().getAttribute("JobId");
        }
        LOGGER.warning("Selected JobId -> " + jobId);
        setWhereClause(null);
        LOGGER.warning("WHERE being reseted -> " + this.getWhereClause());

        return jobId;

    }

    public String getJobWithMinimumSalaryVCVersion() {
        ViewCriteria minimumSalaryVc = createViewCriteria();
        ViewCriteriaRow vcRow = minimumSalaryVc.createViewCriteriaRow();
        ViewCriteriaItem criteriaItem = vcRow.ensureCriteriaItem("MinSalary");
        criteriaItem.setOperator(JboCompOper.OPER_IN);
        criteriaItem.setIsSqlFragment(true);
        criteriaItem.setValue(minimumSalaryWhereClauseVC);
        minimumSalaryVc.add(vcRow);
        applyViewCriteria(minimumSalaryVc);
        executeQuery();

        return (String)first().getAttribute("JobId");
    }

Two methods that does exactly the same thing but with slightly different approach. After that suppose that you want to populate the JobId attribute in Employees View Object with the previous created method return:
adf.source.getApplicationModule().findViewObject("JobsVO1").getJobWithMinimumSalary();

Don't forget to mark the Default Value indicator as "Expression", that will take care of Groovy interpretation process. Run trough AppModule tester to see runtime generated queries of both methods.

Nenhum comentário:

Postar um comentário