Wednesday, July 29, 2015

JDeveloper Memory And Performance

As a general rule, Java is optimized for throughput, not latency. Once the garbage collector kicks in, performance drops like a rock. A 2 second pause every once in a while is OK for a server, but for an IDE it's misery. So here's the fix:


  1. Go to your JDeveloper root directory, is should be something like C:\Oracle\jdev\Middleware\jdeveloper
  2. Open the file ide\bin\ide.conf, scroll down to the default memory settings:
  3.         AddVMOption  -Xms128M
            AddVMOption  -Xmx768M
    
  4. Boost the memory to something larger, like so:
  5.         AddVMOption  -Xms1024M
            AddVMOption  -Xmx1024M
    
  6. Open the file jdev\bin\jdev.conf
  7. Add the following config settings:
  8.         # optimize the JVM for strings / text editing
            AddVMOption -XX:+UseStringCache
            AddVMOption -XX:+OptimizeStringConcat
            AddVMOption -XX:+UseCompressedStrings
    
            # if on a 64-bit system, but using less than 32 GB RAM, this reduces object pointer memory size
            AddVMOption -XX:+UseCompressedOops
    
            # use an aggressive garbage collector (constant small collections)
            AddVMOption -XX:+AggressiveOpts
    
            # for multi-core machines, use multiple threads to create objects and reduce pause times
            AddVMOption -XX:+UseConcMarkSweepGC
    
  9. Then restart JDeveloper... If it doesn't start, you'll need to reduce the amount of memory allocate in the ide.conf file from step 3.

ADF : Insert Row at the Top and Bottom of table

To insert row at the bottom of table follow followings steps:

Step 1 -  Generate VOimpl class of your  View Object.

Step 2 - Go to VOimpl class and add below code

         /**
     * Insert new Rows at the end of RowSet.
     * @param row
     */
    @Override
    public void insertRow(Row row) {
        //go to the end of Rowset if it has rows
        Row lastRow = this.last();
        if (lastRow !=null){
             //insert new row at the end and make it current
            int indx = this.getRangeIndexOf(lastRow)+1;
            this.insertRowAtRangeIndex(indx,row);
            this.setCurrentRow(row);
        }else { // empty Rowset
        super.insertRow(row);
        }
        }

In this way row always insert at bottom of table.


To insert row at the top of table follow following steps:

Step 1 - Generate VOimppl class of your View Object.

Step 2 -Go to VOimpl class and add below code,

         /**
     * Insert new Rows at the top of RowSet.
     * @param row
     */
    @Override
    public void insertRow(Row row) {
        //go to the First of Rowset if it has rows
        Row firstRow = this.first();
        if (firstRow !=null){
             //insert new row at the top and make it current
            int indx = this.getRangeIndexOf(firstRow);
            this.insertRowAtRangeIndex(indx,row);
            this.setCurrentRow(row);
        }else { // empty Rowset
        super.insertRow(row);
        }
        }

In this way row always insert at top of the table.


Tuesday, July 21, 2015

ADF-How To call and Execute sql function Programatically (using operationBinding.getParamsMap() )

Most of the scenarios , we need to call sql function pragmatically.

Here, is the one approch by using Map we can put input parameter to function and get result as Object.

1- Suppose we have Login Table as follows:

2-we want to fetch name of particular user id. So, for that we will create function is database as follows.

3-Now create Application Test ,create Login EO, LoginVO,
4-In AppModuleImpl.class write following method to get result from database.



5-From  Managed Bean call above method as follows:

    OperationBinding operationBinding =
                 (OperationBinding) bindings.getOperationBinding("getName");//AppModuleImpl.class method Name
operationBinding.getParamsMap().put("id", <Pass ID here>);
Object result = operationBinding.execute();//we can get Name of that user Id in result Object


ADF- How to Apply and Create View Criteria Programatically


   

 1.   I have already created a view criteria in EmployeeVO, and I want to call it programmatically.

                public void searchEmployee(Number employeeId) {
                            ViewObjectImpl vo = getEmployeesView1();    
                            ViewCriteria vc = vo.getViewCriteria("findEmployeeVC");   
                            vo.applyViewCriteria(vc);               
                            vo.setNamedWhereClauseParam("pEmployeeId", employeeId);    
                            vo.executeQuery();            
                 }


    2.    I want to create a view criteria dynamically and execute it programmatically.

                   public void searchByEmployeeIdEmail(Number employeeId, String email) {
                                   ViewObjectImpl vo = getEmployeesView2();
                                   ViewCriteria vc = vo.createViewCriteria();
                                   ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
     
                                    vcRow.setAttribute("EmployeeId", employeeId);
                                    vc.addRow(vcRow);
                                    vcRow.setAttribute("Email", email);
                                    vc.addRow(vcRow);
     
                                    vo.applyViewCriteria(vc);
                                    vo.executeQuery();
                    }

Monday, June 22, 2015

ADF -Total Sum of a Column in a Table using Groovy:

In this blog we will see how to get a sum of column in table.

For Example:Sum of salary in employee table:

So,we will use Groovy for this task:

Model Project:

-create EmployeeVO based on Employee EO Table.

-go to EmployeeVO, create one transient attribute say TotalSalSum




-go to accessors,create view accessor of EmployeeVO
Shuffle EmployeeVO,following screen will appear:


-Then give the Groovy for TotalSalSum as follows:
EmployeeVO1.sum(“Salary”)




