Top Banner
1 Oracle EBS 12.1.3: Integrate OA Framework BC4J components within Java Concurrent program. Concurrent processing has been one of the rewarding aspect of Oracle EBS. This allows us to process millions of transactions behind the scene without any user intervention. Oracle has provided multiple avenues to design a concurrent program. One stands out of all “Java concurrent program” which uses Java one language, endless possibilities. Most of background processes performs some kind of database operation. When comes to Java concurrent program, JDBC API is in practice to execute SQL operation. Oracle Application Framework (OAF) is available since many years now to help us to reduce some of the application development complexities. OAF insulates JDBC connection pool complexity within AOL/J integration code. OAF is built on MVC deign patterns where MVC stands for model-view and controller. Model-View relationship separates business/back-end logic with graphical user interface logic. This represent how do we control operation on server level object like table inserts”. OAF provides all the bare minimal code which developer needs to write additionally to fire SELECT/INSERT/UPDATE statement. This way development team is more focus on actual task in hand which in this tutorial “ Read a XML file. In this tutorial, I am going to demonstrate “How to use OA Framework BC4J components in Java concurrent program” to perform complex background operations like loading a data file. We are going to build a custom Java concurrent program which will read the XML file, parse it and load it into the database table. Sample XML file being used for this tutorial is provided as below.
55

Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

Apr 13, 2017

Download

Technology

Amit Singh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

1

Oracle EBS 12.1.3: Integrate OA Framework BC4J components within Java Concurrent program.

Concurrent processing has been one of the rewarding aspect of Oracle EBS. This allows us to process

millions of transactions behind the scene without any user intervention. Oracle has provided multiple

avenues to design a concurrent program. One stands out of all “Java concurrent program” which uses

“Java — one language, endless possibilities”.

Most of background processes performs some kind of database operation. When comes to Java

concurrent program, JDBC API is in practice to execute SQL operation. Oracle Application Framework

(OAF) is available since many years now to help us to reduce some of the application development

complexities. OAF insulates JDBC connection pool complexity within AOL/J integration code.

OAF is built on MVC deign patterns where MVC stands for model-view and controller. Model-View

relationship separates business/back-end logic with graphical user interface logic. This represent how do

we control operation on server level object like “table inserts”. OAF provides all the bare minimal code

which developer needs to write additionally to fire SELECT/INSERT/UPDATE statement. This way

development team is more focus on actual task in hand which in this tutorial “Read a XML file”.

In this tutorial, I am going to demonstrate “How to use OA Framework BC4J components in Java

concurrent program” to perform complex background operations like loading a data file.

We are going to build a custom Java concurrent program which will read the XML file, parse it and load it

into the database table. Sample XML file being used for this tutorial is provided as below.

Page 2: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

2

System Configuration used in this demonstration.

JDeveloper 10g on Window7 4GB RAM.

Oracle Database 11.2.0.4

Oracle EBS 12.1.3 on Linux.

JDeveloper is being primarily tool used for OAF development. Before we proceed, we will have to find

out what JDeveloper version works with Oracle EBS release installed in the development environment.

Oracle has generously published this information in Metalink note#416708.1 to help us find exact

JDeveloper patch required.

I built this example on Release 12.1.3 with patch 15880118 applied which corresponds to JDeveloper

Patch# 9879989 as per below matrix available in note#416708.1.

OA Framework - How to Find the Correct Version of JDeveloper for OA Extensions to Use with

E-Business Suite 11i or Release 12.x (Doc ID 416708.1)

JDeveloper doesn’t comes with installer. Once you have downloaded the patch, you just need to

extract/unzip file at your preferred location.

As an example, I used C:\Amit\Jdev_12_1_3\ as a location to unzip\extract the patch.

Page 3: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

3

Setup Your Development Environment

It’s important we follow all the instructions provided under section “Setting Up Your Development

Environment” in Oracle Application Framework Developer's Guide. This can save us from nuisances.

Step1: Create an environment variable “JDEV_USER_HOME” in local machine.

Step2: Add below responsibilities to your EBS user account.

Step3: Define JDeveloper Database Connection

Step3.a: You can switch to Connection tab, right click on Databases and select “New Database

Connection”.

Responsibility:

OA Framework ToolBox OA Framework ToolBox Tutorial Labs

Page 4: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

4

Step3.b: Ignore the First/Splash screen.

Step3.c: Choose connection name.

Step3.d: Provide DB schema name as Username and corresponding password.

Page 5: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

5

Step3.e: Provide Database hostname, DB Port and SID.

Step3.f: Test the connection.

Page 6: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

6

Step3.g: Expand the connection to review an object / table.

Your DB connection is ready to use. JDeveloper will need DB connection to create Entity Object, View

object etc. for you.

Step4: Run the examples comes with JDeveloper patch

Running examples comes with patch is great way to find out if you are going to get into any trouble with

AOL/J integration. All the examples can be loaded by single WORKSPACE selection “toolbox.jws”. They

are normally available under <LOCAL_ DIR >\JDevHome\jdev\myprojects.

Step4.a: Choose workspace “toolbox.jws”

Go to File menu and select Open option and choose

<LOCAL_DIR>\Jdev\jdevhome\jdev\myprojects\toolbox.jws

Page 7: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

7

Page 8: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

8

In Applications navigator, Right click on toolbox and select Rebuild/compile whole sample set.

Make sure fix any compilation error reported.

Page 9: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

9

Step4.b: Change the “tutorial” project setting to include Database connection and discard whatever

