Tuesday, July 24, 2007

ADF:Invoking AM methods from the Managed Bean

Pure JSF way:
-------------

FacesContext facesContext=FacesContext.getCurrentInstance();
ExpressionFactory exp=facesContext.getApplication().getExpressionFactory();
MethodExpression getDeptNames = exp.createMethodExpression(facesContext.getELContext(),
"#{bindings.getAllDepts.execute}", null,new Class[]{});
HashMap map=(HashMap)getDeptNames.invoke(facesContext.getELContext(),null);



ADF way:
---------

Packages to be imported

import javax.el.ExpressionFactory;

import javax.faces.application.Application;
import javax.faces.context.FacesContext;

import oracle.adf.model.OperationBinding;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;

Sample Code Snippet:
-------------------
FacesContext fctx = FacesContext.getCurrentInstance();
Application app = fctx.getApplication();
ExpressionFactory exp=fctx.getApplication().getExpressionFactory();

DCBindingContainer bc;
bc = (DCBindingContainer)exp.createValueExpression(fctx.getELContext(),
"#{bindings}",DCBindingContainer.class).
getValue(fctx.getELContext());

//Get Current Row Handle
DCIteratorBinding iter = bc.findIteratorBinding("Emp2Iterator");
Row row = iter.getCurrentRow();
Number empNo = (Number)row.getAttribute("Empno");

//get Access to Method Binding

OperationBinding operation = (OperationBinding)bc.get("printANumber");
operation.getParamsMap().put("data", empNo);
operation.execute();

Thursday, July 19, 2007

PLSQL:Compile invalid DB objects


SET SERVEROUTPUT ON SIZE 1000000
BEGIN
FOR cur_rec IN (SELECT owner,
object_name,
object_type,
DECODE(object_type, 'PACKAGE', 1,
'PACKAGE BODY', 2, 2) AS recompile_order
FROM dba_objects
WHERE object_type IN ('PACKAGE', 'PACKAGE BODY')
AND status != 'VALID'
ORDER BY 4)
LOOP
BEGIN
IF cur_rec.object_type = 'PACKAGE' THEN
EXECUTE IMMEDIATE 'ALTER ' || cur_rec.object_type ||
' "' || cur_rec.owner || '"."' || cur_rec.object_name || '" COMPILE';
ElSE
EXECUTE IMMEDIATE 'ALTER PACKAGE "' || cur_rec.owner ||
'"."' || cur_rec.object_name || '" COMPILE BODY';
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line(cur_rec.object_type || ' : ' || cur_rec.owner ||
' : ' || cur_rec.object_name);
END;
END LOOP;
END;
/