How to Insert Data in Database Table in OAF

Today we will learn how we insert data in database table. So we will have to create a database table and sequence. Let’s create those.

Database Design

Table Script

CREATE TABLE XXRD_EMP_TAB
(
EMP_ID NUMBER,
EMP_NAME VARCHAR2(100 BYTE),
DOB DATE,
GENDERA�VARCHAR2(1 BYTE),
COUNTRY VARCHAR2(50 BYTE),
STATE VARCHAR2(50 BYTE),
AGE NUMBER,
FILE_NAME VARCHAR2(50 BYTE),
FILE_CONTENT BLOB,
ATTRIBUTE_CATEGORY VARCHAR2(150 BYTE),
ATTRIBUTE1 VARCHAR2(150 BYTE),
ATTRIBUTE2 VARCHAR2(150 BYTE),
ATTRIBUTE3 VARCHAR2(150 BYTE),
ATTRIBUTE4 VARCHAR2(150 BYTE),
ATTRIBUTE5 VARCHAR2(150 BYTE),
ATTRIBUTE6 VARCHAR2(150 BYTE),
ATTRIBUTE7 VARCHAR2(150 BYTE),
ATTRIBUTE8 VARCHAR2(150 BYTE),
CREATED_BY NUMBER,
CREATION_DATE DATE,
LAST_UPDATED_BY NUMBER,
LAST_UPDATE_DATE DATE,
LAST_UPDATE_LOGIN NUMBER
);

Here is a point to note that if a data is populated with data through OAF, then the 5 WHO Columns are mandatory. Attributes columns were created to implement DFF. Ideally we can keep any number of attribute columns, in my case , I have kept only 8. GENDER will be used to store the sex of the employee, will be done via implemetation of poplist or picklist which is nothing but dropdown in traditional web development.COUNTRY and STATE will be used for storing country and state corresponding to a country, will be done via LOV and Dependent LOV implementation. AGE will be calculated as of Date of Joining through a package/procedure call. FILE_NAME and FILE_CONTENT will be used to store the filename and the content being uploaded. EMP_ID will be populated through Database Sequence generated at OAF end. EMP_NAME and DOB will be inserted by End User.

Sequence Script

CREATE SEQUENCE XXRD_EMP_ID_SEQ
START WITH 101
MAXVALUE 999999999999999999999999999
MINVALUE 1
NOCYCLE
CACHE 20
NOORDER;

OAF Project

Now let’s create Design Time Database Connection in Jdeveloper.

  1. Right Click on Database folder to create New Database Connection.oaf_db_conn1
  2. Having launched the Database Connection Creation Wizard, Click on Next.oaf_db_conn2
  3. Enter relevant Connection Name.oaf_db_conn3
  4. Enter Username and Password for Database schema.(It’s APPS)oaf_db_conn4
  5. Enter TNS Details for the APPS schema for the concerned Instance.oaf_db_conn5
  6. Test the Connection.oaf_db_conn6
  7. Here is the connection enlisted.oaf_db_conn7

Let’s create Workspace and Project in Jdeveloper.

  1. Right Click on Applications to create New OA Workspace.create_workspace
  2. Enter OA Workspace Name. Ensure directory is populated as set in the Environment Variable(JDEV_USER_HOME) as shown in the previous articleA�and Checkbox before “Add a New OA Project” A�is checked.create_workspace_wizard
  3. Click OK and it will take you to Create Project Wizard.create_project_wizard
  4. Enter Project Name. Directory will get populated automatically from Environment Variable.create_project_wizard1
  5. Select the Design Time Database Connection being created. Click Nextcreate_project_wizard2
  6. Browse to enter .dbc file name.create_project_wizard3
  7. Then enter Application User Name and Password along with valid responsibility key and it’s application short name.create_project_wizard4
  8. Click Finish.

In order to create a CRUD application, we have to create the following objects in the same order mentioned below:

Entity Object

  1. Right Click on Project to select Newinsertpg1
  2. Select Entity Object.insertpg2
  3. Enter the Entity Object Name as XXRDEmpEO and Package as xxrd.oracle.apps.ap.schema.server. Select database table XXRD_EMP_TAB. Click Next.insertpg3
  4. Click Next without changing anything.
  5. Set EmpId as Primary Key and Click Nextinsertpg5
  6. Check all methods under Generate Methods of XXRDEmpEOImplinsertpg6
  7. Click Finish

View Object