comes in as default.

Step4.3 Update runtime connection. You can always check directory “$FND_TOP/secure” or

“$FND_SECURE” to find DBC file. If you don’t have access, you can request Oracle Applications DBA to

provide it to you.

Page 10: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

10

Step4.c: You are all set to run JDeveloper examples. Right click on “test_fwktutorial.jsp” and select “Run”

to launch the main page. You shall see webpage showing main menu as below.

As long as you can run the example pages, your configuration settings are OKAY. We can proceed now

with topic in hand.

Step5: Create a New OA Workspace and add a New OA Project

Even though we can use “toolbox.jws” as workspace for development. I prefer we create new workspace

and project to separate the work being done.

Step5.a: Right click on Applications and Select “New OA Workspace...”

Page 11: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

11

Step5.b: Define project name and Default Package.

Oracle naming convention to define package is as below.

<3rdPartyName>.oracle.apps.<applicationShortName>.<subcomponentName>.

In this example, I am using 3rdParty as “custom” and application name as “custmodule”

Step5.c: Predefined connection will be listed under Connection LOV. Select the appropriate one.

Page 12: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

12

Step5.d: Select the DBC file and User name has to be an “EBS” account not Database account.

Click on finish button.

Page 13: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

13

Define Model and View objects

Before we can add any component to newly created project, lets understand what object we will need…

OA Framework Stack

Step6: Create an entity object for table.

Step6.a: Right click on “Server” under “custom.oracle.apps.custmodule.conc” and select “New Entity

Object…”

We are building background job. As per OA

Framework stack, we need following

objects

1. Entity object

2. View Object

3. Application module.

We don’t need OA Controller object

because it is primarily responsible for user

action on HTML page.

Page 14: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

14

Step6.b: Choose all the attributes. Please make sure custom table has WHO columns.

Step6.c: Select the primary key. If you don’t have, then select ROWID as primary key.

Page 15: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

15

Step6.d: Select the Accessors as Generate Methods.

Step6.e: Don’t select the Generate Default View Objects.

Page 16: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

16

Step6.f: Click the finish button to complete the EO creation.

Step7: Create a view object.

Step7.a: Right click on “Server” under “custom.oracle.apps.custmodule.conc” and select “New View

Object…”

Page 17: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

17

Step7.b: Select the Entity object available in left side and move it to right.

Step7.c: Select all the available attributes in view.

Page 18: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

18

Step7.d: Select the View Object class as well as View Row class as per below screen.

Step7.e: Finish the wizard.

Page 19: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

19

Step8 Create an Application module.

Step8.a: Right click on “Server” under “custom.oracle.apps.custmodule.conc” and select “New

Application module. …”

Step8.b: Select the view object available on left side and move it right side.

Page 20: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

20

Step8.c: There is only one Application Module in used. Please ignore this screen.

Step8.d: Select the Generate java files option for “contactinfoAMImpl” and finish the wizard.

Page 21: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

21

JDeveloper will automatically generate java classes for you. As you can see now, you have class file for

Entity Object, View Object and Application Module.

As of now, we have all the required BC4J components which we will integrate with Java concurrent

program class.

Step9: Create class “LoadData.java” which implements Java

concurrent program methods.

Step9.a: Create a class.

Import all the required packages for Java concurrent program.

import oracle.apps.fnd.cp.request.CpContext;

import oracle.apps.fnd.cp.request.JavaConcurrentProgram;

Page 22: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

22

Implements LoadData class to use JavaConcurrentProgram.

Red Underline on LoadData indicates below error. Error: Method RunProgram not implemented Step9.b: Add any missing method.

Now basic implementation of the class to implement Java Concurrent program looks as below.

Step9.c: Add basic functionality to class.

Read any parameter pass to concurrent request. Display parameters in log file.

Set Request completion status as 0 (successful).

import oracle.apps.fnd.cp.request.CpContext;

import oracle.apps.fnd.cp.request.JavaConcurrentProgram;

public class LoadData implements JavaConcurrentProgram{

public LoadData()

{}

public void runProgram(CpContext ctx)

{}

}

public void runProgram(CpContext ctx) { System.out.println(" Running Custom Job Parse and Load XML data into Contact Info table."); String attribute; String line = null; // Concurrent Request execution status ReqCompletion rStatus = ctx.getReqCompletion(); rOutFile = ctx.getOutFile(); // get OutFile object from CpContext rLogFile = ctx.getLogFile();// get LogFile object from CpContext ParameterList pList = ctx.getParameterList(); Hashtable mAttributes = new Hashtable();

Page 23: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

23

Code continue...

Object obj = null; // Retrive the list of parameters provided to concurrent request. if(pList.hasMoreElements()) { rLogFile.writeln( "--------------------", rLogFile.STATEMENT); String attribute_name; String attribute_value; for(; pList.hasMoreElements(); ) { NameValueType namevaluetype = pList.nextParameter(); attribute_name = namevaluetype.getName(); attribute_value = namevaluetype.getValue(); if(attribute_value != null) { if(attribute_name.equalsIgnoreCase("P_FILE_NAME")) mFileName = attribute_value; } } } BufferedReader br; try { br = new BufferedReader(new FileReader(mFileName)); while ((line = br.readLine()) != null) { rLogFile.writeln(line,rLogFile.STATEMENT); } } catch (FileNotFoundException e) {rLogFile.writeln(e.getMessage(),rLogFile.STATEMENT);} catch (java.io.IOException e1) {rLogFile.writeln (e1.getMessage(),rLogFile.STATEMENT) ;} rStatus.setCompletion(mXmlErrorCode, mXmlErrorMsg); rLogFile.writeln ("Load XML Data using OA Business Component job Completed",rLogFile.STATEMENT);

}

