Friday, 20 December 2013

Generate the DB sequence number without loosing

Generally we use sequence number in EntityImpl class create() method using the following code

       SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());

or we will set expression in default attribute of Entity Object xml file. If we follow this approach we will loose the sequence numbers. To avoid this use the following approach

Step 1: Go to entity object xml file  --> select the EmployeeID -- > go to defalu value and set -999 or -9999. Because the sequence number never reach the negetive value.

Step 2: Generate the java class for EO and override the doDML() method

    protected void doDML(int operation, TransactionEvent e) {
            SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());
        super.doDML(operation, e);
Step 3: Run the application

Wednesday, 18 December 2013

Populate dynamic Panel Accordion in ADF page

In this post i will show you how to create dynamic panel accordion. Sometimes you may get requirement to populate the accordion dynamically based on user login or some criteria.

Step1: Create the Business components on Department Table.

Step2: Create on jspx page --> go to data bindings and create Tree Bindings as shown below

Step3:  Add the data source DepartmentView1 and add the rule. Select the department name as shown below.

Step4: Drag and drop panel accordion on jspx page. Select the af:showDetailItem in structure window and surround with af:ForEach

Step5: Set the attributes in forEach tag as shown below.

Step6:  Change the Text attribute value to #{dept.DepartmentName} in af:showdetailsItem

Step7: Run the jspx page 

Tuesday, 17 December 2013

Hiding unwanted operators in Advance mode of ADF Query Search

Sometimes you may get a requirement to hide the unwanted operators in advance mode of adf query search.
 I have created view criteria on employess table with FirstName. Now the requirment is i want to hide the BETWEEN and NOTBETWEEN operators for FirstName Field in advance search mode.
By using the below code you can hide the operators.


Here is my view criteria code.



Thursday, 3 October 2013

Update attribute value in View Object Programmatically

In this post i willl explain you how to update the attribute value of a Row.

The following code will find the EmployeeId 100 in Employee View object and update the FirstName.

        Number empid=100;
       // create the key object
        Key key = new Key(new Object[] { empid });
        Employees1ViewImpl vo = (Employees1ViewImpl)this.getEmployees1View1();
        //find the row using key reference in View Object.
        Row k=vo.getRow(key);
        //using this method we can set the new value to FirstName  
        k.setAttribute("FirstName", "stev");
       System.out.println("the name is");

Programmatically Insert New Row in DB using View Object reference

We have seen declarative approach to insert new row in database.

In this post i will explain you how to insert new row Programmatically.

1. Create the AppModuleImpl class and also create the java class for respective ViewObject. In this example i am working on EmployeeView. So i have generated EmploueeViewImpl java class.

2. Create the user defined method in AppModuleImple calss as shown below.

    public void createNewRow(){

//get he EmployeeViewImpl class instance
        EmployeesViewImpl vo=this.getEmployeesView1();

       // Create new row to insert data
        Row r=vo.createRow();
//Set the values to respective attributes.
            r.setAttribute("EmployeeId", 509);
            r.setAttribute("FirstName", "test");
            r.setAttribute("LastName", "test");
            r.setAttribute("Email", "");
            r.setAttribute("PhoneNumber", "800000444");
            r.setAttribute("HireDate", new Timestamp(System.currentTimeMillis()));
            r.setAttribute("JobId", "IT_PROG");
            r.setAttribute("Salary", 5000);
            r.setAttribute("CommissionPct", "");
            r.setAttribute("ManagerId", "");
            r.setAttribute("DepartmentId", 340);
//insert row in the view object
//commit the transaction

Tuesday, 6 August 2013

Creating DB Table Form Entity Object

I have got the requirement to create the DB table from entity object. Here is example

Step 1: Create the Entity Object

Declare the entity object name. Un-check the existing object check box and click on next. As shown in the image.

Step 2:
Create the attributes for entity object and declare one attribute as primary key. Click on finish.

Step 3:
Right click on entities package and select "Create DataBase object".

Step 4 :
Select and Shuttle the Entity Object to create Database table and click on OK.

Saturday, 27 July 2013

Set DB Sequence number as default value to entity object

In this post i will explain you about setting default value to entity object.
It is very common requirement, where you need to set DB sequence number to entity object. I am using Employees table and Employees_seq (sequence) in this example.

There are two ways of setting default value
1. Groovy Expression    2. Entity Object Java class

1. Groovy Expression
Create the Employees entity object and go to attributes tab in that select employee_id and then go to the default value and select the expression paste the below expression in the text box.

(new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction()))