We are going to create EO based VO now.

  1. Right Click to select View Object.insertpg8
  2. Enter VO Name as XXRDEmpVO and Package as xxrd.oracle.apps.ap.server. And as it is EO based VO, so Updatable Access through Entity Objects.insertpg9
  3. Select the Entity Object by moving from left to right. Click Nextinsertpg10
  4. Select all columns. Click Next.
  5. Click Next.insertpg12
  6. Click Next.insertpg13
  7. Check option to GenerateA�XXRDEmpVOImpl and XXRDEmpVORowImpl classinsertpg14
  8. Click Finish.

Application Module

  1. Right Click to select Application Module.insertpg16
  2. Enter AM Name as XXRDRootAM and Package as xxrd.oracle.apps.ap.server. Click Next.insertpg17
  3. Attach VO instance, here XXRDEmpVO1. Click Next.insertpg18
  4. Click Next.insertpg19
  5. Check option to generate XXRDRootAMImpl class.insertpg20
  6. Click Finish.
    insertpg21

Page

  1. Right Click > New > OA Components > Pageinsertpg22
  2. Enter Page Name as XXRDCreateEmpPG and Package as xxrd.oracle.apps.ap.webuiinsertpg23
  3. Click OKinsertpg24
  4. Change the following:
    ID: MainRN
    Window Title: Create Employee Page
    Title: Create Employeeinsertpg25
  5. Now browse to attach AM.insertpg27
  6. Right Click on MainRN to create another region.insertpg28
  7. Change Region Properties like
    ID:A�CreateRN
    Region Style: messageComponentLayoutinsertpg29
  8. Right Click on CreateRN to add a messageTextInputinsertpg30
  9. Update following properties:
    ID: EmpName
    View Instance: XXRDEmpVO1
    View Attribute EmpName
    Prompt: Employee Nameinsertpg31
  10. Create another messageTextInput.
    ID: EmpDOB
    Data Type:
    View Instance: XXRDEmpVO1
    View Attribute: Dob
    Prompt: Date of Birthinsertpg32
  11. Add a MessageLayout in order to accommodate Buttons under MessageComponentLayout.
  12. Create a submit button.
    ID: CreateEmpBtn
    Item Style: submitButton
    Prompt: Create Employeeinsertpg35
  13. Similarly create a reset button.
    ID: ResetBtn
    Item Style: resetButton
    Text: Resetinsertpg36
  14. Page will look like below.
    insertpg36_1

Controller

  1. Right Click on MainRN to set New Controller. Enter Package: xxrd.oracle.apps.ap.webui Controller Name: XXRDCreateEmpCOinsertpg26

Logic

In XXRDEmpEOImpl.java:

Need to write logic in order to generate sequence from Database Sequence within create() method.

public void create(AttributeList attributeList) {
super.create(attributeList);
OADBTransaction trx = getOADBTransaction();
oracle.jbo.domain.Number empId = trx.getSequenceValue(“XXRD_EMP_ID_SEQ”);
setEmpId(empId);
}

insertpg37_0

In XXRDRootAMImpl.java:

Need to write couple of methods to make data insertion possible.

Method 1:A�createRow() to create a blank row to accommodate data and mark this as Initialized.

public void createRow(){
XXRDEmpVOImpl empVO = getXXRDEmpVO1();
if(!empVO.isPreparedForExecution()){ // Check whether VO is prepared for Execution or not
empVO.executeQuery(); // if Not execute
}
Row row = empVO.createRow(); // Create New Row
empVO.insertRow(row); // Insert the newly created row of Type XXRDEmpVO in the XXRDEmpVO
row.setNewRowState(Row.STATUS_INITIALIZED); // Set the status of the New Row
}

Method 2: commitData() to save the data permanently into a table in database.

public void commiData(){
OADBTransaction trx = getOADBTransaction();
trx.commit();
}

insertpg37

In XXRDCreateEmpCO.java:

code needs to be added in processRequest() and proecessFormRequest(). We will also learn how to invoke method written AM from CO.

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
// Get access to AM attached at page level i.e Root AM
OAApplicationModuleImpl rootAM = (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
// Invoke AM method “createRow”
rootAM.invokeMethod(“createRow”);
}

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
// Get access to AM attached at page level i.e Root AM
OAApplicationModuleImpl rootAM = (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);
// If submit button is clicked
if(pageContext.getParameter(“CreateEmpBtn”)!=null){
// Invoke AM method “commiData”
rootAM.invokeMethod(“commiData”);
}
}

The parameter sign for invokeMethod() is invokeMethod(String methodName), another one , invokeMethod(String methodName, Serializable params[], Class paramClasses[]) . First one is used if there areA�no parameters to pass to AM’s method where as the second one to pass parameters to AM’s method.

insertpg38

Output

The page when launched will look like:insert_output1

Now query:

insert_output

This is how we can insert data in database table through OAF Page. Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

Show my latest post here