修改Project中的表名和字段名

修改Project中的表名及字段名

开发了大半,遇到这样一个需求:
1.自己创建的表,要加上公司的简称做为前缀;
2.自己创建的表的字段不需要添加公司的简称做为前缀;
3.在系统原有的表上添加的字段要添加公司的简称做为前缀。
创建的表太多了,一个个修改是重体力活,于是写了个Job来完成,在这里记录一下:

                        static void ModifyTableAndFieldNameOfSomeProject(Args _args)
{
#TreeNodeSysNodeType
#define.prefix('PF')
#define.ProjectName('ProjectName')
TreeNode projectListNode = SysTreeNode::getPrivateProject();
ProjectGroupNode pNode;
//TreeNode projectSuperNode,projectGroupNode;
TreeNodeIterator projectIt;//,projectGroupIt;
ProjectNode projectNode = projectListNode.AOTfindChild(#ProjectName);

//Only has current Layers?
Boolean onlyCurrentLayer(TreeNode _treeNode)
{
int layers = _treeNode.applObjectLayerMask();
UtilEntryLevel level;
UtilEntryLevel currentLevel;
int i,j=0;
;
for(i=0;i<enumcnt(UtilEntryLevel);i++)
{
if (layers & (1 << i))
{
currentLevel = i;
j++;
}
}
if(j == 1 && currentLevel == infolog.currentAOLayer())
return true;

return false;

}
//Modify Classes and Tables
void modify(TreeNode _treeNode)
{
str property;
TreeNode childTreeNode;
;
switch(_treeNode.sysNodeType())
{
case #NT_DBTABLE:
{
//Modify TableName
if(onlyCurrentLayer(_treeNode))
{
if(substr(tableId2Name(_treeNode.applObjectId()),1,2)!=#prefix)
{
_treeNode.AOTsetProperty("Name",#Prefix+tableId2Name(_treeNode.applObjectId()));

}
}

//Modify field Name
childTreeNode = _treeNode.AOTfirstChild().AOTfirstChild();
while(childTreeNode)
{
if(!onlyCurrentLayer(_treeNode) && onlyCurrentLayer(childTreeNode))
{
if(substr(fieldId2Name(_treeNode.applObjectId(),childTreeNode.applObjectId()),1,2)!=#prefix)
{
childTreeNode.AOTsetProperty("Name",#Prefix+fieldId2Name(_treeNode.applObjectId(),childTreeNode.applObjectId()));
childTreeNode.AOTcompile(1);
childTreeNode.AOTsave();
}
}
childTreeNode = childTreeNode.AOTnextSibling();

}
//Save
_treeNode.AOTcompile(1);
_treeNode.AOTsave();
//Synchronize Table
appl.dbSynchronize(SysDictTable::newTreeNode(_treeNode).id());
break;
}
default:
break;
}
}
//Get the classes and tables to be modify
void getElementsToBeModified(TreeNode _treeNode)
{
TreeNodeIterator projectGroupIt;
TreeNode projectSuperNode,projectGroupNode;
if(!_treeNode)
return;
//Project Group
if(_treeNode.sysNodeType() == #NT_PROJECT_GROUP)
{
projectGroupIt = _treeNode.AOTiterator();
projectGroupNode = projectGroupIt.next();
while(projectGroupNode != null)
{

getElementsToBeModified(projectGroupNode);
projectGroupNode = projectGroupIt.next();
}
}

info(_treeNode.AOTname());
modify(_treeNode);

}
;
projectNode = projectNode.getRunNode();
projectIt = projectNode.AOTiterator();
pNode = projectIt.next();

while(pNode)
{
//info(pNode.AOTname());
getElementsToBeModified(pNode);
pNode = projectIt.next();

}
}

 

转载于:https://www.cnblogs.com/yuankang/archive/2012/04/10/2440309.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值