class PurchJournalChangeType
extends RunBaseBatch
{
PurchaseType purchaseType;
QueryRun journal;
Query query;
DialogField fieldContinue;
PurchTable purchTable;
#define.CurrentVersion(1)
#LOCALMACRO.ParmList
PurchaseType
#ENDMACRO
}
public boolean canGoBatchJournal()
{
return true;
}
Object dialog()
{
FormRun formRun = classfactory.createQueryForm(this);
;
formRun.init();
return formRun;
}
void new(PurchaseType _purchaseType)
{
QueryBuildDataSource queryData;
QueryBuildRange queryRange;
;
super();
this.getLast();
purchaseType = _purchaseType;
query = new Query();
query.addDataSource(tablenum(PurchTable));
queryData = query.dataSourceTable(tablenum(PurchTable));
queryRange = queryData.addRange(fieldnum(PurchTable, PurchaseType));
queryRange.value(queryValue(PurchaseType::Journal));
queryRange.status(1); // locked
queryData.addRange(fieldnum(PurchTable, PurchId));
queryData.addRange(fieldnum(PurchTable, CreatedDateTime));
journal = new QueryRun(query);
}
container pack()
{
return [#CurrentVersion,#ParmList,journal.pack()];
}
public QueryRun queryRun()
{
return journal;
}
void run()
{
#OCCRetryCount
;
journal.query().dataSourceTable(tablenum(PurchTable)).update(true);
journal.query().dataSourceTable(tablenum(PurchTable)).concurrencyModel(ConcurrencyModel::Optimistic);
while (journal.next())
{
purchTable = journal.get(tablenum(PurchTable));
setprefix(#PreFixField(PurchTable, PurchId));
try
{
ttsbegin;
purchTable.PurchaseType = purchaseType;
if (!purchTable.validateWrite())
{
throw Exception::Error;
}
purchTable.write();
ttscommit;
}
catch (Exception::Deadlock)
{
purchTable = PurchTable::find(purchTable.PurchId, true, ConcurrencyModel::Optimistic);
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
purchTable = PurchTable::find(purchTable.PurchId, true, ConcurrencyModel::Optimistic);
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch (Exception::Error)
{
checkFailed("@SYS25904");
}
}
}
public boolean runsImpersonated()
{
return true;
}
boolean unpack(container packedClass)
{
Integer _version = conpeek(packedClass,1);
container _packedQuery;
switch (_version)
{
case #CurrentVersion:
[_version,#ParmList,_packedQuery] = packedClass;
if (_packedQuery)
journal = new QueryRun(_packedQuery);
break;
default:
return false;
}
return true;
}
static PurchJournalChangeType construct(PurchaseType purchaseType)
{
return new PurchJournalChangeType(purchaseType);
}
static ClassDescription description()
{
return "@SYS6146";
}
static void main(Args args)
{
PurchJournalChangeType purchJournalChangeType;
;
if (!args)
throw error("@SYS25407");
purchJournalChangeType = PurchJournalChangeType::construct(args.parmEnum());
if (purchJournalChangeType.prompt())
purchJournalChangeType.run();
}
extends RunBaseBatch
{
PurchaseType purchaseType;
QueryRun journal;
Query query;
DialogField fieldContinue;
PurchTable purchTable;
#define.CurrentVersion(1)
#LOCALMACRO.ParmList
PurchaseType
#ENDMACRO
}
public boolean canGoBatchJournal()
{
return true;
}
Object dialog()
{
FormRun formRun = classfactory.createQueryForm(this);
;
formRun.init();
return formRun;
}
void new(PurchaseType _purchaseType)
{
QueryBuildDataSource queryData;
QueryBuildRange queryRange;
;
super();
this.getLast();
purchaseType = _purchaseType;
query = new Query();
query.addDataSource(tablenum(PurchTable));
queryData = query.dataSourceTable(tablenum(PurchTable));
queryRange = queryData.addRange(fieldnum(PurchTable, PurchaseType));
queryRange.value(queryValue(PurchaseType::Journal));
queryRange.status(1); // locked
queryData.addRange(fieldnum(PurchTable, PurchId));
queryData.addRange(fieldnum(PurchTable, CreatedDateTime));
journal = new QueryRun(query);
}
container pack()
{
return [#CurrentVersion,#ParmList,journal.pack()];
}
public QueryRun queryRun()
{
return journal;
}
void run()
{
#OCCRetryCount
;
journal.query().dataSourceTable(tablenum(PurchTable)).update(true);
journal.query().dataSourceTable(tablenum(PurchTable)).concurrencyModel(ConcurrencyModel::Optimistic);
while (journal.next())
{
purchTable = journal.get(tablenum(PurchTable));
setprefix(#PreFixField(PurchTable, PurchId));
try
{
ttsbegin;
purchTable.PurchaseType = purchaseType;
if (!purchTable.validateWrite())
{
throw Exception::Error;
}
purchTable.write();
ttscommit;
}
catch (Exception::Deadlock)
{
purchTable = PurchTable::find(purchTable.PurchId, true, ConcurrencyModel::Optimistic);
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
purchTable = PurchTable::find(purchTable.PurchId, true, ConcurrencyModel::Optimistic);
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch (Exception::Error)
{
checkFailed("@SYS25904");
}
}
}
public boolean runsImpersonated()
{
return true;
}
boolean unpack(container packedClass)
{
Integer _version = conpeek(packedClass,1);
container _packedQuery;
switch (_version)
{
case #CurrentVersion:
[_version,#ParmList,_packedQuery] = packedClass;
if (_packedQuery)
journal = new QueryRun(_packedQuery);
break;
default:
return false;
}
return true;
}
static PurchJournalChangeType construct(PurchaseType purchaseType)
{
return new PurchJournalChangeType(purchaseType);
}
static ClassDescription description()
{
return "@SYS6146";
}
static void main(Args args)
{
PurchJournalChangeType purchJournalChangeType;
;
if (!args)
throw error("@SYS25407");
purchJournalChangeType = PurchJournalChangeType::construct(args.parmEnum());
if (purchJournalChangeType.prompt())
purchJournalChangeType.run();
}