Page 24: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

24

Step10: Test the basic functionality.

Step10.a: Create directories at middle tier which represent BC4J package

“custom.oracle.apps.custmodule.conc.server”.

Connect to APPS tier (I got Linux) as an instance owner, run below commands to create your directory

structure.

Step10.b: Upload all the class files from local machine to middle tier.

Step10.c: Define concurrent program and executable.

cd $JAVA_TOP

mkdir -p custom/oracle/apps/custmodule/conc/server

$ pwd

Example: /{Instance_name}/apps/apps_st/comn/java/classes/custom/oracle/apps/custmodule/

conc/server

Page 25: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

25

Define Concurrent Program.

Define Parameter for concurrent program.

Page 26: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

26

Step10.d: Register the concurrent program to request group.

Step10.e: Run the concurrent program.

Concurrent request was completed normal. I printed XML content in log file to verify if process can read

file successfully.

Concurrent request log file: Concurrent job was able to read xml file.

Page 27: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

27

Step11: Add a parsing capability.

We can use DOM or SAX API to parse XML data. In this tutorial, I am going to use SAX parser. For more

information on SAX parser, please visit http://www.saxproject.org/.

SAX Parser is event oriented. Parsing event get fired on XML element. This make developer life easy

because we can just look for what is “Point of Interest” and discard rest of data.

With SAX Parser, we will need to implement 5 different methods to represent complete XML tag life cycle.

startDocument()

startElement()

characters()

endElement()

endDocument()

Here is an example how API will be fired.

<?xml version="1.0"?>

<vendor>

<name>Jon Doe</name>

</vendor>

API firing sequence

Start Document

Start Element: vendor

Start Element: name

characters: Jon Doe

End Element: name

End Element: vendor

End document

Why did I select SAX instead of DOM?

Before I proceed to next step, I wanted to clear why SAX Parser was more appealing for me than DOM.

DOM loads whole XML document into memory as a tree. DOM API’s are fast but they need more

memory. In order to load XML data, I don’t need all the XML elements loaded in memory. I don’t even

need all of them. We will look for specific XML elements to decide what to load. For example, I don’t care

about <vendor> tag in file. This is just start and stop marker for me to decide when new record starts.

If you are in need to validate XML document first before you can use the XML data, DOM would be better

for you.

Page 28: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

28

Step11.a: Add a new class “ReadXML” which implements SAX Parser API.

