Thursday, 3 October 2013

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", "test12@gmail.com");
            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
            vo.insertRow(r);
//commit the transaction
            this.getDBTransaction().commit();
       
        }


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()))
.getSequenceNumber()


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());
        setEmployeeId(seq.getSequenceNumber());

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.

DBTransaction.currentDbTime 

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

Hi,
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.setWhereClause(whereClause);
                   empvo.defineNamedWhereClauseParam("deptBind", null, null);
                   empvo.setNamedWhereClauseParam("deptBind",new Number(30));
                   empvo.executeQuery();