View source | Discuss page | Page history | Printable version   
ADVERTISEMENT
Accounting eLearning Courses
Partnerships
SourceForge.net Logo
Openbravo ERP at SourceForge

SourceForge.net Logo
Openbravo POS at SourceForge

Open Solution Alliance Logo
Openbravo at Open Solutions Alliance

BackgroundExample

Code snippet

Name: BackgroundExample
Version: Openbravo 2.35
Author: Victor Gaspar



Rating :
N/A
(0 votes cast)
You have to be registered to be able to vote

Periodic Manteinance

In order to execute automatically some manteinance tasks we can create a background process that can do the dirty job for us periodically. The following steps to create a background process are necessary:


1.- Create the following java file in ~/OpenbravoERP/AppsOpenbravo/src/org/openbravo/erpCommon/ad_background


package org.openbravo.erpCommon.ad_background;

import org.openbravo.erpCommon.utility.SequenceIdData;
import org.openbravo.erpCommon.utility.Utility;

import java.io.*;


public class PeriodicMaintenance implements BackgroundProcess {
   public void processPL(PeriodicBackground periodicBG, boolean directProcess) throws Exception {
       periodicBG.addLog("Starting Periodic Maintenance");

       PeriodicMaintenanceData.periodicMaintenance(periodicBG.conn);
       periodicBG.addLog("Executing PeriodicMainteinance");

       periodicBG.addLog("Finishing Periodic Mainteinance");
           periodicBG.doPause();
     }
}


2.- Create the following xsql file in ~/OpenbravoERP/AppsOpenbravo/src/org/openbravo/erpCommon/ad_background


<?xml version="1.0" encoding="UTF-8" ?>
<SqlClass name="PeriodicMaintenanceData" package="org.openbravo.erpCommon.ad_background">
   <SqlMethod name="select" type="preparedStatement" return="string">
    <SqlMethodComment></SqlMethodComment>
    <Sql>
      <![CDATA[
        SELECT DUMMY FROM DUAL
      ]]>
    </Sql>
  </SqlMethod> 
   <SqlMethod name="periodicMaintenance" type="callableStatement" return="object" object="PeriodicMaintenanceData">
       <SqlMethodComment>procedure PeriodicMaintenance</SqlMethodComment>
       <Sql><![CDATA[
               CALL PeriodicMaintenance()
             ]]></Sql>
   </SqlMethod>
</SqlClass>


3.- Create the following PL/SQL in oracle


CREATE OR REPLACE PROCEDURE "PERIODICMAINTENANCE"
IS
BEGIN
   DELETE FROM AD_NOTE
   WHERE trunc(CREATED) <= trunc(now()) - (4*7);
END PeriodicMaintenance;


4.- Register the PeriodicMaintenance process in the Application Dictionary as a background process (following as example the PeriodicAlert)

Retrieved from "http://wiki.openbravo.com/wiki/BackgroundExample"

This page has been accessed 641 times. This page was last modified 11:38, 10 March 2009. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.


Category: Code Snippets ERP