package custom.oracle.apps.custmodule.conc.server; import java.io.IOException; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.FileInputStream; public class ReadXML extends DefaultHandler { File lFile; InputStream lFileStream; SAXParser lSaxParser; boolean recordData=false; String lName = ""; String lAddress =""; String lCity =""; String lState =""; String lZip = ""; StringBuffer textBuffer; Attributes attrlist; public ReadXML() { } public void readFile(String fileName) { jobAM=LoadData.getAM(); InitSaxXmlParser(fileName); } public void startDocument() throws SAXException { System.out.println("Start of document"); initAttribute(); }

Page 29: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

29

public void initAttribute() { lName = ""; lAddress =""; lCity =""; lState =""; lZip = ""; } public void endDocument() throws SAXException { System.out.println("End of document. Does"); } public void InitSaxXmlParser(String fileName) { DefaultHandler mhandler = new ReadXML(); try { System.out.println("File name length"+fileName.length()); lFile=new File(fileName); lFileStream = new FileInputStream(lFile); // Use the default (non-validating) SAX Parser SAXParserFactory factory = SAXParserFactory.newInstance(); try { lSaxParser = factory.newSAXParser(); lSaxParser.parse(lFileStream, mhandler); } catch (ParserConfigurationException ex) { System.err.println ("Failed to create SAX parser:" + ex);} catch (SAXException ex) { System.err.println ("SAX parser exceeption:" + ex);} catch (IOException ex) { System.err.println ("IO exeception:" + ex);} catch (IllegalArgumentException ex) { System.err.println ("Invalid file argument" + ex);} } catch(FileNotFoundException e) { System.err.println ("Invalid file argument" + e.getMessage());} }

Page 30: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

30

public void startElement(String namespaceURI, String sName, // simple name String qName, Attributes attrs) throws SAXException { getElementText(); attrlist=attrs; if (qName.equalsIgnoreCase("vendor")

recordData=true; if (recordData) { if (qName.equalsIgnoreCase("name")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("address")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("city")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("state")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("zip")) Set_Attributes(attrlist, sName,qName,getElementText()); } } public void Set_Attributes(Attributes mAttribute, String localName, String qualifiedName,

String tagValue ) { if (recordData) { //System.out.println("Set_Attributes ->"+localName+" :"+qualifiedName+ ":"+ tagValue); if (qualifiedName.equalsIgnoreCase("name")) lName = tagValue; if (qualifiedName.equalsIgnoreCase("Address")) lAddress = tagValue; if (qualifiedName.equalsIgnoreCase("city")) lCity = tagValue; if (qualifiedName.equalsIgnoreCase("state")) lState = tagValue; if (qualifiedName.equalsIgnoreCase("zip")) lZip = tagValue; } }

Page 31: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

31

public void characters(char[] buf, int offset, int len) throws SAXException { String s = new String(buf, offset, len); if (textBuffer == null) textBuffer = new StringBuffer(s); else textBuffer.append(s); } public String getElementText() throws SAXException { if (textBuffer == null) return null ; String s = ""+textBuffer; textBuffer = null; return s; } public void endElement(String namespaceURI, String sName, String qName ) throws SAXException { Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("vendor")) { recordData=false; System.out.println(" name->"+lName); System.out.println(" mAddress->"+lAddress); System.out.println(" city->"+lCity); System.out.println(" state->"+lState); System.out.println(" zip->"+lZip); } } public static void main(String[] args) { String fileName="C:\\Amit\\Jdev_12_1_3\\Jdev\\jdevhome\\jdev\\contactInfo.xml"; ReadXML xmltobeRead = new ReadXML(); xmltobeRead.readFile(fileName); }

}

Page 32: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

32

Step12: Integrate BC4J functionality with Java concurrent program.

Step12.a: Define variable and create standalone Application module in LoadXML class.

Step12.b: Add a get method to access AM instance in ReadXML class.

Step12.c: Instantiate the xml parser in LoadXML.

Step12.d: Create a method which will insert row into View Object in ReadXML class.

This method will be called evert time we hit the </vendor> tag which represent end-of-record.

ReadXML xmlConsumer = new ReadXML(); xmlConsumer.readFile(mFileName);

private static OAApplicationModule lJobAM;

String mAmDefName = "custom.oracle.apps.custmodule.conc.server.contactinfoAM"; lJobAM = OAApplicationModuleFactory.createRootOAApplicationModule(ctx, mAmDefName);

public static OAApplicationModule getAM() { return ljobAM; }

private void CreateContactInfoRow() { OAViewObject oaContactInfoVO=null; if(jobAM!=null) { oaContactInfoVO=(OAViewObject)jobAM.findViewObject("contactInfoVO1"); OARow contactInfoRow = (OARow) oaContactInfoVO.createRow(); if(contactInfoRow!=null) { contactInfoRow.setAttribute("Name",lName); contactInfoRow.setAttribute("Address",lAddress); contactInfoRow.setAttribute("City", lCity); contactInfoRow.setAttribute("State",lState); contactInfoRow.setAttribute("Zip",lZip); jobAM.invokeMethod("commitContactInfo"); } else System.out.println("AM job was NULL"); } }

Page 33: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

33

Step12.e: Add a method in Application module class to commit your changes.

Step12.f: Modify endElement method to call “CreateContactInfoRow()” as soon as we hit </vendor> tag.

We are all set to re-run the concurrent program again.

public void commitContactInfo() { Throwable athrowable[] = null; OADBTransaction oadbtransaction = getOADBTransaction(); contactInfoVOImpl ccNewContact = getcontactInfoVO1(); oadbtransaction.postChanges(); oadbtransaction.commit(); ccNewContact.closeRowSet(); oadbtransaction.clearEntityCache("custom.oracle.apps.custmodule.conc.server.contactInfoEO"); if(athrowable != null && athrowable.length > 0) throw OAException.getBundledOAException(athrowable); else return; }

public void endElement(String namespaceURI, String sName, String qName ) throws SAXException { Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("vendor")) { recordData=false; System.out.println(" name->"+lName); System.out.println(" mAddress->"+lAddress); System.out.println(" city->"+lCity); System.out.println(" state->"+lState); System.out.println(" zip->"+lZip); CreateContactInfoRow(); } }

Page 34: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

34

Step12.g: Run the concurrent program

Finally query the table to confirm data was truly loaded.

Page 35: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

35

As you can see, I was able to insert data into table without writing a single

INSERT statement. This is the simplification BC4J component offers to us.

This completes the demonstration “Integrate OA Framework BC4J components within Java concurrent

program”. All the class source code is available in Appendix section.

Summary

Define entity object for table.

Define view object for entity object.

Define application module for view object.

Define “LoadXML” class which implements Java concurrent program methods.

Define “ReadXML” class which implement SAX Parser API’s.

Create a root level Application Module in LoadXML class using Context passed as

parameter.

Instantiate ReadXML within LoadXML class.

Create an SAX Parser instance using SAXParserFactory and pass the XML file as

parameter to parse method.

Parsing will generate event in below sequence for XML elements.

-> StartElement()

->Characters()

->EndElement()

Inside method “EndElement()” , If xml element is “VENDOR” , call

CreateContactInfoRow()” which create a new row in view object.

At the end of “CreateContactInfoRow()” method call commitContactInfo() which is defined

in application module to post the changes at database table.

For all the XML element “VENDOR” , CreateContactInfoRow() will be called which will

create eventually all the rows in table.

After XML parsing event complete, set the request set completion status as 0 in LoadData

class.

Page 36: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

36

Appendix A: Application module java class.

package custom.oracle.apps.custmodule.conc.server; import oracle.apps.fnd.framework.OAException; import oracle.apps.fnd.framework.server.OAApplicationModuleImpl; import oracle.apps.fnd.framework.server.OADBTransaction; // --------------------------------------------------------------------- // --- File generated by Oracle ADF Business Components Design Time. // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------- public class contactinfoAMImpl extends OAApplicationModuleImpl { /**This is the default constructor (do not remove) */ public contactinfoAMImpl() { } /**Container's getter for contactInfoVO1 */ public contactInfoVOImpl getcontactInfoVO1() { return (contactInfoVOImpl)findViewObject("contactInfoVO1"); } public void commitContactInfo() { Throwable athrowable[] = null; OADBTransaction oadbtransaction = getOADBTransaction(); contactInfoVOImpl ccNewContact = getcontactInfoVO1(); oadbtransaction.postChanges(); oadbtransaction.commit(); ccNewContact.closeRowSet(); oadbtransaction.clearEntityCache("custom.oracle.apps.custmodule.conc.server.contactInfoEO"); if(athrowable != null && athrowable.length > 0) throw OAException.getBundledOAException(athrowable); else return; } /**Sample main for debugging Business Components code using the tester. */ public static void main(String[] args) { launchTester("custom.oracle.apps.custmodule.conc.server", /* package name */ "contactinfoAMLocal" /* Configuration Name */); } }

Page 37: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

37

Appendix B: Entity Object Java class file.

package custom.oracle.apps.custmodule.conc.server; import oracle.apps.fnd.framework.server.OAEntityDefImpl; import oracle.apps.fnd.framework.server.OAEntityImpl; import oracle.jbo.domain.Date; import oracle.jbo.domain.Number; import oracle.jbo.domain.RowID; import oracle.jbo.server.AttributeDefImpl; import oracle.jbo.server.EntityDefImpl; // --------------------------------------------------------------------- // --- File generated by Oracle ADF Business Components Design Time. // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------- public class contactInfoEOImpl extends OAEntityImpl { public static final int NAME = 0; public static final int ADDRESS = 1; public static final int CITY = 2; public static final int STATE = 3; public static final int ZIP = 4; public static final int CREATIONDATE = 5; public static final int CREATEDBY = 6; public static final int LASTUPDATEDATE = 7; public static final int LASTUPDATEDBY = 8; public static final int ROWID = 9; public static final int LASTUPDATELOGIN = 10; private static OAEntityDefImpl mDefinitionObject; /**This is the default constructor (do not remove) */ public contactInfoEOImpl() { } /**Retrieves the definition object for this instance class. */ public static synchronized EntityDefImpl getDefinitionObject() { if (mDefinitionObject == null) { mDefinitionObject = (OAEntityDefImpl)EntityDefImpl.findDefObject("custom.oracle.apps.custmodule.conc.server.contactInfoEO"); } return mDefinitionObject; }

Page 38: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

38

/**Gets the attribute value for Name, using the alias name Name */ public String getName() { return (String)getAttributeInternal(NAME); } /**Sets <code>value</code> as the attribute value for Name */ public void setName(String value) { setAttributeInternal(NAME, value); } /**Gets the attribute value for Address, using the alias name Address */ public String getAddress() { return (String)getAttributeInternal(ADDRESS); } /**Sets <code>value</code> as the attribute value for Address */ public void setAddress(String value) { setAttributeInternal(ADDRESS, value); } /**Gets the attribute value for City, using the alias name City */ public String getCity() { return (String)getAttributeInternal(CITY); } /**Sets <code>value</code> as the attribute value for City */ public void setCity(String value) { setAttributeInternal(CITY, value); } /**Gets the attribute value for State, using the alias name State */ public String getState() { return (String)getAttributeInternal(STATE); } /**Sets <code>value</code> as the attribute value for State */ public void setState(String value) { setAttributeInternal(STATE, value); }

Page 39: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

39

/**Gets the attribute value for Zip, using the alias name Zip */ public String getZip() { return (String)getAttributeInternal(ZIP); } /**Sets <code>value</code> as the attribute value for Zip */ public void setZip(String value) { setAttributeInternal(ZIP, value); } /**Gets the attribute value for CreationDate, using the alias name CreationDate */ public Date getCreationDate() { return (Date)getAttributeInternal(CREATIONDATE); } /**Sets <code>value</code> as the attribute value for CreationDate */ public void setCreationDate(Date value) { setAttributeInternal(CREATIONDATE, value); } /**Gets the attribute value for CreatedBy, using the alias name CreatedBy */ public Number getCreatedBy() { return (Number)getAttributeInternal(CREATEDBY); } /**Sets <code>value</code> as the attribute value for CreatedBy */ public void setCreatedBy(Number value) { setAttributeInternal(CREATEDBY, value); } /**Gets the attribute value for LastUpdateDate, using the alias name LastUpdateDate */ public Date getLastUpdateDate() { return (Date)getAttributeInternal(LASTUPDATEDATE); } /**Sets <code>value</code> as the attribute value for LastUpdateDate */ public void setLastUpdateDate(Date value) { setAttributeInternal(LASTUPDATEDATE, value); } /**Gets the attribute value for LastUpdatedBy, using the alias name LastUpdatedBy*/

Page 40: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

40

public Number getLastUpdatedBy() { return (Number)getAttributeInternal(LASTUPDATEDBY); } /**Sets <code>value</code> as the attribute value for LastUpdatedBy */ public void setLastUpdatedBy(Number value) { setAttributeInternal(LASTUPDATEDBY, value); } /**Gets the attribute value for RowID, using the alias name RowID */ public RowID getRowID() { return (RowID)getAttributeInternal(ROWID); } /**getAttrInvokeAccessor: generated method. Do not modify. */ protected Object getAttrInvokeAccessor(int index, AttributeDefImpl attrDef) throws Exception { switch (index) { case NAME: return getName(); case ADDRESS: return getAddress(); case CITY: return getCity(); case STATE: return getState(); case ZIP: return getZip(); case CREATIONDATE: return getCreationDate(); case CREATEDBY: return getCreatedBy(); case LASTUPDATEDATE: return getLastUpdateDate(); case LASTUPDATEDBY: return getLastUpdatedBy(); case ROWID: return getRowID(); case LASTUPDATELOGIN: return getLastUpdateLogin(); default: return super.getAttrInvokeAccessor(index, attrDef); } }

Page 41: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

41

protected void setAttrInvokeAccessor(int index, Object value, AttributeDefImpl attrDef) throws Exception { switch (index) { case NAME: setName((String)value); return; case ADDRESS: setAddress((String)value); return; case CITY: setCity((String)value); return; case STATE: setState((String)value); return; case ZIP: setZip((String)value); return; case CREATIONDATE: setCreationDate((Date)value); return; case CREATEDBY: setCreatedBy((Number)value); return; case LASTUPDATEDATE: setLastUpdateDate((Date)value); return; case LASTUPDATEDBY: setLastUpdatedBy((Number)value); return; case LASTUPDATELOGIN: setLastUpdateLogin((Number)value); return; default: super.setAttrInvokeAccessor(index, value, attrDef); return; } } public Number getLastUpdateLogin() { return (Number)getAttributeInternal(LASTUPDATELOGIN); } public void setLastUpdateLogin(Number value) { setAttributeInternal(LASTUPDATELOGIN, value); } }

Page 42: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

42

Appendix C: View Object Java class file.

package custom.oracle.apps.custmodule.conc.server; import oracle.apps.fnd.framework.server.OAViewRowImpl; import oracle.jbo.domain.Date; import oracle.jbo.domain.Number; import oracle.jbo.domain.RowID; import oracle.jbo.server.AttributeDefImpl; // --------------------------------------------------------------------- // --- File generated by Oracle ADF Business Components Design Time. // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------- public class contactInfoVORowImpl extends OAViewRowImpl { public static final int NAME = 0; public static final int ADDRESS = 1; public static final int CITY = 2; public static final int STATE = 3; public static final int ZIP = 4; public static final int CREATIONDATE = 5; public static final int CREATEDBY = 6; public static final int LASTUPDATEDATE = 7; public static final int LASTUPDATEDBY = 8; public static final int ROWID = 9; public static final int LASTUPDATELOGIN = 10; /**This is the default constructor (do not remove) */ public contactInfoVORowImpl() { } /**Gets contactInfoEO entity object. */ public contactInfoEOImpl getcontactInfoEO() { return (contactInfoEOImpl)getEntity(0); } /**Gets the attribute value for NAME using the alias name Name */ public String getName() { return (String) getAttributeInternal(NAME); } /**Sets <code>value</code> as attribute value for NAME using the alias name Name */

Page 43: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

43

public void setName(String value) { setAttributeInternal(NAME, value); } /**Gets the attribute value for ADDRESS using the alias name Address */ public String getAddress() { return (String) getAttributeInternal(ADDRESS); } /**Sets <code>value</code> as attribute value for ADDRESS using the alias name Address */ public void setAddress(String value) { setAttributeInternal(ADDRESS, value); } /**Gets the attribute value for CITY using the alias name City */ public String getCity() { return (String) getAttributeInternal(CITY); } /**Sets <code>value</code> as attribute value for CITY using the alias name City */ public void setCity(String value) { setAttributeInternal(CITY, value); } /**Gets the attribute value for STATE using the alias name State */ public String getState() { return (String) getAttributeInternal(STATE); } /**Sets <code>value</code> as attribute value for STATE using the alias name State */ public void setState(String value) { setAttributeInternal(STATE, value); } /**Gets the attribute value for ZIP using the alias name Zip */ public String getZip() { return (String) getAttributeInternal(ZIP); } /**Sets <code>value</code> as attribute value for ZIP using the alias name Zip

Page 44: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

44

*/ public void setZip(String value) { setAttributeInternal(ZIP, value); } /**Gets the attribute value for CREATION_DATE using the alias name CreationDate */ public Date getCreationDate() { return (Date) getAttributeInternal(CREATIONDATE); } /**Sets <code>value</code> as attribute value for CREATION_DATE using the alias name CreationDate */ public void setCreationDate(Date value) { setAttributeInternal(CREATIONDATE, value); } /**Gets the attribute value for CREATED_BY using the alias name CreatedBy */ public Number getCreatedBy() { return (Number) getAttributeInternal(CREATEDBY); } /**Sets <code>value</code> as attribute value for CREATED_BY using the alias name CreatedBy */ public void setCreatedBy(Number value) { setAttributeInternal(CREATEDBY, value); } /**Gets the attribute value for LAST_UPDATE_DATE using the alias name LastUpdateDate */ public Date getLastUpdateDate() { return (Date) getAttributeInternal(LASTUPDATEDATE); } /**Sets <code>value</code> as attribute value for LAST_UPDATE_DATE using the alias name LastUpdateDate */ public void setLastUpdateDate(Date value) { setAttributeInternal(LASTUPDATEDATE, value); } public Number getLastUpdatedBy() { return (Number) getAttributeInternal(LASTUPDATEDBY); }

Page 45: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

45

/**Sets <code>value</code> as attribute value for LAST_UPDATED_BY using the alias name LastUpdatedBy */ public void setLastUpdatedBy(Number value) { setAttributeInternal(LASTUPDATEDBY, value); } /**Gets the attribute value for ROWID using the alias name RowID */ public RowID getRowID() { return (RowID) getAttributeInternal(ROWID); } /**getAttrInvokeAccessor: generated method. Do not modify. */ protected Object getAttrInvokeAccessor(int index, AttributeDefImpl attrDef) throws Exception { switch (index) { case NAME: return getName(); case ADDRESS: return getAddress(); case CITY: return getCity(); case STATE: return getState(); case ZIP: return getZip(); case CREATIONDATE: return getCreationDate(); case CREATEDBY: return getCreatedBy(); case LASTUPDATEDATE: return getLastUpdateDate(); case LASTUPDATEDBY: return getLastUpdatedBy(); case ROWID: return getRowID(); case LASTUPDATELOGIN: return getLastUpdateLogin(); default: return super.getAttrInvokeAccessor(index, attrDef); } } /**setAttrInvokeAccessor: generated method. Do not modify. */

Page 46: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

46

*/

protected void setAttrInvokeAccessor(int index, Object value, AttributeDefImpl attrDef) throws Exception { switch (index) { case NAME: setName((String)value); return; case ADDRESS: setAddress((String)value); return; case CITY: setCity((String)value); return; case STATE: setState((String)value); return; case ZIP: setZip((String)value); return; case CREATIONDATE: setCreationDate((Date)value); return; case CREATEDBY: setCreatedBy((Number)value); return; case LASTUPDATEDATE: setLastUpdateDate((Date)value); return; case LASTUPDATEDBY: setLastUpdatedBy((Number)value); return; case LASTUPDATELOGIN: setLastUpdateLogin((Number)value); return; default: super.setAttrInvokeAccessor(index, value, attrDef); return; } } /**Gets the attribute value for LAST_UPDATE_LOGIN using the alias name LastUpdateLogin */ public Number getLastUpdateLogin() { return (Number) getAttributeInternal(LASTUPDATELOGIN); } /**Sets <code>value</code> as attribute value for LAST_UPDATE_LOGIN using the alias name LastUpdateLogin

Page 47: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

47

public void setLastUpdateLogin(Number value) { setAttributeInternal(LASTUPDATELOGIN, value); } } package custom.oracle.apps.custmodule.conc.server; import oracle.apps.fnd.framework.server.OAViewObjectImpl; // --------------------------------------------------------------------- // --- File generated by Oracle ADF Business Components Design Time. // --- Custom code may be added to this class. // --- Warning: Do not modify method signatures of generated methods. // --------------------------------------------------------------------- public class contactInfoVOImpl extends OAViewObjectImpl { /**This is the default constructor (do not remove) */ public contactInfoVOImpl() { } }

