Friday, July 5, 2013

Customized Sequence

We need to create a sequence to fill the primary key of a payment orders table.
The sequence number composed of :  
(the first two digits of the current year - dept id - serial )
Ex : 
      129010001
      139010001
      139010002
      135500001 
      135500002
 
Steps to accomplish the task :
  1. Create a PL/SQL function that deals with creating sequences
  2. Inside payment EO , Call PL/SQL function from doDml method 
  3. Pass the arguments .
  4. Get the result and assign it to the primary key or the target attribute
CallableStatement cs=
         getDBTransaction().createCallableStatement ("begin ? := PAY_ORDER_SEQ(?,?) ; end;", 0);

 PL/SQL function




Wednesday, July 3, 2013

Entity Object can't fetch PK for a view or Synonym


If we try to create an Entity Object (EO) based on a View or Synonym, we should add a Primary Key to EO manually , the reason is ADF Framework can't get the PK by itself .
by adding PK manually , you  avoid adding rowid column for your EO by ADF Framework .

(you can find another issue based on the same subject here:Entity Object based on Synonym issue )

an example : without PK



 



with PK:


finally , If you use Entity Object option instead of  ADF Business Component, you will be asked to add the primary key to a view/Synonym

 




Saturday, May 4, 2013

Friday, May 3, 2013

Friday, April 26, 2013

Task Flow And Switcher Example


The next example show how to switch between two fragments in the same task flow by using the switcher .

Use Case : The user can explore the hierarchy of departments and explore the hierarchy of employees by selecting from the menu in the left corner of the screen 

The hierarchy of departments


The hierarchy of employees

One of the solutions that can be used is the use of dynamic region, but in my case I will use a different technique which consists of a single task flow with 2 fragments and switcher

Implementation steps :
  1. create a task flow (fragment)
  2. create a switcher and 2 fragments , one for  hierarchy of departments and one for hierarchy of employees
  3. define cases for the switcher
  4. add the task flow to a consumer page as a region 
  5. create menu and add setPropertyListener to menu items
  6. add partial trigger to the region 
  7. change Refresh' property for the task flow to "if needed"

Create the task flow with 2 page fragments and add the navigation cases 


create the region for the hierarchy of departments 


create the region for the hierarchy of employees 



Define a parameter in  the parameters section 


Define the cases of the switcher  :
if the value of choiceParam == 'dept' then go to hierarchy of departments
if the
value of choiceParam == 'emp' then go to hierarchy of employees



Add the task flow as a region to a consumer page
create a menu model
Add partial trigger for the region 


Add SetPropertyListener to menu items



In the consumer page :
  • go to the page definition
  • pass the value of the menu item to the task flow
  • change refresh ' property to "ifNeeded"


Monday, April 15, 2013

Entity Object based on Synonym issue


We have HR and Finance Database , in the schema of Hr we need to create an Entity Object Based on Synonym in Financial database.
when running wizard to create ADBC , we can't see any Eo or Vo !
I will explain how to reproduce the problem and how to solve it

The Design of the Database :
  • Ben_View is DB View in Finance
  • HR have the privilege to select data from Ben_View
 
 

Now start ADFBC wizard


Choose connection
 

choose Synonym only


Create Entity Object


Create View Object


Create Application Module


The result is ....... !!!
No Entity Object or View Object  , just Application module !


I have tried repeating the above steps with another synonyms and the result was good and normal !

ok , now let's look at Ben_View , Ben_View composed of two query and this is the difference between it and other synonyms 


the solution is very easy , we need to add primary key for Ben_View when creating EO.
i will create EO and add PK to it 


Now we can see EO inside the project




Tuesday, March 26, 2013

How to sum column in View Object using Groovy

Use Case : 
we have 2 tables PayOrders  and  PayOrderTrans 
 we need to :  sum Credit column in PaymentOrderTrans table

  • First create New Attribute called CreditTotal 
  • Go to Default Value section
  • Choose Expression
  • Enter the following expression
         object.getRowSet().sum('Credit')

  What about the Null value ?   
     to avoid null value, you must modify the expression to
          object.getRowSet().sum('Credit != null ? Credit : 0 ')


Saturday, March 23, 2013

The techniques for populate a sequence attribute in Oracle ADF


Technique No1:   
Allowing the database to handle the insertion operation
1- Add trigger to DB Table to fetch next sequence' number


2- Open Entity Object (ex:Department)
3- Change type of DepartmentId attribute to DBSequence


Technique No2
Fetching the next sequence number using Java/Groovy
first we need to add a java method to get thenext sequence' No
  • Open Department Entity Object
  • Go to Java ==>> Edit Java Option 
  • Check Generate Entity Object Class
  • Open DepartmentsImpl Java file 
  • Add the following lines to end of the file

To Get the next sequence number at the time of record creation (Java code):
  • Open DepartmentsImpl Java file
  • Go to Source Menu ==>> Override Methods
  • check create method
Add the following line after create  method 

To Get the next sequence number at the time of record creation (Groovy) : 
    • Open Departments Entity Object
    • Go to DepartmentId
    • Choose Expression in Default Value section
    • Enter adf.object.nextSequenceVal("DEPARTMENTS_SEQ")
       
      To Get the next sequence number at the time of Commit (Java Code) : 
      used to avoid gaps between sequence number 

      • Open DepartmentsImpl Entity Object
      • Go to Java tab 
      • Check Data Manipulation Methods 
      •  Add the following to doDML methods

      Question:if i am in need to apply EMPLOYEES SEQ to Employee Id,do i need to add nextSequenceVal method in the Employees EO again ?
      Answer : Yes, but can you think of a more general way to extend ADF Framework Classes where you can add your favorite utilities


      To add our custom ADF Framework Classes:
      • Right click on TestSeqModel 
      • java ==>>Class
      • Enter EntityImpl for Name 
      • Enter model.extension for Package
      • Enter oracle.jbo.server.EntityImpl for Extends
      • Add nextSequenceVal method
       
      • Double click on TestSeqModel 
      • Go to ADF Business Component ==>> Base Classes
      • In Entity Object Section  , browse for Row 
      • Enter entity word in the search menu
      • Choose model.extension
      • Press Ok and again OK 
      • Remove nextSequenceVal method from Departments EO 
      • The nextSequenceVal method is available now to all Entity Objects
      • Use nextSequenceVal in Employees EO
      Nick Haralabidis spoke about using a custom property to populate a sequence attribute in his book Oracle JDeveloper 11gR2 Cookbook 



      The best solution for me is the third one