基本: 其實只要servicetask 一個就可以做成BATCH JOB, 4個CLASS 是因為需要dynamic filter 可以給我自動篩選指定資料.
4個CLASS :
1. Contract - 資料入口
2. Controller - 資料面版控制
3. Service - 程式控制接口
4 ServiceTask - 執行程式
Contract :
[DataContractAttribute]
class UpdateItemCostPriceContract
{
str qry;
[DataMemberAttribute,
AifQueryTypeAttribute(identifierStr(_qry), queryStr(UpdateItemCostPriceQuery))]
public str parmQry(str _qry = qry)
{
qry = _qry;
return qry;
}
}
Controller :
class UpdateItemCostPriceController extends SysOperationServiceController
{
public static void main(Args _args)
{
UpdateItemCostPriceController dataController;
dataController = new UpdateItemCostPriceController(classStr(UpdateItemCostPriceService),
methodStr(UpdateItemCostPriceService, startOperation),
SysOperationExecutionMode::Synchronous);
dataController.parmDialogCaption("Auto Update Item Cost Price.");
dataController.startOperation();
}
}
Service:
class UpdateItemCostPriceService extends SysOperationServiceBase
{
// Contract Variables
//ItemId itemId ;
//SalesIdBase orderNumber;
str qryUpdate;
[SysEntryPointAttribute]
public void startOperation(UpdateItemCostPriceContract _dataContract)
{
System.Exception ex;
#OCCRetryCount
qryUpdate = _dataContract.parmQry();
try
{
//this.processOperation();
UpdateItemCostPriceServiceTask::newTask(_dataContract);
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch (Exception::Error)
{
error(strFmt("Error occured"));
retry;
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(strFmt("Error occured"));
}
}
retry;
}
}
private void processOperation()
{
//TODO Implement business logic here
//CG_DataServiceTask::newTask(_dataContract);
}
}
ServiceTask:
class UpdateItemCostPriceServiceTask extends RunBaseBatch
{
str packedQuery ;
ItemId qryItemid;
#define.CurrentVersion(2)
#define.Version1(2)
public boolean canGoBatchJournal()
{
return true;
}
public boolean init()
{
return true;
}
protected void new()
{
super();
}
public container pack()
{
return [#CurrentVersion];
}
// This method unpacks the query and returns it as query object.
public Query getQuery()
{
return
new Query(SysOperationHelper::base64Decode(packedQuery));
}
// This method takes a query object, encodes it and stores the packed query.
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
public void Update()
{
SalesTable _salesTable;
Query query = this.getQuery();
QueryRun qr;
// Executing our query.
qr = new QueryRun(query);
// Looping through query results.
while (qr.next())
{
_salesTable = qr.get(tableNum(_salesTable));
// code here....
}
}
public void run()
{
#OCCRetryCount
if (! this.validate())
throw error("");
try
{
ttsbegin;
this.Update();
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
public boolean runsImpersonated()
{
return true;
}
public boolean unpack(container packedClass)
{
Version version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
[version] = packedClass;
break;
default:
return false;
}
return true;
}
public boolean validate(Object _calledFrom = null)
{
if (false)
return checkFailed("");
return true;
}
server static UpdateItemCostPriceServiceTask construct()
{
return new UpdateItemCostPriceServiceTask();
}
static ClassDescription description()
{
return "Auto Update Item Cost Price.";
}
static void main(Args args)
{
}
protected boolean canRunInNewSession()
{
return false;
}
public static UpdateItemCostPriceServiceTask newTask(UpdateItemCostPriceContract _dataContract)
{
UpdateItemCostPriceServiceTask task;
task = UpdateItemCostPriceServiceTask::construct();
task.parmPackedQuery(_dataContract.parmQry());
task.runOperation();
return task;
}
public static UpdateItemCostPriceServiceTask queryTask(ItemId qryItemid)
{
UpdateItemCostPriceServiceTask task;
task = UpdateItemCostPriceServiceTask::construct();
task.parmItemId(qryItemid);
task.runOperation();
return task;
}
public str parmPackedQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
public str parmItemId(ItemId _itemId = qryItemid)
{
qryItemid = _itemId;
return qryItemid;
}
}
留言列表