Page 48: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

48

Appendix D: LoadData Java class

package custom.oracle.apps.custmodule.conc.server; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import oracle.apps.fnd.cp.request.ReqCompletion; import oracle.apps.fnd.cp.request.LogFile; import oracle.apps.fnd.cp.request.CpContext; import oracle.apps.fnd.cp.request.JavaConcurrentProgram; import oracle.apps.fnd.cp.request.OutFile; import oracle.apps.fnd.util.ParameterList; import java.util.Properties; import java.util.Hashtable; import oracle.apps.fnd.common.Message; import oracle.apps.fnd.common.MessageToken; import oracle.apps.fnd.util.NameValueType; import oracle.apps.fnd.framework.OAApplicationModule; import oracle.apps.fnd.framework.OAApplicationModuleFactory; import oracle.apps.fnd.framework.OAException; import java.sql.CallableStatement; import java.sql.SQLException; import java.math.BigDecimal; public class LoadData implements JavaConcurrentProgram { private static OAApplicationModule ljobAM; private static LogFile rLogFile; private static OutFile rOutFile; private static int mRequestId; private static String mFileName; private static int mXmlErrorCode=0; private static String mXmlErrorMsg=""; public static void writeToLog(String data) { rLogFile.writeln( data, rLogFile.STATEMENT); } public static OAApplicationModule getAM() { return ljobAM; }

Page 49: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

49

public static String getFileName() { return mFileName; } public void runProgram(CpContext ctx) { System.out.println(" Running Custom Job Parse and Load XML data into Contact Info table."); String attribute; String line = null; // Concurrent Request execution status ReqCompletion rStatus = ctx.getReqCompletion(); // properties will be used to store the all values in hash table with particular name Properties rProperties = new Properties(); rProperties.put("APPS_CONTEXT", ctx); String mAmDefName = "custom.oracle.apps.custmodule.conc.server.contactinfoAM"; ljobAM = OAApplicationModuleFactory.createRootOAApplicationModule(ctx, mAmDefName); rOutFile = ctx.getOutFile(); // get OutFile object from CpContext rLogFile = ctx.getLogFile();// get LogFile object from CpContext //LogFile mLog = cpcontext.getLogFile(); //cpcontext.getReqDetails() ParameterList pList = ctx.getParameterList(); Hashtable mAttributes = new Hashtable(); Object obj = null; // Retrive the list of parameters provided to concurrent request. if(pList.hasMoreElements()) { rLogFile.writeln( "--------------------", rLogFile.STATEMENT); String attribute_name; String attribute_value; for(; pList.hasMoreElements(); ) { NameValueType namevaluetype = pList.nextParameter(); attribute_name = namevaluetype.getName(); attribute_value = namevaluetype.getValue(); if(attribute_value != null) { if(attribute_name.equalsIgnoreCase("P_FILE_NAME"))

Page 50: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

50

mFileName = attribute_value; } } } Message message = new Message("FND", "CONC-ARGUMENTS"); rLogFile.writeln(message, rLogFile.STATEMENT); rLogFile.writeln( "--------------------", rLogFile.STATEMENT); rLogFile.writeln("File Name: "+mFileName,rLogFile.STATEMENT ); BufferedReader br; try { br = new BufferedReader(new FileReader(mFileName)); while ((line = br.readLine()) != null) { rLogFile.writeln(line,rLogFile.STATEMENT); } } catch (FileNotFoundException e) {rLogFile.writeln(e.getMessage(),rLogFile.STATEMENT);} catch (java.io.IOException e1) {rLogFile.writeln(e1.getMessage(),rLogFile.STATEMENT);} //Call the XML Parser ReadXML xmlConsumer = new ReadXML(); xmlConsumer.readFile(mFileName); rStatus.setCompletion(mXmlErrorCode, mXmlErrorMsg); rLogFile.writeln("Load XML Data using OA Business Component job Completed",rLogFile.STATEMENT); } }

