Hi,
I have this service class, and i want to enhance the code performance and also start using RecordInsertList when inserting to TableX
but I'm not sure what to do with updateTableASuccess and updateTableAFailHere's the current Code, and i'll show u after it, what I tried to do in order to enhance it with RecordInsertList (
but i don't know what i will do with parmTable and updateTableASuccess and updateTableAFail) public service()
{
public void process(ContractA _contract)
{
System.Exception ex;
query = _contract.getQuery();
queryRun = new QueryRun(query);
while(queryRun.next())
{
table1 = queryRun.get(tableNum(Table1));
table2 = queryRun.get(tableNum(Table2));
if(table2)
{
try
{
ttsbegin;
ClassA classA = ClassA::newFromfieldA(table1.Field1Enum);
if(classA)
{
classA.run(table2);
this.updateTableASuccess(table2, classA.parmTable());
}
else
{
throw error(/error/);
}
ttscommit;
}
catch(ex)
{
this.updateTableAFail(tableA, ex.Message);
}
}
}
}
public void updateTableASuccess(Table2 _table2, common _table)
{
ttsbegin;
_table2.selectForUpdate(true);
_table2.RefTableId = _table.TableId;
_table2.RefRecId = _table.RecId;
_table2.Status = Status::Completed;
_table2.ErrorTxt = '';
_table2.update();
ttscommit;
}
public void updateTableAFail(Table2 _table2, str _errorMsg)
{
ttsbegin;
_table2.selectForUpdate(true);
_table2.ErrorTxt = _errorMsg;
_table2.Status = Status::Error;
_table2.update();
ttscommit;
}
}
[EnumAtrribute (Field1Enum::Value1)]
class class1 extends ClassA
{
protected void process(str _name)
{
//logic
ttsbegin;
TableX tableX = TableX ::find(x,y);
if(!tableX )
{
tableX.X= x;
tableX.Y= y;
tableX .Name = _name;
tableX.insert();
}
else
{
tableX.selectForUpdate(true);
tableX.Name = _name;
tableX.update();
}
this.parmTable(tableX );
ttscommit;
}
As you can see, when inserting records in TableX in class1 -- I'm updating table2 in case of errors and Success -- not sure how to handle this in the new code below after using recrodInsertList as i won't have the recId yet---------------------------------------------------------------------------------
Here's my new code: public service()
{
public void process(ContractA _contract)
{
System.Exception ex;
query = _contract.getQuery();
queryRun = new QueryRun(query);
ClassA classA;
Map map = new Map(Types::Enum, Types::Class);
while(queryRun.next())
{
table1 = queryRun.get(tableNum(Table1));
table2 = queryRun.get(tableNum(Table2));
if(table2)
{
try
{
ttsbegin;
if(map.exists(table1.Field1Enum))
{
classA= map.lookup(table1.Field1Enum);
}
else
{
classA= CassA::newFromfieldA(table1.Field1Enum);
map.add(table1.Field1Enum, classA);
}
if(classA)
{
classA.run(table2);
this.updateTableASuccess(table2, classA.parmTable()); // what I'm going to do with this after i used insertRecordList
}
else
{
throw error(/error/);
}
ttscommit;
}
catch(ex)
{
this.updateTableAFail(tableA, ex.Message); // what I'm going to do with this after i used insertRecordList
}
}
}
MapEnumerator mapEnum = map.getEnumerator();
while (mapEnum .moveNext())
{
classA= mapEnum .currentValue();
if (classA)
{
classA.InsertToDatabase();
}
}
public void updateTableASuccess(Table2 _table2, common _table)
{
ttsbegin;
_table2.selectForUpdate(true);
_table2.RefTableId = _table.TableId; //what to do
_table2.RefRecId = _table.RecId;
_table2.Status = Status::Completed;
_table2.ErrorTxt = '';
_table2.update();
ttscommit;
}
public void updateTableAFail(Table2 _table2, str _errorMsg)
{
ttsbegin;
_table2.selectForUpdate(true); //what to do
_table2.ErrorTxt = _errorMsg;
_table2.Status = Status::Error;
_table2.update();
ttscommit;
}
}
}
[EnumAtrribute (Field1Enum::Value1)]
class class1 extends ClassA
{
RecordInsertList recordList = new RecordInsertList(tableNum(TableX));
protected void process(str _name)
{
//logic
ttsbegin;
TableX tableX = TableX ::find(x,y);
if(!tableX )
{
tableX.X= x;
tableX.Y= y;
tableX .Name = _name;
recordList.add(tableX);
}
else
{
tableX.selectForUpdate(true);
tableX.Name = _name;
tableX.update();
}
this.parmTable(tableX );
ttscommit;
}
public void InsertToDatabase()
{
recordList.insertDatabase();
}
}