2. Entity Object java class

Create the entity object java class and include the create method in that. Then use the below code in create  method.

        SequenceImpl seq=new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction());

Final step is to create Employee view and Application module, run your AM, You vill see the result when ever u add new record.

Thursday, 6 June 2013

Get DB Server Date time and app server using groovy expression.

The below expression is used to get the DB current date time. This expression you can use as default value on EO or VO.


If you are looking for app server date  or Date time. You can use the below expression

1. adf.currentDate -- Date

2. adf.currentDateTime -- Date time.

Wednesday, 22 May 2013

Creating SOAP Web Service Data Control

In this post i am going to show you sample application with webservice data control.

Step 1: 

You must have web service WSDL URL. For this application i am using the below WSDL url. Which will return the IP addres and location.

Step 2: 

Create new fusion web application.

Step 3:

Select Web Service Data Control as shown in below image

Step 4:

Give the service name and Service URL as Shown in image and click on next.

Step 5:
Select the GeoIPServiceSoap and click on next finish.

You will find the data control with Service name

Step 6:
Create one jspx page and drag and drop GetGeoIPContext() method as button and expand GetGeoIPContext method and drag n drop GetGeoIPContextResult as form in page (you can make use of other method also).

Step 7:

Run the application. You will find the below result. 

Tuesday, 7 May 2013

Set Page flow scope using java code

By using the below code you can set and get the page flow scope using java.

AdfFacesContext.getCurrentInstance().getPageFlowScope().put("pageflowScopeVarName","value" );
System.out.println("The value is="+AdfFacesContext.getCurrentInstance().getPageFlowScope().get("pageflowScopeVarName"));

Saturday, 4 May 2013

Creating where clause programmatically and execute view object

       The below code is used to create where clause and bind variable programmatically execute the view object.        
The defineNamedWhereClauseParam () method of ViewObject is used to create the bind variable at run time.

                   ViewObject empvo = this.getEmployeesView1();
                   String whereClause = "Employees.DEPARTMENT_ID = :deptBind";
                   empvo.defineNamedWhereClauseParam("deptBind", null, null);
                   empvo.setNamedWhereClauseParam("deptBind",new Number(30));

Thursday, 17 January 2013

Get current row of table in oracle ADF

The following code is use to get the current row.

    DCBindingContainer dcbindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();           
    DCIteratorBinding dcIt = dcbindings.findIteratorBinding("iteratorname");

    RowSetIterator RSIter = dcIt.getRowSetIterator();

    Row r = RSIter.getCurrentRow();

Friday, 11 January 2013

Run mysql script in java

package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.ibatis.common.jdbc.ScriptRunner;

public class SqlScript {
 public static void main(String[] args) throws ClassNotFoundException,
  SQLException {
  String aSQLScriptFilePath = "sql/script.sql";
  // Create MySql Connection
  Connection con = DriverManager.getConnection(
   "jdbc:mysql://localhost:3306/database", "username", "password");
  Statement stmt = null;
  try {
   // Initialize object for ScripRunner
   ScriptRunner sr = new ScriptRunner(con, false, false);
   // Give the input file to Reader
   Reader reader = new BufferedReader(
                               new FileReader(aSQLScriptFilePath));
   // Exctute script
  } catch (Exception e) {
  System.err.println("Failed to Execute" + aSQLScriptFilePath
     + " The error is " + e.getMessage());
  1. sql script should have an semi colen (;) for each end of the statement.
  2. You sql script does not have any select statement.