Page 51: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

51

Appendix E: ReadXML Java class

package custom.oracle.apps.custmodule.conc.server; import java.io.IOException; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.FileInputStream; import oracle.apps.fnd.framework.OAViewObject; import oracle.apps.fnd.framework.OARow; import java.lang.Integer; import oracle.apps.fnd.framework.OAApplicationModule; import oracle.apps.fnd.framework.OAApplicationModuleFactory; public class ReadXML extends DefaultHandler { File lFile; InputStream lFileStream; SAXParser lSaxParser; boolean recordData=false; static OAApplicationModule jobAM; String lName = ""; String lAddress =""; String lCity =""; String lState =""; String lZip = ""; StringBuffer textBuffer; Attributes attrlist; public ReadXML() { } public void readFile(String fileName) {

Page 52: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

52

jobAM=LoadData.getAM(); InitSaxXmlParser(fileName); } private void CreateContactInfoRow() { OAViewObject oaContactInfoVO=null; if(jobAM!=null) { oaContactInfoVO=(OAViewObject)jobAM.findViewObject("contactInfoVO1"); OARow contactInfoRow = (OARow) oaContactInfoVO.createRow(); if(contactInfoRow!=null) { contactInfoRow.setAttribute("Name",lName); contactInfoRow.setAttribute("Address",lAddress); contactInfoRow.setAttribute("City", lCity); contactInfoRow.setAttribute("State",lState); contactInfoRow.setAttribute("Zip",lZip); jobAM.invokeMethod("commitContactInfo"); } else System.out.println("AM job was NULL"); } } public void initAttribute() { lName = ""; lAddress =""; lCity =""; lState =""; lZip = ""; } public void InitSaxXmlParser(String fileName) { DefaultHandler mhandler = new ReadXML(); try { System.out.println("File name length"+fileName.length()); lFile=new File(fileName); lFileStream = new FileInputStream(lFile);

Page 53: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

53

// Use the default (non-validating) SAX Parser SAXParserFactory factory = SAXParserFactory.newInstance(); try { lSaxParser = factory.newSAXParser(); lSaxParser.parse(lFileStream, mhandler); } catch (ParserConfigurationException ex) { System.err.println ("Failed to create SAX parser:" + ex);} catch (SAXException ex) { System.err.println ("SAX parser exceeption:" + ex);} catch (IOException ex) { System.err.println ("IO exeception:" + ex);} catch (IllegalArgumentException ex) { System.err.println ("Invalid file argument" + ex);} } catch(FileNotFoundException e) { System.err.println ("Invalid file argument" + e.getMessage());} } public void startDocument() throws SAXException { System.out.println("Start of document"); initAttribute(); } public void endDocument() throws SAXException { System.out.println("End of document. Does"); } public void Set_Attributes(Attributes mAttribute, String localName, String qualifiedName, String tagValue ) { if (recordData) { //System.out.println("Set_Attributes ->"+localName+" :"+qualifiedName+ ":"+ tagValue); if (qualifiedName.equalsIgnoreCase("name")) lName = tagValue; if (qualifiedName.equalsIgnoreCase("Address")) lAddress = tagValue;

Page 54: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

54

if (qualifiedName.equalsIgnoreCase("city")) lCity = tagValue; if (qualifiedName.equalsIgnoreCase("state")) lState = tagValue; if (qualifiedName.equalsIgnoreCase("zip")) lZip = tagValue; } } public void startElement(String namespaceURI, String sName, // simple name String qName, // qualified name Attributes attrs) throws SAXException { getElementText(); attrlist=attrs; if (qName.equalsIgnoreCase("vendor")) { recordData=true; } if (recordData) { if (qName.equalsIgnoreCase("name")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("address")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("city")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("state")) Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("zip")) Set_Attributes(attrlist, sName,qName,getElementText()); } } public void endElement(String namespaceURI, String sName, String qName ) throws SAXException {

Page 55: Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concurrent program.

55

Set_Attributes(attrlist, sName,qName,getElementText()); if (qName.equalsIgnoreCase("vendor")) { recordData=false; CreateContactInfoRow(); } } public void characters(char[] buf, int offset, int len) throws SAXException { String s = new String(buf, offset, len); if (textBuffer == null) textBuffer = new StringBuffer(s); else textBuffer.append(s); } private String getElementText() throws SAXException { if (textBuffer == null) return null ; String s = ""+textBuffer; textBuffer = null; return s; } public static void main(String[] args) { String fileName="C:\\Amit\\Jdev_12_1_3\\Jdev\\jdevhome\\jdev\\contactInfo.xml";//LoadData.getFileName(); ReadXML xmltobeRead = new ReadXML(); xmltobeRead.readFile(fileName); } }