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

      No comments:

      Post a Comment