Thursday, November 21, 2013

How to invoke Stored Procedure from a package, Convert the response to POJO using Java

This blog explains about invoking a stored procedure from a package and convert the stored procedure response back to POJO(Plain Old Java Object) using Java

- Below is the Java class, which connects to database, execute stored procedure from a package, Convert the response to List of POJO's
       

      /**
     * Invoke Stored Procedure from a package
     * Iterate the result from Stored Procedure, populate the response to
     * Employee POJO class.
     * @param eName
     * @return
     * @throws Exception
     */
    public static List getEmployees(String eName) throws Exception {
        List empList = new ArrayList();
        Connection dbConnection = null;
        CallableStatement callableStatement = null;
        ResultSet rs = null;
        String empSql = "{call employee_pkg.getEmployees(?,?)}";
        try {
            dbConnection = getDBConnection();
            callableStatement = dbConnection.prepareCall(empSql);
            callableStatement.setString(1, eName);
            callableStatement.registerOutParameter(2, OracleTypes.CURSOR);
            callableStatement.executeUpdate();
            rs = (ResultSet)callableStatement.getObject(2);
            while (rs.next()) {
                Employee emp = new Employee();
                emp.setEmpNo(rs.getInt("empno"));
                emp.setEmpName(rs.getString("empname"));
                emp.setEmpSal(rs.getInt("sal"));
                empList.add(emp);
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        } finally {
            if (rs != null) {
                rs.close();
            }
            if (callableStatement != null) {
                callableStatement.close();
            }
            if (dbConnection != null) {
                dbConnection.close();
            }
        }
        return empList;
    }
       
 
- Here is Employee POJO class
       

  public class Employee 
{
 private int empNo;
 private String empName;
 private int empSal;
 
 public int getEmpNo() 
 {
  return empNo;
 }
 public void setEmpNo(int empNo) 
 {
  this.empNo = empNo;
 }
 public String getEmpName() 
 {
  return empName;
 }
 public void setEmpName(String empName) 
 {
  this.empName = empName;
 }
 public int getEmpSal() 
 {
  return empSal;
 }
 public void setEmpSal(int empSal) 
 {
  this.empSal = empSal;
 }
}


       
 

- Here is sample Stored Procedure
       

  
CREATE OR REPLACE PACKAGE employee_pkg AS
  TYPE employee_cur IS REF CURSOR RETURN employees%rowtype;
  PROCEDURE getEmployees (ename IN VARCHAR2, empData OUT employee_cur);
END employee_pkg;
/

CREATE OR REPLACE PACKAGE BODY employee_pkg AS 
  PROCEDURE getEmployees (ename IN VARCHAR2, empData OUT employee_cur) AS
  BEGIN
    OPEN empData FOR
 SELECT empno, empname, sal FROM employees WHERE empname = ename ORDER BY empno;
  END getEmployees;  
END employee_pkg;
/
       
 

Tuesday, November 12, 2013

How to Create Popup Using ADF

This blog explains about creating a simple popup using ADF

Scenario : Display a popup by clicking on button

Implementation

 - Drag the 'popup' component from component pallet to page/page fragment
 - Drag the 'dialog' component from the component pallet to page/page fragment
 - You can define whatever components you want on this dialog, Even you can drag the taskflow as a region on it.
- Below is how source code looks like



- Drag the 'ShowPopupBehavior' component from the component pallet on to 'button'
- Define the popupId attribute, In this example, popup ID value is 'p1' as per above screen shot.

- Run the page, you will see the button as shown below

- Click on the button, below is the screenshot for popup window how it displayed



Below section explains, about how you can invoke popup programatically based on some condition

// Below is the code to get the RichPopup component in backing bean

            RichPopup popup =
                (RichPopup)JSFUtils.findComponent("p1");
            if (popup != null) {
                  // Hid the popup
                  popup.hide();
            }

             // Here is the code to show popup.
             popup.show(new RichPopup.PopupHints());

// Define <af:outputText> in <af:dialog> and bind the value of this property to backing bean, and set whatever message you want to display based on some specific condition in backing bean.

Also, You can bind the 'title' attribute of <af:dialog> component to backing bean , Get the dialog component using findComponent() method and set whatever the title you want to display.

popupFetchListener : Bind this attribute to any backing bean method in order to invoke any functionality while loading the popup

dialoglistener : This attribute belongs to <af:dialog> component, Bind this attribute to any backing bean method , in order to execute code upon any action(Ok, Cancel, Yes, No, etcc)  performed on a popup

 public void doCancel(DialogEvent dialogEvent) {
        Outcome outcome = dialogEvent.getOutcome();
        if (Outcome.yes == outcome) {
            
        }
    }

How to programatically hide and show the popup in ADF ?

 - Get the Popup UI component instance i.e RichPopup
 - empPopup.show(new RichPopup.PopupHints());
- To Hide : empPopup.hide()


Refer below blog for findComponent() implementation


- You can customize the popup the way you want, mouse hover, value change, on focus, etc..

Here is more documentation about popup

http://docs.oracle.com/cd/E21764_01/apirefs.1111/e12419/tagdoc/af_showPopupBehavior.html

http://docs.oracle.com/cd/E17904_01/apirefs.1111/e12419/tagdoc/af_popup.html

ADF Naming Standards and Best Practices

Naming Standards are very important to organize the code, especially when you are working with large scale applications. Below are the naming conventions based on JUST my past experience


Business Components

  Entity                                  - Suffix with 'EO' - example : EmployeeEO
  Updateable View Object      - Suffix with 'VO' - example : EmployeeVO
  Programmatic View Object  - Suffix with 'TRVO' example : EmployeeTRVO
  ReadOnly View Object        -  Suffix with 'ROVO' example : EmployeeROVO
  List of Values View Object  -  Suffix with 'LOV' example : GenderLOV
  View Link                            - Suffix with 'VL' example : EmployeeDepartmentVL
   Association                         - Suffix with 'Assoc' Example : EmployeeDepartmentAssoc
  View Accessor                    - Suffix with 'VA' Example :  EmployeeNameVA
  Application Module               - Suffix with 'Service' example : EmployeeService

Packaging

Entities                            :     com.<application>.<project>.model.entities
Updateable View Object :     com.<application>.<project>.model.queries    
Application Module         :      com.<application>.<project>.model.services           
Programmatic View Object :     com.<application>.<project>.model.trvo
View Link                          :    com.<application>.<project>.model.vl
Association                        :    com.<application>.<project>.model.assoc
Read only View Object      :    com.<application>.<project>.model.readonly

Application Naming 
- Giver proper name to application , For eg : EmployeeMgmt, CustomerMgmt, VendorMgmt, etc.. The name of the application should be meaningful with respect to the functionality

Project Naming
 - Give meaningful name to each project you create in any application
 - Model Project :
   Example : EmployeeModel, CustomerModel,VendorModel - All the model projects suffix with 'Model'
- View Controller Project : 
 Example : EmployeeUI, CustomerUI, VendorUI - This project holds all the User Interface related components such as .jsff, jspx, xml, etc..

- Web Service Projects
 Example : EmployeeWSService, CustomerWSService, VendorWSService - All these projects contains the web services related.

- Web Service Proxies
Example : EmployeeWSProxies, VendorWSProxies, CustomerWSProxies - All these projects contains the web service proxy related files.

- JSP Pages

Example : create-employee.jspx, edit-employee-job-details.jspx - Give meaningful name, all lower case , better if seperated by '-'

- Page Fragments (.jsff)
Same as JSP Pages

- Task Flow
- Meaningful name separated by '-' and prefix with config.xml
   Ex : create-employee-config.xml , edit-employee-job-details-config.xml

Backing Bean

- Give meaningful name such as 'EmployeeBean', 'CustomerBean', 'VendorBean' etc.
- Package : com.fm.helloworld.view.backing.EmployeeBean
- Every bean class must implement java.io.Serializable interface.
- Try to avoid binding any ADF UI components to Backing beans

Best Practices
- Define entry and exit log messages as shown below

import java.util.logging.Level;
import java.util.logging.Logger;

// Define below at class level

private static final String CLAZZ_NAME = EmpServiceImpl.class.getName();
private static final Logger _logger = Logger.getLogger(CLAZZ_NAME);

 public void runPublication()
  {
    String methodName = "runPublication()";
    _logger.entering(CLAZZ_NAME, methodName);
    _logger.exiting(CLAZZ_NAME, methodName);
  }
// Log Exceptions as below
      _logger.logp(Level.FINEST, CLAZZ_NAME, methodName,

                   message.toString(), pException);
// Log Information messages as below
              _logger.logp(Level.FINEST, CLAZZ_NAME, lMethodName,
                           " Invoking  updateRates() CORBA Call: Data List Size " +
                           newDataList.size());
Follow this link for better performance tips and best practices : http://fortunefusionminds.blogspot.com/2011/12/performance-tuning-tips-with-adf-web.html


  

Wednesday, November 6, 2013

How to ignore unwanted files using Tortoise GIT tool


create .gitignore file in your root directory and include required unwated entires there.

For eg : I want to ignore all the class files in Model project

/EmployeeManagement/EmpModel/classes
*.obj
*.class

This will exclude displaying these files before you check-in.

Tuesday, November 5, 2013

How to Configure Data Source in Weblogic Console


This blog explains about creating a data source in Web logic console. ADF Applications can use this data source reference in Application Module configurations, and when the application deployed to Web logic console, ADF application will connect to database using the Data source which is defined in Web Logic Console

Implementation

 - Ensure, Weblogic server is up and running , Login to Weblogic Console, Choose Services as shown below, Click on 'Data Sources'

- Choose New -> Generic Data Source as shown below.

- Enter valid name and JNDI Name as shown below

- Choose the Database driver based on the database which you are going to connect.

- Enter the valid values for Database name, Host Name, Port , User Name and Password as shown below

- Choose Next, then verify all the details, Test the DB details by clicking on 'Test Conifguration' button as shown below.

- Finally choose the targets where you want to use the data source.

- You have successfully conrigured data source.