-Create a new page. Drag and Drop EmployeesVO from data control and create a new read only table "without" TotalSalSum Attribute.
-Now go to the Salary Column, add Facet-column ->footer



-Now from data control drag and drop TotalSalSum attribute in Salary attribute footer


-Go to the source of TotalSalSum ->  change output text value Attribute
From : <af:outputText value="#{row.TotalSalSum}"
To:  <af:outputText value="#{bindings.TotalSalSum.inputValue}"


-Now go to bindings and create a new binding for this attribute.



Save all and run Page:Result:





Wednesday, June 17, 2015

Programmetic View Object in ADF

Sometime we need to call Stored Procedure or Stored function in ADF application. Programmetic View objects are used for this. In this blog I will explain how to use Programmetic VO to call the Strored procedure and function.

We need to override following methods of the ViewImpl class
1.executeQueryForCollection()
2.hasNextForCollection()
3.createRowFromResultSet()
4.releaseUserDataForCollection()
Below are the detailed steps
    1.create VO as below


   2. add the needed atributes
   3. Override the above mentioned methods in VOImpl Class
   4. Make sure all the attributes in VO are updatable
   5. Atleast one attribute should be key attribute
   6. I have created Employee VO as below
   




Define the Stored Function in DB,

CREATE OR REPLACE FUNCTION HR.FUNC_returnEmployee
RETURN SYS_REFCURSOR
AS
REF_TEST   SYS_REFCURSOR;
BEGIN
OPEN REF_TEST FOR
SELECT   employee_id,first_name,phone_number,salary
FROM   employees;
RETURN REF_TEST;
END;


Code of ViewObject Impl class which override above define method.


package model.views;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jbo.JboException;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleTypes;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Mon May 05 14:59:26 IST 2014
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class EmployeeProgramaticVoImpl extends ViewObjectImpl {
    /**
     * This is the default constructor (do not remove).
     */
    public EmployeeProgramaticVoImpl() {
    }
    /**
     * executeQueryForCollection - overridden for custom java data source support.
     */
    protected void executeQueryForCollection(Object qc, Object[] params,
                                             int noUserParams) {
        addEmployeeRecords(qc, callToStroredFunc(qc, params));
        super.executeQueryForCollection(qc, params, noUserParams);
    }
   
    private ResultSet callToStroredFunc(Object qc, Object[] params) {
    ResultSet rs =getStoredProcParams();
    return rs;
    }
   
    public ResultSet getStoredProcParams() {
    ResultSet rs = null;
    try {
    String sp = "{? = call func_returnEmployee()}";
    CallableStatement proc = null;
    proc = this.getDBTransaction().createCallableStatement(sp,0);
    proc.registerOutParameter(1, OracleTypes.CURSOR);
    proc.executeQuery();
    rs= ((OracleCallableStatement)proc).getCursor(1);
    } catch (SQLException sqlerr) {
    throw new JboException(sqlerr);
    }
    return rs;
    }
    private void addEmployeeRecords(Object qc, ResultSet rs) {
    ResultSet existingRs = (ResultSet)getUserDataForCollection(qc);
    // If this query collection is getting reused, close out any previous rowset
    if (existingRs != null) {
    try {
    existingRs.close();
    } catch (SQLException e) {
    throw new JboException(e);
    }
    }
    setUserDataForCollection(qc, rs);
    hasNextForCollection(qc); // Prime the pump with the first row.
    }

     /**
     * hasNextForCollection - overridden for custom java data source support.
     */
     protected boolean hasNextForCollection(Object qc) {
     ResultSet rs = (ResultSet)getUserDataForCollection(qc);
     boolean nextOne = false;
     if (rs != null) {
     try {
     nextOne = rs.next();
     /*
     * When were at the end of the result set, mark the query collection
     * as "FetchComplete".
     */
     if (!nextOne) {
     setFetchCompleteForCollection(qc, true);
     /*
     * Close the result set, we're done with it
     */
     rs.close();
     }
     } catch (SQLException s) {
     throw new JboException(s);
     }
     }
     return nextOne;
     }
     /**
     * createRowFromResultSet - overridden for custom java data source support.
     */
     protected ViewRowImpl createRowFromResultSet(Object qc,
     ResultSet resultSet) {
     resultSet = (ResultSet)getUserDataForCollection(qc);
     /*
     * Create a new row to populate
     */
     ViewRowImpl r = createNewRowForCollection(qc);
     if (resultSet != null) {
     try {
     /*
     * Populate new row by attribute slot number for current row in Result Set
     */
     populateAttributeForRow(r, 0,
     resultSet.getString(1));
     populateAttributeForRow(r, 1,
     resultSet.getString(2));
     populateAttributeForRow(r, 2,
     resultSet.getString(3));
     populateAttributeForRow(r, 3,
     resultSet.getString(4));
     } catch (SQLException s) {
     throw new JboException(s);
     }
     }
     return r;
     }
     protected void releaseUserDataForCollection(Object qc, Object rs) {
     ResultSet userDataRS = (ResultSet)getUserDataForCollection(qc);
     if (userDataRS != null) {
     try {
     userDataRS.close();
     } catch (SQLException s) {
     /* Ignore */
     }
     }
     super.releaseUserDataForCollection(qc, rs);
     }
     /**
     * getQueryHitCount - overridden for custom java data source support.
     */
     public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
   
     return 100;
     }
   
}

Run the AM and see the result.