Saturday, May 6, 2017

How to import a Java project to Oracle Forms 11G

Hello everyone,

  Today's session, I would like to show you how to work with Java - Maven project , Oracle Forms and WebLogic features all together.


  • At this project the idea is not use DB jvm for forms. Instead of that create a library in forms(PLL) that imports the java project, based on the Maven project that generates a deployment(.jar) file. 
  1. So, first action is setup your libraries PLL and Jar files to avoid any kind of dependency issues.
     Eg:  FRM-10102: Cannot attach PL/SQL library XXX. This library attachment will be lost if the module is saved.
     
    So, to avoid that, please setup properly where your library is going to be. For example: 

FORMS_PATH=C:\Oracle\Middleware\Oracle_FRHome1\forms;C:\Oracle\Middleware\asinst_1\FormsComponent\forms
LD_LIBRARY_PATH=C:\Oracle\Middleware\Oracle_FRHome1\lib


   2. Second action is setup where your jar file is going to be. You have to define that on FORMS_BUILDER_CLASSPATH environment variable. If you are setting up for development you can use REGEDIT tool, but if you are configuring it in WebLogic, you will have to change your .env classpath variable in order to allow WLS_FORMS managed server to see it properly. Please, note - You must bounce the service for the second option here.


  • Once you have all the dependencies setup, you can start coding as I am going to show below:
  1.  Your Java class must have the constructor to be initialized if you are looking to have 'getters' and 'setters' in your java class. 
  2. Please, also make sure you have a toString method to send and convert all the parameters at one shoot, as needed during the process.
  3. Once you have all your java code deployed(in my case I've used Maven to generate the .jar file), you can copy your jar file to the folder you defined above as your FORMS_BUILDER_CLASSPATH. Another key point here is - In this example, I am doing a development on Forms library and then later calling this library from Oracle Forms. So, from high level design perspective, I have two libraries(PLL and Java) and one Forms file.
  4. Import your Java code to your PLL file.


      
  5.  Once you have them imported, they should look like this in your PLL file. 
  6. Now, you have all your code automatically generated by the import tool and based on your java code previously developed.


  7. You can see the constructor generated have the same number of records that the java code showed on the first and second picture above have.
  8. In order to instantiate your java from Oracle forms you have to execute them like this command line below. Eg: something.new; or something.new(''.'','')
  9. The picture below shows you how to use the get and set features that were created in your java class.


I hope this helps you to work easily with Oracle Forms and Java - all together. Please, shoot me a question if you have any. Otherwise, have fun.



Happy coding ,
Thiago Leoncio.



        

Saturday, April 29, 2017

How to integrate Struts and Hibernate

Hi everybody,



  Today's article, I would like to explain how to integrate Struts and Hibernate framework. First of all, I would like to explain that I am using the MVC pattern to configure it. Struts is my VIEW and CONTROLLER and Hibernate will be the MODEL.

 

Steps of the integration :

  • Configure the plug-in property on struts-config or in another class to setup the configuration of the file .cfg.xml.
  • Create a Hibernate - Struts plugin to set the Hibernate session factory in the servlet context based on the previous setup.
  • Then get the Hibernate  session factory from the servlet context and call/execute whatever Hibernate task needed.

Step-by-step:

   1.0- In my case, I've created a util class called HibernateUtil.java where I am setting up the CreateSessionFactory as below.


   1.1 - You can also do the same dynamic step above manually inserting the Hibernate config XML plugin in struts-config.xml as below:<struts-config>
  1.     ...
        <plug-in className="com.mkyong.common.plugin.HibernatePluginThiago">
           <set-property property="path" value="/hibernate.cfg.xml"/>
        </plug-in>
     ...
    <struts-config
I prefer the first option as you keep your code reusing as much as possible code.


2.0 - On the same scenario, HibernateUtil is where you reference the struts-config.xml parameters and add the datasource session picking up the methods as below:




As you can see the datasouirce is called THIAGO-DB, and this is configured thru all methods that belongs to HibernateUtil.java.

3.0 - Next and final step now is get the Hibernate session factory thru the DAO object that you need to configure. The suggestion that I have is keep as much dynamic as possible in order to make it very easy to change later, as needed.

Here it's the piece of code that I've created to call the session factory from my Hibernate configuration in Struts.

You can see in my try-catch block above that I am calling the current session of HibernateUtil instance that has the THIAGO_DB configuration. So, you are now getting the session factory configured to Hibernate in Struts framework.


I hope this helps, happy coding.
Thiago Leoncio.