Friday, September 14, 2007

Automatic Java class invocation after deployment of Oracle ADF application

Recently I was implementing requirement of automatic Java class invocation right after application is deployed on Oracle Application Server. Automatic class loading possibly is required when for example job scheduling system like Quartz is used by application. This means that job scheduling should be started right after application is deployed, so main question is how to to invoke Java class automatically.

In developed sample application - DeploymentRegistration.zip, I have decided not to use any job scheduling invocation, but to implement deployment registration functionality. Implemented logic - when application is deployed, record with history data is stored in the database table. Application itself is based on standard HR schema, however some additional elements are used. You can find SQL script with statements for database table, sequence and trigger in sample application package.

Data is inserted into database table using application module that is looked up and created using a Command-Line Java Test Client for ADF BC. So, this means that ADF BC functionality is accessed from external Java class. Java class code, which is invoked automatically after deployment:

DeploymentHistory class acquires application module, creates new row and commits it into database. You are probably interested, how this code is invoked automatically, after deployment. Automatic invocation is implemented using simple servlet - AutoLoader, this servlet is loaded automatically after deployment and invokes main method in DeploymentHistory class. Servlet code:


AutoLoader servlet is declared in web.xml with load-on-startup setting equal to 1, this means that servlet will be loaded after deployment automatically and init method code will be executed. Declaration in web.xml:


Now we can test developed application. To test it we can use OC4J that comes with JDeveloper, just right-click on main.jspx and choose Run - application will be deployed on embedded OC4J and started. Developed application shows a table with information about countries and provides a button - Deployments History, which opens pop-up window with information about deployments history stored in the database.


Let's say there were several deployments, it is reflected in deployments history:


When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.

4 comments:

Mourado said...

Hi Andrejus,

it was a relly intresting sample but when i tried it the was no error but the table was not updated.
the only one difference betwenne my sample and your's that i don't instanciate the class in a servlet but with the old good public static void main.
Thanks

Andrejus Baranovskis said...

Hi,

But, my sample should work. Did you experience problems?

Regards,
Andrejus

Mourado said...

HI,
I don't know why not.
I will try to invoke from a servlet

Mourado said...

Hi,
I find the solution, after downloading your zip , I fiubd that i only built simple view object , but in your pack it was entity from table.I built myne and it work.
Thanks