BackgroundExample
Code snippetName: BackgroundExample
|
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)
Category: Code Snippets ERP

