Inside Dynamics Axapta源代码赏析(五)
生活随笔
收集整理的這篇文章主要介紹了
Inside Dynamics Axapta源代码赏析(五)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
第十二章 The Database layer
1.更改RecVersion
AX4.0使用了樂(lè)觀并發(fā)控制,RecVersion是用來(lái)標(biāo)識(shí)記錄版本的。
static?void?RecVersionChange(Args?_args)
{
????CustTable?custTableSelected;
????CustTable?custTableSelectedForUpdate;
????CustTable?custTableUpdated;
????;
????ttsbegin;
????select?custTableSelected
????????where?custTableSelected.AccountNum?==?'4000';
????select?forupdate?custTableSelectedForUpdate
????????where?custTableSelectedForUpdate.AccountNum?==?'4000';
????select?forupdate?custTableUpdated
????????where?custTableUpdated.AccountNum?==?'4000';
????//?At?this?point,?RecVersion?in?all?three?buffers?are?equal.
????custTableUpdated.CreditMax?=?custTableUpdated.CreditMax;
????custTableUpdated.update();
????print?custTableUpdated.recVersion;
????print?custTableSelectedForupdate.recVersion;
????print?custTableSelected.recVersion;
????//?At?this?point,?RecVersion?is?changed?in?the?custTableUpdated
????//?and?custTableSelectedForUpdate?buffers.?CustTableSelected?still
????//?has?its?original?value?in?RecVersion.
????ttscommit;
????pause;
}
2.跳過(guò)ForUpdate和TTSbegin,TTSCommit的檢查.
?CustTable?custTable;
????;
????ttsbegin;
????select?custTable?where?custTable.AccountNum?==?'4000';
????custTable.CreditMax?=?1000;
????custTable.skipTTSCheck(true);
????custTable.update();
????ttscommit; 這樣是可以跳過(guò),但為什么要跳過(guò)那?
3.臨時(shí)表的使用.
通過(guò)setTmp和data兩個(gè)方法可以搞定.
static?void?TmpCustTable(Args?_args)
{
????CustTable?custTable;
????CustTable?custTableTmp;
????;
????custTableTmp.setTmp();
????ttsbegin;
????while?select?custTable
????{
????????custTableTmp.data(custTable);
????????custTableTmp.doInsert();
????}
????ttscommit;
}
{
????TmpLedgerTable?tmpLedgerTable;
????;
????tmpLedgerTable.CompanyId?=?'dat';
????tmpledgerTable.AccountNum?=?'1000';
????tmpLedgerTable.AccountName?=?'Name';
????tmpLedgerTable.insert();?//?Insert?into?first?dataset.
????tmpLedgerTable?=?null;?//?Allocated?memory?is?freed
???????????????????????????//?and?file?is?deleted.
????tmpLedgerTable.CompanyId?=?'dat';
????tmpledgerTable.AccountNum?=?'1000';
????tmpLedgerTable.AccountName?=?'Name';
????tmpLedgerTable.insert();?//?Insert?into?new?dataset.
????
????//Check?it
????while?select?*?from?tmpLedgerTable
????{
????????print?tmpLedgerTable.AccountName;
?
????}
????pause;
}
{
????TmpLedgerTable?tmpLedgerTable1;
????TmpLedgerTable?tmpLedgerTable2;
????;
????tmpLedgerTable2.setTmpData(tmpLedgerTable1);
????tmpLedgerTable1.CompanyId?=?'dat';
????tmpledgerTable1.AccountNum?=?'1000';
????tmpLedgerTable1.AccountName?=?'Name';
????tmpLedgerTable1.insert();?//?Insert?into?shared?dataset.
????tmpLedgerTable2.CompanyId?=?'dat';
????tmpledgerTable2.AccountNum?=?'1000';
????tmpLedgerTable2.AccountName?=?'Name';
????tmpLedgerTable2.insert();?//?Insert?will?fail?with?dublicate?value.
}
1.更改RecVersion
AX4.0使用了樂(lè)觀并發(fā)控制,RecVersion是用來(lái)標(biāo)識(shí)記錄版本的。
static?void?RecVersionChange(Args?_args)
{
????CustTable?custTableSelected;
????CustTable?custTableSelectedForUpdate;
????CustTable?custTableUpdated;
????;
????ttsbegin;
????select?custTableSelected
????????where?custTableSelected.AccountNum?==?'4000';
????select?forupdate?custTableSelectedForUpdate
????????where?custTableSelectedForUpdate.AccountNum?==?'4000';
????select?forupdate?custTableUpdated
????????where?custTableUpdated.AccountNum?==?'4000';
????//?At?this?point,?RecVersion?in?all?three?buffers?are?equal.
????custTableUpdated.CreditMax?=?custTableUpdated.CreditMax;
????custTableUpdated.update();
????print?custTableUpdated.recVersion;
????print?custTableSelectedForupdate.recVersion;
????print?custTableSelected.recVersion;
????//?At?this?point,?RecVersion?is?changed?in?the?custTableUpdated
????//?and?custTableSelectedForUpdate?buffers.?CustTableSelected?still
????//?has?its?original?value?in?RecVersion.
????ttscommit;
????pause;
}
2.跳過(guò)ForUpdate和TTSbegin,TTSCommit的檢查.
?CustTable?custTable;
????;
????ttsbegin;
????select?custTable?where?custTable.AccountNum?==?'4000';
????custTable.CreditMax?=?1000;
????custTable.skipTTSCheck(true);
????custTable.update();
????ttscommit; 這樣是可以跳過(guò),但為什么要跳過(guò)那?
3.臨時(shí)表的使用.
通過(guò)setTmp和data兩個(gè)方法可以搞定.
static?void?TmpCustTable(Args?_args)
{
????CustTable?custTable;
????CustTable?custTableTmp;
????;
????custTableTmp.setTmp();
????ttsbegin;
????while?select?custTable
????{
????????custTableTmp.data(custTable);
????????custTableTmp.doInsert();
????}
????ttscommit;
}
Table有兩個(gè)方法,data()和setTmpData(),其中Data()是拷貝一份數(shù)據(jù),而setTmpData()只是對(duì)象引用的傳遞.
4.臨時(shí)表的清空
把臨時(shí)表賦值為null的時(shí)候,內(nèi)存被清空,臨時(shí)文件被刪除
{
????TmpLedgerTable?tmpLedgerTable;
????;
????tmpLedgerTable.CompanyId?=?'dat';
????tmpledgerTable.AccountNum?=?'1000';
????tmpLedgerTable.AccountName?=?'Name';
????tmpLedgerTable.insert();?//?Insert?into?first?dataset.
????tmpLedgerTable?=?null;?//?Allocated?memory?is?freed
???????????????????????????//?and?file?is?deleted.
????tmpLedgerTable.CompanyId?=?'dat';
????tmpledgerTable.AccountNum?=?'1000';
????tmpLedgerTable.AccountName?=?'Name';
????tmpLedgerTable.insert();?//?Insert?into?new?dataset.
????
????//Check?it
????while?select?*?from?tmpLedgerTable
????{
????????print?tmpLedgerTable.AccountName;
?
????}
????pause;
}
5.下面的這段代碼正好印證了前面的說(shuō)法,setTmpData是指向同一個(gè)對(duì)象的.
{
????TmpLedgerTable?tmpLedgerTable1;
????TmpLedgerTable?tmpLedgerTable2;
????;
????tmpLedgerTable2.setTmpData(tmpLedgerTable1);
????tmpLedgerTable1.CompanyId?=?'dat';
????tmpledgerTable1.AccountNum?=?'1000';
????tmpLedgerTable1.AccountName?=?'Name';
????tmpLedgerTable1.insert();?//?Insert?into?shared?dataset.
????tmpLedgerTable2.CompanyId?=?'dat';
????tmpledgerTable2.AccountNum?=?'1000';
????tmpLedgerTable2.AccountName?=?'Name';
????tmpLedgerTable2.insert();?//?Insert?will?fail?with?dublicate?value.
}
6.ttsabort用于忽略記錄的更改或插入.
剩下的代碼都是一些關(guān)于事務(wù)和鎖的問(wèn)題,跟數(shù)據(jù)庫(kù)的理論類(lèi)似,這里就不摘錄了.
?
轉(zhuǎn)載于:https://www.cnblogs.com/Farseer1215/archive/2006/09/26/515340.html
總結(jié)
以上是生活随笔為你收集整理的Inside Dynamics Axapta源代码赏析(五)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 安装CVSNT
- 下一篇: SharePoint 2007 Back