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();

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.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;
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
  Class.forName("com.mysql.jdbc.Driver");
  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
   sr.runScript(reader);
 
  } catch (Exception e) {
  System.err.println("Failed to Execute" + aSQLScriptFilePath
     + " The error is " + e.getMessage());
  }
 }
}
Note
  1. sql script should have an semi colen (;) for each end of the statement.
  2. You sql script does not have any select statement.